[rspec-users] Is there a way to use the rescue_action defined in a controller in the controller's specs?

Thorben Schröder stillepost at gmail.com
Sun Oct 7 03:43:22 EDT 2007


Heyho,

I start to discover RSpec but it seems that just on my second day I
ran into some strange trouble with the rescue_action of my
controllers. Just like in Rails 2.0 where there is a

rescue_from Exception, :with => :foo_method

thing to rescue exception thrown in actions in the production
environment, I did a little helper that rescues my action exceptions
with a defined class.
For example if a login fails for some reason I just have to throw a
certain error, this will get rescued by a special method which then
redirects back to the login page.
This works fine if you run it, but seems really hard to spec.
I did a lot of search and found a raise_controller_errors method in
RSpec before 1.0.6 but even if it would be still available it seems
not be a cool solution, because I would not like to spec the
exception, I would like to spec the redirect and that seems impossible
at the moment.

All I get is the render of the diagnostic.html if I leave RSpec in
it's default behaviour. If I add a

@controller_name.send(:define, :rescue_action) {|e| raise e}

to the specs, the error is raised but as I said that is not what I
would like to spec. Is there no way just to invoke the rescue_action
of the controller (actually my rescue_action is in the
ApplicationController)? Would be great :)

I hope you can help me, because this sooner or later will drive me crazy!

Thanks for your help and your great work on RSpec!

Thorben


More information about the rspec-users mailing list