# "def rescue\_action(e) raise e end" causing problems in integ

**URL:** <https://www.ruby-forum.com/t/def-rescue-action-e-raise-e-end-causing-problems-in-integ/82505>\
**Category:** Rails\
**Created:** [January 19, 2007, 4:30pm UTC](https://www.ruby-forum.com/t/def-rescue-action-e-raise-e-end-causing-problems-in-integ/82505 "2007-01-19T16:30:57Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/3bc359/32.png) [@jon](https://www.ruby-forum.com/u/jon)\
**Post date:** [January 19, 2007, 4:30pm UTC](https://www.ruby-forum.com/t/def-rescue-action-e-raise-e-end-causing-problems-in-integ/82505/1 "2007-01-19T16:30:57Z")

</div>

Functional tests all come with a handy line that gives more sensible  
exception reporting, looking something like :

class FooController; def rescue\_action(e) raise e end; end

This causes problems in autotest. AFAICT, autotest doesn’t reload the  
controllers when moving between functional tests and integration tests,  
so controllers still have the rewritten rescue\_action method in  
integration.

Normally, this doesn’t matter. When an exception is raised, you get an  
HTTP status of 500, as expected, and you don’t notice that  
rescue\_action is behaving differently.  
However, the status 500 is being set by dispatcher.rb:42, and so there  
are differences. In particular, ActiveRecord::RecordNotFound is  
supposed to return a status of 404. In autotest’s integration  
testing, you might get 404, you might get 500, depending on whether or  
not your functional tests got loaded first on that particular run.

Has anyone found a workaround for this? At the moment I’m having to  
remove the “def rescue\_action(e) raise e end” line from functional  
tests, and it’s making functional test debugging a bit painful…

Jon

---

<div class="post-metadata">

**Author:** ![jon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/3bc359/32.png) [@jon](https://www.ruby-forum.com/u/jon)\
**Post date:** [September 25, 2007, 10:38pm UTC](https://www.ruby-forum.com/t/def-rescue-action-e-raise-e-end-causing-problems-in-integ/82505/2 "2007-09-25T22:38:05Z")

</div>

Jon wrote the following on 10.01.2007 15:54 :

> Has anyone found a workaround for this? At the moment I’m having to  
> remove the “def rescue\_action(e) raise e end” line from functional  
> tests, and it’s making functional test debugging a bit painful…

I’ve no solution for you, but I’ve found another problem with  
integration/functionnal tests that gets in the way with autotest. For  
nearly all tests, I’m using a method for login a user in with this kind  
of code :  
old\_controller = @controller  
@controller = LoginController.new  
post :login, \<whatever\_params\_needed\>  
@controller = old\_controller

There’s a hack in Integration tests which prevents this (a cache returns  
the same controller on each Controller.new call) as soon as a  
controller has been used in an integration test.

A solution :

# Make IntegrationTest classes revert their changes to

# ActionController::Base (which prevent functional tests from

# working properly)

module IntegrationTestPatch  
def self.included(base)  
base.class\_eval do  
def run\_with\_cleanup(\*args, &block)  
ActionController::Base.send(:include,

ActionController::Integration::ControllerCapture)  
run\_without\_cleanup(\*args, &block)  
if  
ActionController::Base.respond\_to?(:clear\_last\_instantiation!)  
ActionController::Base.send(:include,  
RevertControllerCapture)  
end  
end  
alias\_method :run\_without\_cleanup, :run  
alias\_method :run, :run\_with\_cleanup  
end  
end  
end

# Used to patch ActionController::Base

module RevertControllerCapture  
def self.included(base)  
base.class\_eval do  
class \<\< self  
alias\_method :new, :new\_without\_capture  
end  
end  
end  
end

I realize I could manipulate the session directly without using my  
LoginController to the same effect and this problem would go away too,  
but I’ll have to duplicate the LoginController behaviour, which isn’t  
DRY…

Lionel.
