[rspec-users] What rescue hooks

Nathan Wilmes nathan at pivotallabs.com
Fri Feb 13 18:20:47 EST 2009


A few of our tests attempt to test controllers with production-style
rescuing.  Before the current rspec/Rails 2.2.2 combo, it was fairly easy to
set up for these tests:

it "should throw a 404 for strange actions" do
  controller.use_rails_error_handling!
  get :strange_action_name
  response.should be_missing
  response.body.should include("You've hit our custom 404 page.")
end

As of trunk rspec/Rails 2.2.2, this doesn't work.  It turns out that
ActionController::TestCase has invented its own hook for testing.  Without
this hook set, you end up
in 'local development' mode.  So to get into production mode, you need to do
this:

it "should throw a 404 for strange actions" do
  controller.use_rails_error_handling!  # rspec no longer throws the error
without hitting Rails logic
  rescue_action_in_public!  # ActionController::TestCase no longer considers
this request a local request

  get :strange_action_name
  response.should be_missing
  response.body.should include("You've hit our custom 404 page.")
end

Of course, if you have 'rescue_from' handlers, these will happen no matter
what.

I guess my question is, now that the 'rescue_action_in_public!' hook exists
in Rails, does it still make sense for rspec-rails to have its own method?
Might it make sense
to merge the two functionalities in some way?

=Nathan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20090213/66c65d7a/attachment.html>


More information about the rspec-users mailing list