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.
E.g.
cols = [stub(:primary => true, :name => ''id'', :type
=> :integer),
stub(:primary => false, :name => ''desc'', :type
=> :string)]
model = mock
model.stubs(:columns).returns(cols)
Then later:
model.columns.each do |col|
display_type = case col.type
when :integer : ''Int''
when :string : ''String''
else ''n/a''
end
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
--
Ed Howland
http://greenprogrammer.blogspot.com