[mocha-developer] Aliasing type method in Mocha

Ed Howland ed.howland at gmail.com
Mon Sep 11 19:29:45 EDT 2006

Hi, (Mocha and Stubba are great, btw.)

Is there any way to alias the call to .type in Mocha? The issue is
that AR effectively aliases the normal type method for the Column
class (for whatever Adapter.) My code is reflecting on the adapter
methods to iterate over the columns in a particular model. This makes
it hard to write test code that stubs out columns and mocks my models.

cols = [stub(:primary => true, :name => 'id', :type => :integer),
          stub(:primary => false, :name => 'desc', :type => :string)]
model = mock

Then later:
   model.columns.each do |col|
       display_type = case col.type
       when :integer : 'Int'
       when :string : 'String'
       else 'n/a'

The trouble is that stub in the cols array returns Mocha::Mock as the
type, not what the :type key says it should return. I tried alias
Mocha:Mock :type to :otype in my test and in lib/mocha/mock.rb bot to
no avail. The alias takes, in that s.otype returns "Mocha::Mock" but
the stub method does not really redefine the type method, it stll
returns Mocha::Mock


Ed Howland

More information about the mocha-developer mailing list