Skip to content

Commit 5e34a92

Browse files
committed
Test behavior in unit test
1 parent e28f147 commit 5e34a92

File tree

2 files changed

+40
-30
lines changed

2 files changed

+40
-30
lines changed

actionpack/test/dispatch/exception_wrapper_test.rb

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,46 @@ def backtrace
186186
}.inspect, wrapper.traces.inspect)
187187
end
188188

189+
test "#show? returns false when using :rescuable and the exceptions is not rescuable" do
190+
exception = RuntimeError.new("")
191+
wrapper = ExceptionWrapper.new(nil, exception)
192+
193+
env = { "action_dispatch.show_exceptions" => :rescuable }
194+
request = ActionDispatch::Request.new(env)
195+
196+
assert_equal false, wrapper.show?(request)
197+
end
198+
199+
test "#show? returns true when using :rescuable and the exceptions is rescuable" do
200+
exception = AbstractController::ActionNotFound.new("")
201+
wrapper = ExceptionWrapper.new(nil, exception)
202+
203+
env = { "action_dispatch.show_exceptions" => :rescuable }
204+
request = ActionDispatch::Request.new(env)
205+
206+
assert_equal true, wrapper.show?(request)
207+
end
208+
209+
test "#show? returns false when using :none and the exceptions is rescuable" do
210+
exception = AbstractController::ActionNotFound.new("")
211+
wrapper = ExceptionWrapper.new(nil, exception)
212+
213+
env = { "action_dispatch.show_exceptions" => :none }
214+
request = ActionDispatch::Request.new(env)
215+
216+
assert_equal false, wrapper.show?(request)
217+
end
218+
219+
test "#show? returns true when using :all and the exceptions is not rescuable" do
220+
exception = RuntimeError.new("")
221+
wrapper = ExceptionWrapper.new(nil, exception)
222+
223+
env = { "action_dispatch.show_exceptions" => :all }
224+
request = ActionDispatch::Request.new(env)
225+
226+
assert_equal true, wrapper.show?(request)
227+
end
228+
189229
test "#show? emits a deprecation when show_exceptions is true" do
190230
exception = RuntimeError.new("")
191231
wrapper = ExceptionWrapper.new(nil, exception)

railties/test/application/middleware/exceptions_test.rb

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -273,35 +273,5 @@ def index
273273
error = assert_raises(RuntimeError) { get "/foo" }
274274
assert_equal "oops", error.message
275275
end
276-
277-
test "show_exceptions with deprecated true" do
278-
controller :foo, <<-RUBY
279-
class FooController < ActionController::Base
280-
def index
281-
raise 'oops'
282-
end
283-
end
284-
RUBY
285-
286-
app.config.action_dispatch.show_exceptions = true
287-
288-
get "/foo"
289-
assert_equal 500, last_response.status
290-
end
291-
292-
test "show_exceptions with deprecated false" do
293-
controller :foo, <<-RUBY
294-
class FooController < ActionController::Base
295-
def index
296-
raise 'oops'
297-
end
298-
end
299-
RUBY
300-
301-
app.config.action_dispatch.show_exceptions = false
302-
303-
error = assert_raises(RuntimeError) { get "/foo" }
304-
assert_equal "oops", error.message
305-
end
306276
end
307277
end

0 commit comments

Comments
 (0)