[rspec-users] Does mock_model's :null_object option work?
dchelimsky at gmail.com
Wed Dec 5 10:16:50 EST 2007
On Dec 5, 2007 9:07 AM, Tom Stuart <tom at experthuman.com> 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.
> 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
> rspec-users at rubyforge.org
More information about the rspec-users