Does mock_model's :null_object option work?

Please understand in the following that I am making relatively minor
changes to legacy (non-TDD/BDD) code in Substruct and don’t have the
time to refactor nicely right now. I’m just trying to get past the
untested/un-speced cruft quickly to write the spec for my new code, so
I’m looking for expediency over prettiness.

I’m specifying

before( :each ) do
@order_address = mock_model( OrderAddress, :null_object => TRUE )
end

but finding that unstubbed/unmocked method calls on @order_address still
throw error messages like:

Mock ‘OrderAddress_1026’ received unexpected message :first_name with
(no args)

so I’m starting to wonder whether the :null_object option is doing
anything at all…

Al

  ____________________________________________________________________________________

Be a better friend, newshound, and
know-it-all with Yahoo! Mobile. Try it now.
http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ

On Dec 5, 2007 8:52 AM, Al Chou [email protected] wrote:

@order_address = mock_model( OrderAddress, :null_object => TRUE )
:null_object => true (lower case) should work.

On 5 Dec 2007, at 14:52, Al Chou wrote:

@order_address = mock_model( OrderAddress, :null_object => TRUE )
Mock ‘OrderAddress_1026’ received unexpected message :first_name
with (no args)
so I’m starting to wonder whether the :null_object option is doing
anything at all…

:null_object is an option to #mock, not #mock_model, which does call
down to #mock but doesn’t pass any arguments through to it.

The optional hash argument to #mock_model allows you to stub specific
methods (in addition to #id, #to_param etc which #mock_model already
does for you), e.g. mock_model(OrderAddress, :first_name =>
‘Al’, :last_name => ‘Chou’).

If you’ve got so many methods to stub that it’s not worth doing it
explicitly, your best bet is probably to use #mock directly and
pass :null_object.

Cheers,
-Tom

On Dec 5, 2007 9:07 AM, Tom S. [email protected] wrote:

On 5 Dec 2007, at 14:52, Al Chou wrote:

@order_address = mock_model( OrderAddress, :null_object => TRUE )
Mock ‘OrderAddress_1026’ received unexpected message :first_name
with (no args)
so I’m starting to wonder whether the :null_object option is doing
anything at all…

:null_object is an option to #mock, not #mock_model, which does call
down to #mock but doesn’t pass any arguments through to it.

This is true of the 1.0.8 release, but the current trunk does push
:null_object down to the mock.

On Dec 5, 2007 9:17 AM, Tom S. [email protected] wrote:

On 5 Dec 2007, at 15:02, David C. wrote:

@order_address = mock_model( OrderAddress, :null_object => TRUE )
:null_object => true (lower case) should work.

Well, I’m talking bollocks then, aren’t I?

Actually, it turns out that TRUE and true resolve to the same issue.
I’m guessing Al is using 1.0.8.

On 5 Dec 2007, at 15:02, David C. wrote:

@order_address = mock_model( OrderAddress, :null_object => TRUE )
:null_object => true (lower case) should work.

Well, I’m talking bollocks then, aren’t I?

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs