forked from sinatra/sinatra
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcustom_error_test.rb
67 lines (43 loc) · 1.15 KB
/
custom_error_test.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
require File.dirname(__FILE__) + '/helper'
context "Custom Errors (in general)" do
setup do
Sinatra.application = nil
end
specify "override the default 404" do
get_it '/'
should.be.not_found
body.should.equal '<h1>Not Found</h1>'
error Sinatra::NotFound do
'Custom 404'
end
get_it '/'
should.be.not_found
body.should.equal 'Custom 404'
end
specify "override the default 500" do
Sinatra.application.options.raise_errors = false
get '/' do
raise 'asdf'
end
get_it '/'
status.should.equal 500
body.should.equal '<h1>Internal Server Error</h1>'
error do
'Custom 500 for ' + request.env['sinatra.error'].message
end
get_it '/'
get_it '/'
status.should.equal 500
body.should.equal 'Custom 500 for asdf'
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