test/mapped_error_test.rb in bmizerany-sinatra-0.8.10 vs test/mapped_error_test.rb in bmizerany-sinatra-0.9.0
- old
+ new
@@ -1,8 +1,12 @@
-require File.dirname(__FILE__) + '/helper'
+require 'test/spec'
+require 'sinatra/base'
+require 'sinatra/test'
describe 'Exception Mappings' do
+ include Sinatra::Test
+
class FooError < RuntimeError
end
it 'invokes handlers registered with ::error when raised' do
mock_app {
@@ -11,12 +15,12 @@
get '/' do
raise FooError
end
}
get '/'
- assert_equal 500, status
- assert_equal 'Foo!', body
+ status.should.equal 500
+ body.should.equal 'Foo!'
end
it 'uses the Exception handler if no matching handler found' do
mock_app {
set :raise_errors, false
@@ -24,62 +28,50 @@
get '/' do
raise FooError
end
}
get '/'
- assert_equal 500, status
- assert_equal 'Exception!', body
+ status.should.equal 500
+ body.should.equal 'Exception!'
end
it "sets env['sinatra.error'] to the rescued exception" do
mock_app {
set :raise_errors, false
error(FooError) {
- assert env.include?('sinatra.error')
- assert env['sinatra.error'].kind_of?(FooError)
+ env.should.include 'sinatra.error'
+ env['sinatra.error'].should.be.kind_of FooError
'looks good'
}
get '/' do
raise FooError
end
}
get '/'
- assert_equal 'looks good', body
+ body.should.equal 'looks good'
end
- it 'dumps errors to rack.errors when dump_errors is enabled' do
- mock_app {
- set :raise_errors, false
- set :dump_errors, true
- get('/') { raise FooError, 'BOOM!' }
- }
-
- get '/'
- assert_equal 500, status
- assert @response.errors =~ /FooError - BOOM!:/
- end
-
it "raises without calling the handler when the raise_errors options is set" do
mock_app {
set :raise_errors, true
error(FooError) { "she's not there." }
get '/' do
raise FooError
end
}
- assert_raise(FooError) { get '/' }
+ lambda { get '/' }.should.raise FooError
end
it "never raises Sinatra::NotFound beyond the application" do
mock_app {
set :raise_errors, true
get '/' do
raise Sinatra::NotFound
end
}
- assert_nothing_raised { get '/' }
- assert_equal 404, status
+ lambda { get '/' }.should.not.raise Sinatra::NotFound
+ status.should.equal 404
end
class FooNotFound < Sinatra::NotFound
end
@@ -89,26 +81,15 @@
error(FooNotFound) { "foo! not found." }
get '/' do
raise FooNotFound
end
}
- assert_nothing_raised { get '/' }
- assert_equal 404, status
- assert_equal 'foo! not found.', body
+ lambda { get '/' }.should.not.raise FooNotFound
+ status.should.equal 404
+ body.should.equal 'foo! not found.'
end
- it 'has a not_found method for backwards compatibility' do
- mock_app {
- not_found do
- "Lost, are we?"
- end
- }
-
- get '/test'
- assert_equal 404, status
- assert_equal "Lost, are we?", body
- end
end
describe 'Custom Error Pages' do
it 'allows numeric status code mappings to be registered with ::error' do
mock_app {
@@ -117,12 +98,12 @@
get '/' do
[500, {}, 'Internal Foo Error']
end
}
get '/'
- assert_equal 500, status
- assert_equal 'Foo!', body
+ status.should.equal 500
+ body.should.equal 'Foo!'
end
it 'allows ranges of status code mappings to be registered with :error' do
mock_app {
set :raise_errors, false
@@ -130,12 +111,12 @@
get '/' do
[507, {}, 'A very special error']
end
}
get '/'
- assert_equal 507, status
- assert_equal 'Error: 507', body
+ status.should.equal 507
+ body.should.equal 'Error: 507'
end
class FooError < RuntimeError
end
@@ -152,9 +133,9 @@
get '/' do
raise FooError
end
}
get '/'
- assert_equal 502, status
- assert_equal 'from custom error page', body
+ status.should.equal 502
+ body.should.equal 'from custom error page'
end
end