Skip to content

Instantly share code, notes, and snippets.

@dchelimsky
Created February 15, 2009 19:21
Show Gist options
  • Save dchelimsky/64820 to your computer and use it in GitHub Desktop.
Save dchelimsky/64820 to your computer and use it in GitHub Desktop.
class ThingsController < ApplicationController
class UnRescuedError < StandardError; end
class RescuedError < StandardError; end
rescue_from RescuedError do |exception|
#no-op
end
def action_that_raises_rescued_error
raise RescuedError
end
def action_that_raises_un_rescued_error
raise UnRescuedError
end
end
$ ruby test/functional/things_controller_test.rb
Loaded suite test/functional/things_controller_test
Started
....
Finished in 0.198612 seconds.
4 tests, 5 assertions, 0 failures, 0 errors
require File.join(File.dirname(__FILE__), "/../test_helper")
class ThingsControllerTest < ActionController::TestCase
test "action_that_raises_rescued_error does not raise error" do
get :action_that_raises_rescued_error
assert_response 200
end
test "action_that_raises_rescued_error does not raise error with rescue_action_in_public!" do
rescue_action_in_public!
get :action_that_raises_rescued_error
assert_response 200
end
test "action_that_raises_un_rescued_error raises error in test" do
assert_raises ThingsController::UnRescuedError do
get :action_that_raises_un_rescued_error
end
assert_response 200 # just to see what rails does here - wouldn't do this normally
end
test "action_that_raises_un_rescued_error raises error in response" do
rescue_action_in_public!
get :action_that_raises_un_rescued_error
assert_response 500
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment