From 0eca3f46c74bfc88fb97484fc6f1744f1cfbe79a Mon Sep 17 00:00:00 2001 From: Blake Mizerany Date: Tue, 1 Apr 2008 13:38:36 -0700 Subject: [PATCH] raise errors from error This allows us to test custom errors easier --- lib/sinatra.rb | 6 ++++-- test/custom_error_test.rb | 12 ++++++++++++ test/mapped_error_test.rb | 6 ------ 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/lib/sinatra.rb b/lib/sinatra.rb index 91416589..a7957904 100644 --- a/lib/sinatra.rb +++ b/lib/sinatra.rb @@ -738,7 +738,6 @@ module Sinatra end body = returned.to_result(context) rescue => e - raise e if options.raise_errors request.env['sinatra.error'] = e context.status(500) result = (errors[e.class] || errors[ServerError]).invoke(request) @@ -763,7 +762,10 @@ module Sinatra def setup! configure do - error { '

Internal Server Error

'} + error do + raise request.env['sinatra.error'] if Sinatra.options.raise_errors + '

Internal Server Error

' + end not_found { '

Not Found

'} end diff --git a/test/custom_error_test.rb b/test/custom_error_test.rb index 93e46d70..e479d6b3 100644 --- a/test/custom_error_test.rb +++ b/test/custom_error_test.rb @@ -46,6 +46,18 @@ context "Custom Errors (in general)" do Sinatra.application.options.raise_errors = true end + + class UnmappedError < RuntimeError; end + + specify "should bring unmapped error back to the top" do + get '/' do + raise UnmappedError, 'test' + end + + assert_raises(UnmappedError) do + get_it '/' + end + end end diff --git a/test/mapped_error_test.rb b/test/mapped_error_test.rb index 15c00ff6..918af061 100644 --- a/test/mapped_error_test.rb +++ b/test/mapped_error_test.rb @@ -6,14 +6,8 @@ context "Mapped errors" do setup do Sinatra.application = nil - Sinatra.application.options.raise_errors = false end - teardown do - Sinatra.application.options.raise_errors = true - end - - specify "are rescued and run in context" do error FooError do