Test behavior in unit test

This commit is contained in:
Rafael Mendonça França 2023-05-24 17:01:38 +00:00
parent e28f147329
commit 5e34a9297b
No known key found for this signature in database
GPG Key ID: FC23B6D0F1EEE948
2 changed files with 40 additions and 30 deletions

@ -186,6 +186,46 @@ def backtrace
}.inspect, wrapper.traces.inspect)
end
test "#show? returns false when using :rescuable and the exceptions is not rescuable" do
exception = RuntimeError.new("")
wrapper = ExceptionWrapper.new(nil, exception)
env = { "action_dispatch.show_exceptions" => :rescuable }
request = ActionDispatch::Request.new(env)
assert_equal false, wrapper.show?(request)
end
test "#show? returns true when using :rescuable and the exceptions is rescuable" do
exception = AbstractController::ActionNotFound.new("")
wrapper = ExceptionWrapper.new(nil, exception)
env = { "action_dispatch.show_exceptions" => :rescuable }
request = ActionDispatch::Request.new(env)
assert_equal true, wrapper.show?(request)
end
test "#show? returns false when using :none and the exceptions is rescuable" do
exception = AbstractController::ActionNotFound.new("")
wrapper = ExceptionWrapper.new(nil, exception)
env = { "action_dispatch.show_exceptions" => :none }
request = ActionDispatch::Request.new(env)
assert_equal false, wrapper.show?(request)
end
test "#show? returns true when using :all and the exceptions is not rescuable" do
exception = RuntimeError.new("")
wrapper = ExceptionWrapper.new(nil, exception)
env = { "action_dispatch.show_exceptions" => :all }
request = ActionDispatch::Request.new(env)
assert_equal true, wrapper.show?(request)
end
test "#show? emits a deprecation when show_exceptions is true" do
exception = RuntimeError.new("")
wrapper = ExceptionWrapper.new(nil, exception)

@ -273,35 +273,5 @@ def index
error = assert_raises(RuntimeError) { get "/foo" }
assert_equal "oops", error.message
end
test "show_exceptions with deprecated true" do
controller :foo, <<-RUBY
class FooController < ActionController::Base
def index
raise 'oops'
end
end
RUBY
app.config.action_dispatch.show_exceptions = true
get "/foo"
assert_equal 500, last_response.status
end
test "show_exceptions with deprecated false" do
controller :foo, <<-RUBY
class FooController < ActionController::Base
def index
raise 'oops'
end
end
RUBY
app.config.action_dispatch.show_exceptions = false
error = assert_raises(RuntimeError) { get "/foo" }
assert_equal "oops", error.message
end
end
end