How to disable handlers in Ruby on Rails applications when I run functional tests?

I have several controllers in my Ruby on Rails applications with a save handler at the end of the action, which basically catches any unhandled errors and returns some kind of user-friendly error. However, when I do a rake test, I would like to disable these emergency handlers by default so that I can see the full error and stack trace. Is there any automated way to do this?

Refresh to clarify: I have an action like this:

def foo
  # do some stuff...
rescue
  render :text => "Exception: #{$!}" # this could be any kind of custom render
end

Now, when I check the functionality, if an exception occurs, I'm going to get some information about the exception, but I would like it to act as if there was no rescue agent, so I get full debugging information.

Update: SOLUTION

I have done this:

  rescue:
    raise unless Rails.env.production?
    render :text => "Exception: #{$!}" # this could be any kind of custom render
  end
+5
source share
5 answers

Not entirely automated, but how to change the code to throw exceptions when called in a test?

Maybe something like this:

def foo
  # do some stuff...
rescue
  raise if ENV["RAILS_ENV"] == "test"
  render :text => "Exception: #{$!}" # this could be any kind of custom render
end
+9
source

Have you looked at using a call assert_raise( exception1, exception2, ... ) { block }and then listing an exception from a block?

0
source

? ActionController .

:

def rescue_action_in_public(exception)
    response_code = response_code_for_rescue(exception)
    status = interpret_status(response_code)
    respond_to do |format|
        format.html { render_optional_error_file response_code}
        format.js { render :update, :status => status  do |page| page.redirect_to(:url => error_page_url(status)) end}
end

This displays user errors in run mode.

0
source

I think the easiest way is to check if the render is being called correctly, or something else other than the usual, non-exceptional case.

0
source

You do not need to turn off the recovery unit. Use the assert_raise method (as suggested by Scott), and in the block, call the method from which you expect an exception.

For example:

def test_throws_exception
  assert_raise Exception do
    raise_if_true(true)
  end
end
-1
source

All Articles