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?
Is there a way around this? Or do I need to use rspec mock objects?
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.
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?
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
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.