Re: Does mock_model's :null_object option work?

Cool, I’ll use mock for this purpose in the future!


----- Original Message ----
From: Tom S. [email protected]
To: rspec-users [email protected]
Sent: Wednesday, December 5, 2007 7:07:55 AM
Subject: Re: [rspec-users] Does mock_model’s :null_object option 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.


rspec-users mailing list
[email protected]


Never miss a thing. Make Yahoo your home page.

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