Evening.
I've got a question about the redefinition of
ActionController::Base#rescue_action. Mainly, why? From the comment in
the source it looks there was a pain point that this solved, but I
can't figure out what that might be.
My problem is this: I make heavy use of rescue_from to trap
exceptional cases so I can 404, 401 or 500 as appropriate. I've got a
Scenario which looks like this ('deleted' blog posts in this app
aren't erased from the DB, they're marked deleted for auditing):
Scenario: Attempting to visit a deleted blog post
Given there is a blog post entitled "Look Ma no hands"
And the blog post "Look Ma no hands" has been marked as deleted
When I attempt to visit the Blog post page for "Look Ma no hands"
Then the response should be a 404 error
That looks like a perfectly reasonable scenario to me, except that it
blows up at "When I attempt to visit". The source for that step is:
When /^I attempt to visit the Blog post page for "(.+)"$/ do |title|
visit entry_path(Entry.find_by_url_slug!
(Digest::MD5.hexdigest(title)))
end
[Excuse the MD5 - it's just a way of maintaining readability in the
scenarios without resorting to fixtures (I'm undecided about it as an
approach, btw)]
visit is exploding when my controller raises a FourOhFour error
because a non-staff non-logged-in user shouldn't be able to see the
page. I use rescue_from to render a special 404 template, but that's
never reached because of the redefinition of rescue_action.
This seems really counterintuitive to me: I expect that the
integration tests will use the full stack, and even in my isolated
controller specs I have to explicitly request that the normal
rescue_action is bypassed. If there's a genuine pain point here that
re-raising and not handling the exception solves then I'm sure I can
find a different idiom for these kinds of scenarios, but I've spent 4
hours today trying to figure out what was broken: first in my app code
then breaking out rdebug to find out what was really happening, which
suggests to me that it's a non-obvious and confusing intervention.
Anyway, sorry to sound so whingey. Like I said: if there's a genuine
problem this approach solves, I'll find a new idiom and shut up.
Otherwise, can this be changed?
Thanks,
Matt
--
Matt Patterson | Design & Code
<matt at reprocessed org> |
http://www.reprocessed.org/_______________________________________________
rspec-devel mailing list
rspec-devel@...
http://rubyforge.org/mailman/listinfo/rspec-devel