forked from sinatra/sinatra
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathresult_test.rb
98 lines (82 loc) · 1.86 KB
/
result_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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
require File.expand_path('../helper', __FILE__)
class ResultTest < Test::Unit::TestCase
it "sets response.body when result is a String" do
mock_app {
get '/' do
'Hello World'
end
}
get '/'
assert ok?
assert_equal 'Hello World', body
end
it "sets response.body when result is an Array of Strings" do
mock_app {
get '/' do
['Hello', 'World']
end
}
get '/'
assert ok?
assert_equal 'HelloWorld', body
end
it "sets response.body when result responds to #each" do
mock_app {
get '/' do
res = lambda { 'Hello World' }
def res.each ; yield call ; end
res
end
}
get '/'
assert ok?
assert_equal 'Hello World', body
end
it "sets response.body to [] when result is nil" do
mock_app {
get '/' do
nil
end
}
get '/'
assert ok?
assert_equal '', body
end
it "sets status, headers, and body when result is a Rack response tuple" do
mock_app {
get '/' do
[203, {'Content-Type' => 'foo/bar'}, 'Hello World']
end
}
get '/'
assert_equal 203, status
assert_equal 'foo/bar', response['Content-Type']
assert_equal 'Hello World', body
end
it "sets status and body when result is a two-tuple" do
mock_app {
get '/' do
[409, 'formula of']
end
}
get '/'
assert_equal 409, status
assert_equal 'formula of', body
end
it "raises a ArgumentError when result is a non two or three tuple Array" do
mock_app {
get '/' do
[409, 'formula of', 'something else', 'even more']
end
}
assert_raise(ArgumentError) { get '/' }
end
it "sets status when result is a Fixnum status code" do
mock_app {
get('/') { 205 }
}
get '/'
assert_equal 205, status
assert_equal '', body
end
end