test/mapped_error_test.rb in sinatra-1.3.0.d vs test/mapped_error_test.rb in sinatra-1.3.0.e
- old
+ new
@@ -1,6 +1,6 @@
-require File.dirname(__FILE__) + '/helper'
+require File.expand_path('../helper', __FILE__)
class FooError < RuntimeError
end
class FooNotFound < Sinatra::NotFound
@@ -37,10 +37,40 @@
get '/'
assert_equal 500, status
assert_equal 'Exception!', body
end
+ it 'walks down inheritance chain for errors' do
+ mock_app {
+ set :raise_errors, false
+ error(RuntimeError) { 'Exception!' }
+ get '/' do
+ raise FooError
+ end
+ }
+
+ get '/'
+ assert_equal 500, status
+ assert_equal 'Exception!', body
+ end
+
+ it 'favors subclass handler over superclass handler if available' do
+ mock_app {
+ set :raise_errors, false
+ error(Exception) { 'Exception!' }
+ error(FooError) { 'FooError!' }
+ error(RuntimeError) { 'Exception!' }
+ get '/' do
+ raise FooError
+ end
+ }
+
+ get '/'
+ assert_equal 500, status
+ assert_equal 'FooError!', body
+ end
+
it "sets env['sinatra.error'] to the rescued exception" do
mock_app {
set :raise_errors, false
error(FooError) {
assert env.include?('sinatra.error')
@@ -161,9 +191,22 @@
it 'allows ranges of status code mappings to be registered with :error' do
mock_app {
set :raise_errors, false
error(500..550) { "Error: #{response.status}" }
+ get '/' do
+ [507, {}, 'A very special error']
+ end
+ }
+ get '/'
+ assert_equal 507, status
+ assert_equal 'Error: 507', body
+ end
+
+ it 'allows passing more than one range' do
+ mock_app {
+ set :raise_errors, false
+ error(409..411, 503..509) { "Error: #{response.status}" }
get '/' do
[507, {}, 'A very special error']
end
}
get '/'