2007-11-29 20:56:18 -05:00
|
|
|
require File.dirname(__FILE__) + '/helper'
|
|
|
|
|
2008-09-07 09:23:02 -04:00
|
|
|
context "Custom Errors" do
|
2007-11-29 20:56:18 -05:00
|
|
|
|
2007-12-02 18:48:45 -05:00
|
|
|
setup do
|
2008-02-24 19:43:39 -05:00
|
|
|
Sinatra.application = nil
|
2007-12-02 18:48:45 -05:00
|
|
|
end
|
2008-08-31 03:39:26 -04:00
|
|
|
|
2007-11-29 20:56:18 -05:00
|
|
|
specify "override the default 404" do
|
2008-08-31 03:39:26 -04:00
|
|
|
|
2007-11-29 20:56:18 -05:00
|
|
|
get_it '/'
|
|
|
|
should.be.not_found
|
|
|
|
body.should.equal '<h1>Not Found</h1>'
|
2008-08-31 03:39:26 -04:00
|
|
|
|
2008-02-24 19:43:39 -05:00
|
|
|
error Sinatra::NotFound do
|
2007-11-29 20:56:18 -05:00
|
|
|
'Custom 404'
|
|
|
|
end
|
2008-08-31 03:39:26 -04:00
|
|
|
|
2007-11-29 20:56:18 -05:00
|
|
|
get_it '/'
|
|
|
|
should.be.not_found
|
|
|
|
body.should.equal 'Custom 404'
|
2008-08-31 03:39:26 -04:00
|
|
|
|
2007-11-29 20:56:18 -05:00
|
|
|
end
|
2008-08-31 03:39:26 -04:00
|
|
|
|
2007-11-29 20:56:18 -05:00
|
|
|
specify "override the default 500" do
|
2008-02-24 19:43:39 -05:00
|
|
|
Sinatra.application.options.raise_errors = false
|
2008-08-31 03:39:26 -04:00
|
|
|
|
2007-11-29 20:56:18 -05:00
|
|
|
get '/' do
|
|
|
|
raise 'asdf'
|
|
|
|
end
|
2008-08-31 03:39:26 -04:00
|
|
|
|
2007-11-29 20:56:18 -05:00
|
|
|
get_it '/'
|
|
|
|
status.should.equal 500
|
|
|
|
body.should.equal '<h1>Internal Server Error</h1>'
|
2008-08-31 03:39:26 -04:00
|
|
|
|
|
|
|
|
2008-02-24 19:43:39 -05:00
|
|
|
error do
|
2007-11-29 20:56:18 -05:00
|
|
|
'Custom 500 for ' + request.env['sinatra.error'].message
|
|
|
|
end
|
2008-08-31 03:39:26 -04:00
|
|
|
|
2007-11-29 20:56:18 -05:00
|
|
|
get_it '/'
|
2008-08-31 03:39:26 -04:00
|
|
|
|
2007-11-29 20:56:18 -05:00
|
|
|
get_it '/'
|
|
|
|
status.should.equal 500
|
|
|
|
body.should.equal 'Custom 500 for asdf'
|
2008-08-31 03:39:26 -04:00
|
|
|
|
2008-02-24 19:43:39 -05:00
|
|
|
Sinatra.application.options.raise_errors = true
|
2007-11-29 20:56:18 -05:00
|
|
|
end
|
2008-08-31 03:39:26 -04:00
|
|
|
|
2008-04-01 16:38:36 -04:00
|
|
|
class UnmappedError < RuntimeError; end
|
2008-08-31 03:39:26 -04:00
|
|
|
|
2008-04-01 16:38:36 -04:00
|
|
|
specify "should bring unmapped error back to the top" do
|
|
|
|
get '/' do
|
|
|
|
raise UnmappedError, 'test'
|
|
|
|
end
|
2008-08-31 03:39:26 -04:00
|
|
|
|
2008-04-01 16:38:36 -04:00
|
|
|
assert_raises(UnmappedError) do
|
|
|
|
get_it '/'
|
|
|
|
end
|
|
|
|
end
|
2007-11-29 20:56:18 -05:00
|
|
|
|
|
|
|
end
|