Doug Livesey
2008-May-20 10:50 UTC
[rspec-users] mock_model not stubbing model attribtues in view spec
Hi -- I am just getting to grips w/ view specs, and am having an issue with mock_model not stubbing the mocked model''s attributes. For instance, I have the following: <CODE> before do @input_timesheet = mock_model( InputTimesheet ) assigns[:input_timesheet] = @input_timesheet end it "should display a table element" do render ''/input_timesheets/edit.rhtml_spec.rb'' response.should have_tag( ''table'' ) end </CODE> Obviously, the view calls for a number of attributes from the @input_timesheet, but unless I explicitly define these in the mock_model method, I get the following kind of error: ActionView::TemplateError in ''/input_timesheets/edit.rhtml should display expected InputTimesheet details'' Mock ''InputTimesheet_1000'' received unexpected message :comments with (no args) Can anyone offer any advice as to why this should be? (Maybe it''s supposed to be like this for views?) Cheers, Doug. -- Posted via http://www.ruby-forum.com/.
Ashley Moran
2008-May-20 11:26 UTC
[rspec-users] mock_model not stubbing model attribtues in view spec
On 20 May 2008, at 11:50, Doug Livesey wrote:> Obviously, the view calls for a number of attributes from the > @input_timesheet, but unless I explicitly define these in the > mock_model > method, I get the following kind of error:I''m puzzled, I thought you always had to stub methods on a mock from mock_model? I don''t remember the default behaviour ever being to ignore unknown messages? Sorry, guess this is not a helpful post, I just wanted to know how it behaves for you normally. Ashley -- http://www.patchspace.co.uk/ http://aviewfromafar.net/
Jarkko Laine
2008-May-20 11:32 UTC
[rspec-users] mock_model not stubbing model attribtues in view spec
On 20.5.2008, at 14.26, Ashley Moran wrote:> > On 20 May 2008, at 11:50, Doug Livesey wrote: > >> Obviously, the view calls for a number of attributes from the >> @input_timesheet, but unless I explicitly define these in the >> mock_model >> method, I get the following kind of error: > > > I''m puzzled, I thought you always had to stub methods on a mock from > mock_model? I don''t remember the default behaviour ever being to > ignore unknown messages? > > Sorry, guess this is not a helpful post, I just wanted to know how > it behaves for you normally.mock_model doesn''t stub any methods automatically, and it doesn''t matter whether you''re in view, model or controller specs. If you need the attributes and don''t want to specify anything by hand, stub_model might work for you. It basically creates a real AR object, with its db connections cut. //jarkko> > > Ashley > > > -- > http://www.patchspace.co.uk/ > http://aviewfromafar.net/ > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users-- Jarkko Laine http://jlaine.net http://dotherightthing.com http://www.railsecommerce.com http://odesign.fi -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/pkcs7-signature Size: 2417 bytes Desc: not available URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20080520/86ce53e0/attachment.bin>
David Chelimsky
2008-May-20 11:35 UTC
[rspec-users] mock_model not stubbing model attribtues in view spec
On May 20, 2008, at 6:32 AM, Jarkko Laine wrote:> > On 20.5.2008, at 14.26, Ashley Moran wrote: > >> >> On 20 May 2008, at 11:50, Doug Livesey wrote: >> >>> Obviously, the view calls for a number of attributes from the >>> @input_timesheet, but unless I explicitly define these in the >>> mock_model >>> method, I get the following kind of error: >> >> >> I''m puzzled, I thought you always had to stub methods on a mock >> from mock_model? I don''t remember the default behaviour ever being >> to ignore unknown messages? >> >> Sorry, guess this is not a helpful post, I just wanted to know how >> it behaves for you normally. > > mock_model doesn''t stub any methods automatically, and it doesn''t > matter whether you''re in view, model or controller specs. If you > need the attributes and don''t want to specify anything by hand, > stub_model might work for you. It basically creates a real AR > object, with its db connections cut.FYI - this is only in git right now: http://github.com/dchelimsky/rspec http://github.com/dchelimsky/rspec-rails git://github.com/dchelimsky/rspec.git git://github.com/dchelimsky/rspec-rails.git Cheers, David> > > //jarkko > >> >> >> Ashley >> >> >> -- >> http://www.patchspace.co.uk/ >> http://aviewfromafar.net/ >> >> >> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users > > -- > Jarkko Laine > http://jlaine.net > http://dotherightthing.com > http://www.railsecommerce.com > http://odesign.fi > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users
Doug Livesey
2008-May-20 13:17 UTC
[rspec-users] mock_model not stubbing model attribtues in view spec
Wow, did I ever have *that* wrong, then! Thanks for all those replies -- stub_model looks like the ticket I was after, in that case. Cheers again, Doug. -- Posted via http://www.ruby-forum.com/.