Forum: Ruby on Rails writing tests for rescue_action_in_public

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
19fe735490c8f7e08d5c2de7dc25c826?d=identicon&s=25 Jason Frankovitz (Guest)
on 2007-01-19 16:31
(Received via mailing list)
I'm having trouble with rescue_action_in_public, both in getting it
to work right in my rails app, and in writing tests to make sure.
What I ultimately want to do is test for what a normal user would see
when an error is trapped.

I override local_request? like so:

def rescue_action_in_public(exception)
   render :text => "oops"

def local_request?

Also, I altered the environments files so I won't get the standard
developer error messages (although this seems like possible overkill)

config.action_controller.consider_all_requests_local = false

config.action_controller.consider_all_requests_local = false

In my functional tests, I chose a random controller to use, and
commented out the local rescue_action, so the test won't stop when
rails hits an error (I assume this is what I want, because I want to
continue processing the error, not stop):

# class GroupController; def rescue_action(e) raise e end; end

   def test_error_no_such_group
     post :home, :id => "this_is_not_a_valid_id"
     assert_tag :content => "oops"

When I run this test, the test.log shows the expected
"ActiveRecord::RecordNotFound (Couldn't find Group with
ID=this_is_not_a_valid_id)" but the test passes successfully. If I
uncomment the rescue_action(e) line at the top of the
group_controller_test.rb, the test fails, but the assert_tag check is
never performed so I can't see what rescue_action_in_public is doing.
I could use some advice about how to configure things so I can
deliberately cause errors, and confirm they're being handled right by
the application controller.

Sorry for the lengthy post, but I wanted to be thorough in explaining
the problem.

Any ideas or suggestions are greatly appreciated. Thanks in advance
to everyone.


PS: As far as routes.rb, there's nothing in there doing any explicit
routing to my application controller or the rescue_action_in_public
method, so I don't think that's a factor.

Jason Frankovitz -
work: (310) 601-8454
cell: (415) 254-4890
AIM/Skype: jfrankov
This topic is locked and can not be replied to.