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 -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20071205/02ca5dc7/attachment-0001.html
David Chelimsky
2007-Dec-05 15:02 UTC
[rspec-users] Does mock_model''s :null_object option work?
On Dec 5, 2007 8:52 AM, Al Chou <hotfusionman at yahoo.com> wrote:> > 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 ):null_object => true (lower case) should work.> 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. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >
Tom Stuart
2007-Dec-05 15:07 UTC
[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. Cheers, -Tom
David Chelimsky
2007-Dec-05 15:16 UTC
[rspec-users] Does mock_model''s :null_object option work?
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. > > Cheers, > -Tom > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >
Tom Stuart
2007-Dec-05 15:17 UTC
[rspec-users] Does mock_model''s :null_object option work?
On 5 Dec 2007, at 15:02, David Chelimsky 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?
Cool, I''ll use mock for this purpose in the future! Al ----- Original Message ---- From: Tom Stuart <tom at experthuman.com> To: rspec-users <rspec-users at rubyforge.org> 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. Cheers, -Tom _______________________________________________ rspec-users mailing list rspec-users at rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users ____________________________________________________________________________________ Never miss a thing. Make Yahoo your home page. http://www.yahoo.com/r/hs -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20071205/c0f74491/attachment.html
David Chelimsky
2007-Dec-05 15:30 UTC
[rspec-users] Does mock_model''s :null_object option work?
On Dec 5, 2007 9:17 AM, Tom Stuart <tom at experthuman.com> wrote:> On 5 Dec 2007, at 15:02, David Chelimsky 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.> > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >
Uh, shouldn''t they both work? I use TRUE (and FALSE) because I like the facts that a) they stand out typographically and b) they are Ruby constants. I can''t believe the case of the letters matters, unless you are doing something meta-programmingy rather than just passing the value through to whatever is receiving it.... Al ----- Original Message ---- From: Tom Stuart <tom at experthuman.com> To: rspec-users <rspec-users at rubyforge.org> Sent: Wednesday, December 5, 2007 7:17:06 AM Subject: Re: [rspec-users] Does mock_model''s :null_object option work? On 5 Dec 2007, at 15:02, David Chelimsky 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? _______________________________________________ rspec-users mailing list rspec-users at rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users ____________________________________________________________________________________ Never miss a thing. Make Yahoo your home page. http://www.yahoo.com/r/hs -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20071205/69d23402/attachment.html
David Chelimsky
2007-Dec-05 15:53 UTC
[rspec-users] Does mock_model''s :null_object option work?
On Dec 5, 2007 9:36 AM, Al Chou <hotfusionman at yahoo.com> wrote:> > Uh, shouldn''t they both work? I use TRUE (and FALSE) because I like the > facts that a) they stand out typographically and b) they are Ruby constants. > I can''t believe the case of the letters matters, unless you are doing > something meta-programmingy rather than just passing the value through to > whatever is receiving it....Did you see my earlier email acknowledging that the problem was not true/TRUE, but was likely the version of the plugin you are using? 1.0.8 does not support :null_object. Trunk does.> > Al > > > > ----- Original Message ---- > From: Tom Stuart <tom at experthuman.com> > To: rspec-users <rspec-users at rubyforge.org> > Sent: Wednesday, December 5, 2007 7:17:06 AM > Subject: Re: [rspec-users] Does mock_model''s :null_object option work? > > On 5 Dec 2007, at 15:02, David Chelimsky 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? > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > > ________________________________ > Be a better friend, newshound, and know-it-all with Yahoo! Mobile. Try it > now. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >
That''s correct, I''m still on 1.0.8. Sorry for forgetting to mention that. I''m trying to keep some semblance of sanity as to knowing what versions of code I''m using, given how scattered I am about a subset of it (viz., Substruct). Al ----- Original Message ---- From: David Chelimsky <dchelimsky at gmail.com> To: rspec-users <rspec-users at rubyforge.org> Sent: Wednesday, December 5, 2007 7:30:12 AM Subject: Re: [rspec-users] Does mock_model''s :null_object option work? On Dec 5, 2007 9:17 AM, Tom Stuart <tom at experthuman.com> wrote:> On 5 Dec 2007, at 15:02, David Chelimsky 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. _______________________________________________ rspec-users mailing list rspec-users at rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users ____________________________________________________________________________________ Be a better friend, newshound, and know-it-all with Yahoo! Mobile. Try it now. http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20071205/38ce146c/attachment.html