Jason Nah
2011-Jan-30 09:48 UTC
[rspec-users] Named routes problem... more rails than rspec
Howdy, I have emailed before about the inconsistencies I''m spotting when using named routes/resource, but I think I''ve narrowed down the issue. It would seem this has nothing to do with rspec per se, but more with how routing works with rails. If you have an object instance, that isn''t saved and you attempt to generate a path for that item, even though the item may have an ID, you get a "No route matches" exception. If the item is saved, then a valid route can be generated for that item. Two things seem odd: 1. The exception raised isn''t very informative 2. Why is this a constraint? And can it be turned off for testing purposes? Is there a way around this? Or do I need to use rspec mock objects? Cheers, Jason -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20110130/9b8c661b/attachment.html>
David Chelimsky
2011-Jan-30 14:09 UTC
[rspec-users] Named routes problem... more rails than rspec
On Jan 30, 2011, at 3:48 AM, Jason Nah wrote:> Howdy, > > I have emailed before about the inconsistencies I''m spotting when using named routes/resource, but I think I''ve narrowed down the issue. It would seem this has nothing to do with rspec per se, but more with how routing works with rails. > > If you have an object instance, that isn''t saved and you attempt to generate a path for that item, even though the item may have an ID, you get a "No route matches" exception. > > If the item is saved, then a valid route can be generated for that item. > > Two things seem odd: > The exception raised isn''t very informative > Why is this a constraint? And can it be turned off for testing purposes?If that''s how the framework works and it''s an internal thing like this, turning it off for testing purposes would just lead to confusion.> Is there a way around this? Or do I need to use rspec mock objects?You can either use mock_model or mock_stub (which each act like saved objects unless you tell them otherwise), or use real objects saved to the db. HTH, David -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20110130/2330258b/attachment.html>
Rick DeNatale
2011-Jan-30 15:34 UTC
[rspec-users] Named routes problem... more rails than rspec
On Sun, Jan 30, 2011 at 9:09 AM, David Chelimsky <dchelimsky at gmail.com> wrote:> You can either use mock_model or mock_stubDavid, Did you mean to say stub_model rather than mock_stub? -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Github: http://github.com/rubyredrick Twitter: @RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale
David Chelimsky
2011-Jan-30 17:33 UTC
[rspec-users] Named routes problem... more rails than rspec
On Jan 30, 2011, at 9:34 AM, Rick DeNatale wrote:> On Sun, Jan 30, 2011 at 9:09 AM, David Chelimsky <dchelimsky at gmail.com> wrote: >> You can either use mock_model or mock_stub > > > David, > > Did you mean to say stub_model rather than mock_stub?Yes :)
Jason Nah
2011-Jan-30 23:53 UTC
[rspec-users] Named routes problem... more rails than rspec
Thanks for that... although the exception still bugs me... and digging through the router code in rails is mighty obtuse. I''m switching over to rspec mocks to get me over this... (was using mocha). One problem I ran into, I''m testing a mailer (+ view), and I''m trying to generate the email ONCE for the entire spec, and then run various it { should have_body_text(x) } If I generate the email once using before(:all), I don''t have access to any mock methods (which is understandable). Is there a way to get this going? Or am I going to have to do the whole thing in one big "it" block? Cheers, Jason On 31 January 2011 04:33, David Chelimsky <dchelimsky at gmail.com> wrote:> On Jan 30, 2011, at 9:34 AM, Rick DeNatale wrote: > > > On Sun, Jan 30, 2011 at 9:09 AM, David Chelimsky <dchelimsky at gmail.com> > wrote: > >> You can either use mock_model or mock_stub > > > > > > David, > > > > Did you mean to say stub_model rather than mock_stub? > > Yes :) > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20110131/1abd2dc5/attachment.html>
David Chelimsky
2011-Jan-31 05:54 UTC
[rspec-users] Named routes problem... more rails than rspec
On Jan 30, 2011, at 5:53 PM, Jason Nah wrote:> On 31 January 2011 04:33, David Chelimsky <dchelimsky at gmail.com> wrote: > On Jan 30, 2011, at 9:34 AM, Rick DeNatale wrote: > > > On Sun, Jan 30, 2011 at 9:09 AM, David Chelimsky <dchelimsky at gmail.com> wrote: > >> You can either use mock_model or mock_stub > > > > > > David, > > > > Did you mean to say stub_model rather than mock_stub? > > Yes :)> Thanks for that... although the exception still bugs me... and digging through the router code in rails is mighty obtuse. > > I''m switching over to rspec mocks to get me over this... (was using mocha). > > > One problem I ran into, I''m testing a mailer (+ view), and I''m trying to generate the email ONCE for the entire spec, and then run various it { should have_body_text(x) } > > If I generate the email once using before(:all), I don''t have access to any mock methods (which is understandable). Is there a way to get this going?Yes - you''ve got it in front of you, but you don''t seem to want to do it :) Use mocks in before(:each).> Or am I going to have to do the whole thing in one big "it" block?That''s an alternative too, but I''d recommend what I wrote above. FWIW, David -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20110130/e9245bb3/attachment.html>