bmizerany-sinatra 0.9.0 → 0.9.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/AUTHORS +40 -0
- data/CHANGES +43 -11
- data/README.rdoc +138 -91
- data/Rakefile +7 -1
- data/compat/events_test.rb +10 -7
- data/compat/helper.rb +13 -1
- data/lib/sinatra/base.rb +72 -26
- data/lib/sinatra/compat.rb +142 -44
- data/lib/sinatra/test/bacon.rb +17 -0
- data/lib/sinatra/test/rspec.rb +7 -0
- data/lib/sinatra/test/spec.rb +7 -0
- data/lib/sinatra/test/unit.rb +1 -1
- data/lib/sinatra/test.rb +94 -90
- data/lib/sinatra.rb +5 -0
- data/sinatra.gemspec +7 -3
- data/test/base_test.rb +33 -14
- data/test/builder_test.rb +12 -16
- data/test/erb_test.rb +11 -16
- data/test/filter_test.rb +48 -12
- data/test/haml_test.rb +14 -18
- data/test/helper.rb +25 -0
- data/test/helpers_test.rb +55 -62
- data/test/mapped_error_test.rb +43 -24
- data/test/middleware_test.rb +8 -13
- data/test/options_test.rb +29 -35
- data/test/reload_test.rb +16 -20
- data/test/request_test.rb +12 -5
- data/test/result_test.rb +16 -20
- data/test/routing_test.rb +124 -71
- data/test/sass_test.rb +8 -12
- data/test/sinatra_test.rb +2 -4
- data/test/static_test.rb +16 -19
- data/test/templates_test.rb +23 -19
- metadata +7 -4
data/test/helpers_test.rb
CHANGED
@@ -1,10 +1,4 @@
|
|
1
|
-
require '
|
2
|
-
require 'sinatra/base'
|
3
|
-
require 'sinatra/test'
|
4
|
-
|
5
|
-
class Test::Unit::TestCase
|
6
|
-
include Sinatra::Test
|
7
|
-
end
|
1
|
+
require File.dirname(__FILE__) + '/helper'
|
8
2
|
|
9
3
|
describe 'Sinatra::Helpers' do
|
10
4
|
describe '#status' do
|
@@ -19,7 +13,7 @@ describe 'Sinatra::Helpers' do
|
|
19
13
|
|
20
14
|
it 'sets the response status code' do
|
21
15
|
get '/'
|
22
|
-
response.status
|
16
|
+
assert_equal 207, response.status
|
23
17
|
end
|
24
18
|
end
|
25
19
|
|
@@ -32,7 +26,7 @@ describe 'Sinatra::Helpers' do
|
|
32
26
|
}
|
33
27
|
|
34
28
|
get '/'
|
35
|
-
|
29
|
+
assert_equal 'Hello World', body
|
36
30
|
end
|
37
31
|
|
38
32
|
it 'takes a String, Array, or other object responding to #each' do
|
@@ -43,7 +37,7 @@ describe 'Sinatra::Helpers' do
|
|
43
37
|
}
|
44
38
|
|
45
39
|
get '/'
|
46
|
-
|
40
|
+
assert_equal 'Hello World', body
|
47
41
|
end
|
48
42
|
end
|
49
43
|
|
@@ -57,9 +51,9 @@ describe 'Sinatra::Helpers' do
|
|
57
51
|
}
|
58
52
|
|
59
53
|
get '/'
|
60
|
-
|
61
|
-
body
|
62
|
-
response['Location']
|
54
|
+
assert_equal 302, status
|
55
|
+
assert_equal '', body
|
56
|
+
assert_equal '/foo', response['Location']
|
63
57
|
end
|
64
58
|
|
65
59
|
it 'uses the code given when specified' do
|
@@ -71,9 +65,9 @@ describe 'Sinatra::Helpers' do
|
|
71
65
|
}
|
72
66
|
|
73
67
|
get '/'
|
74
|
-
|
75
|
-
body
|
76
|
-
response['Location']
|
68
|
+
assert_equal 301, status
|
69
|
+
assert_equal '', body
|
70
|
+
assert_equal '/foo', response['Location']
|
77
71
|
end
|
78
72
|
end
|
79
73
|
|
@@ -87,8 +81,8 @@ describe 'Sinatra::Helpers' do
|
|
87
81
|
}
|
88
82
|
|
89
83
|
get '/'
|
90
|
-
|
91
|
-
body
|
84
|
+
assert_equal 501, status
|
85
|
+
assert_equal '', body
|
92
86
|
end
|
93
87
|
|
94
88
|
it 'takes an optional body' do
|
@@ -100,8 +94,8 @@ describe 'Sinatra::Helpers' do
|
|
100
94
|
}
|
101
95
|
|
102
96
|
get '/'
|
103
|
-
|
104
|
-
|
97
|
+
assert_equal 501, status
|
98
|
+
assert_equal 'FAIL', body
|
105
99
|
end
|
106
100
|
|
107
101
|
it 'uses a 500 status code when first argument is a body' do
|
@@ -113,8 +107,8 @@ describe 'Sinatra::Helpers' do
|
|
113
107
|
}
|
114
108
|
|
115
109
|
get '/'
|
116
|
-
|
117
|
-
|
110
|
+
assert_equal 500, status
|
111
|
+
assert_equal 'FAIL', body
|
118
112
|
end
|
119
113
|
end
|
120
114
|
|
@@ -128,8 +122,8 @@ describe 'Sinatra::Helpers' do
|
|
128
122
|
}
|
129
123
|
|
130
124
|
get '/'
|
131
|
-
|
132
|
-
body
|
125
|
+
assert_equal 404, status
|
126
|
+
assert_equal '', body
|
133
127
|
end
|
134
128
|
end
|
135
129
|
|
@@ -142,20 +136,20 @@ describe 'Sinatra::Helpers' do
|
|
142
136
|
}
|
143
137
|
|
144
138
|
get '/', :env => { 'rack.session' => { :foo => 'bar' } }
|
145
|
-
|
139
|
+
assert_equal 'bar', body
|
146
140
|
end
|
147
141
|
|
148
142
|
it 'creates a new session when none provided' do
|
149
143
|
mock_app {
|
150
144
|
get '/' do
|
151
|
-
session.
|
145
|
+
assert session.empty?
|
152
146
|
session[:foo] = 'bar'
|
153
147
|
'Hi'
|
154
148
|
end
|
155
149
|
}
|
156
150
|
|
157
151
|
get '/'
|
158
|
-
|
152
|
+
assert_equal 'Hi', body
|
159
153
|
end
|
160
154
|
end
|
161
155
|
|
@@ -163,18 +157,18 @@ describe 'Sinatra::Helpers' do
|
|
163
157
|
include Sinatra::Helpers
|
164
158
|
it "looks up media types in Rack's MIME registry" do
|
165
159
|
Rack::Mime::MIME_TYPES['.foo'] = 'application/foo'
|
166
|
-
|
167
|
-
media_type('.foo')
|
168
|
-
|
160
|
+
assert_equal 'application/foo', media_type('foo')
|
161
|
+
assert_equal 'application/foo', media_type('.foo')
|
162
|
+
assert_equal 'application/foo', media_type(:foo)
|
169
163
|
end
|
170
164
|
it 'returns nil when given nil' do
|
171
|
-
media_type(nil).
|
165
|
+
assert media_type(nil).nil?
|
172
166
|
end
|
173
167
|
it 'returns nil when media type not registered' do
|
174
|
-
media_type(:bizzle).
|
168
|
+
assert media_type(:bizzle).nil?
|
175
169
|
end
|
176
170
|
it 'returns the argument when given a media type string' do
|
177
|
-
|
171
|
+
assert_equal 'text/plain', media_type('text/plain')
|
178
172
|
end
|
179
173
|
end
|
180
174
|
|
@@ -188,8 +182,8 @@ describe 'Sinatra::Helpers' do
|
|
188
182
|
}
|
189
183
|
|
190
184
|
get '/'
|
191
|
-
response['Content-Type']
|
192
|
-
|
185
|
+
assert_equal 'text/plain', response['Content-Type']
|
186
|
+
assert_equal 'Hello World', body
|
193
187
|
end
|
194
188
|
|
195
189
|
it 'takes media type parameters (like charset=)' do
|
@@ -201,9 +195,9 @@ describe 'Sinatra::Helpers' do
|
|
201
195
|
}
|
202
196
|
|
203
197
|
get '/'
|
204
|
-
|
205
|
-
|
206
|
-
|
198
|
+
assert ok?
|
199
|
+
assert_equal 'text/html;charset=utf-8', response['Content-Type']
|
200
|
+
assert_equal "<h1>Hello, World</h1>", body
|
207
201
|
end
|
208
202
|
|
209
203
|
it "looks up symbols in Rack's mime types dictionary" do
|
@@ -216,9 +210,9 @@ describe 'Sinatra::Helpers' do
|
|
216
210
|
}
|
217
211
|
|
218
212
|
get '/foo.xml'
|
219
|
-
|
220
|
-
response['Content-Type']
|
221
|
-
|
213
|
+
assert ok?
|
214
|
+
assert_equal 'application/foo', response['Content-Type']
|
215
|
+
assert_equal 'I AM FOO', body
|
222
216
|
end
|
223
217
|
|
224
218
|
it 'fails when no mime type is registered for the argument provided' do
|
@@ -228,8 +222,7 @@ describe 'Sinatra::Helpers' do
|
|
228
222
|
"I AM FOO"
|
229
223
|
end
|
230
224
|
}
|
231
|
-
|
232
|
-
lambda { get '/foo.xml' }.should.raise RuntimeError
|
225
|
+
assert_raise(RuntimeError) { get '/foo.xml' }
|
233
226
|
end
|
234
227
|
end
|
235
228
|
|
@@ -255,26 +248,26 @@ describe 'Sinatra::Helpers' do
|
|
255
248
|
it "sends the contents of the file" do
|
256
249
|
send_file_app
|
257
250
|
get '/file.txt'
|
258
|
-
|
259
|
-
|
251
|
+
assert ok?
|
252
|
+
assert_equal 'Hello World', body
|
260
253
|
end
|
261
254
|
|
262
255
|
it 'sets the Content-Type response header if a mime-type can be located' do
|
263
256
|
send_file_app
|
264
257
|
get '/file.txt'
|
265
|
-
response['Content-Type']
|
258
|
+
assert_equal 'text/plain', response['Content-Type']
|
266
259
|
end
|
267
260
|
|
268
261
|
it 'sets the Content-Length response header' do
|
269
262
|
send_file_app
|
270
263
|
get '/file.txt'
|
271
|
-
|
264
|
+
assert_equal 'Hello World'.length.to_s, response['Content-Length']
|
272
265
|
end
|
273
266
|
|
274
267
|
it 'sets the Last-Modified response header' do
|
275
268
|
send_file_app
|
276
269
|
get '/file.txt'
|
277
|
-
|
270
|
+
assert_equal File.mtime(@file).httpdate, response['Last-Modified']
|
278
271
|
end
|
279
272
|
|
280
273
|
it "returns a 404 when not found" do
|
@@ -284,7 +277,7 @@ describe 'Sinatra::Helpers' do
|
|
284
277
|
end
|
285
278
|
}
|
286
279
|
get '/'
|
287
|
-
|
280
|
+
assert not_found?
|
288
281
|
end
|
289
282
|
end
|
290
283
|
|
@@ -303,19 +296,19 @@ describe 'Sinatra::Helpers' do
|
|
303
296
|
|
304
297
|
it 'sets the Last-Modified header to a valid RFC 2616 date value' do
|
305
298
|
get '/'
|
306
|
-
response['Last-Modified']
|
299
|
+
assert_equal @now.httpdate, response['Last-Modified']
|
307
300
|
end
|
308
301
|
|
309
302
|
it 'returns a body when conditional get misses' do
|
310
303
|
get '/'
|
311
|
-
|
312
|
-
|
304
|
+
assert_equal 200, status
|
305
|
+
assert_equal 'Boo!', body
|
313
306
|
end
|
314
307
|
|
315
308
|
it 'halts when a conditional GET matches' do
|
316
309
|
get '/', :env => { 'HTTP_IF_MODIFIED_SINCE' => @now.httpdate }
|
317
|
-
|
318
|
-
body
|
310
|
+
assert_equal 304, status
|
311
|
+
assert_equal '', body
|
319
312
|
end
|
320
313
|
end
|
321
314
|
|
@@ -332,25 +325,25 @@ describe 'Sinatra::Helpers' do
|
|
332
325
|
|
333
326
|
it 'sets the ETag header' do
|
334
327
|
get '/'
|
335
|
-
response['ETag']
|
328
|
+
assert_equal '"FOO"', response['ETag']
|
336
329
|
end
|
337
330
|
|
338
331
|
it 'returns a body when conditional get misses' do
|
339
332
|
get '/'
|
340
|
-
|
341
|
-
|
333
|
+
assert_equal 200, status
|
334
|
+
assert_equal 'Boo!', body
|
342
335
|
end
|
343
336
|
|
344
337
|
it 'halts when a conditional GET matches' do
|
345
338
|
get '/', :env => { 'HTTP_IF_NONE_MATCH' => '"FOO"' }
|
346
|
-
|
347
|
-
body
|
339
|
+
assert_equal 304, status
|
340
|
+
assert_equal '', body
|
348
341
|
end
|
349
342
|
|
350
343
|
it 'should handle multiple ETag values in If-None-Match header' do
|
351
344
|
get '/', :env => { 'HTTP_IF_NONE_MATCH' => '"BAR", *' }
|
352
|
-
|
353
|
-
body
|
345
|
+
assert_equal 304, status
|
346
|
+
assert_equal '', body
|
354
347
|
end
|
355
348
|
|
356
349
|
it 'uses a weak etag with the :weak option' do
|
@@ -361,7 +354,7 @@ describe 'Sinatra::Helpers' do
|
|
361
354
|
end
|
362
355
|
}
|
363
356
|
get '/'
|
364
|
-
|
357
|
+
assert_equal 'W/"FOO"', response['ETag']
|
365
358
|
end
|
366
359
|
|
367
360
|
end
|
data/test/mapped_error_test.rb
CHANGED
@@ -1,10 +1,6 @@
|
|
1
|
-
require '
|
2
|
-
require 'sinatra/base'
|
3
|
-
require 'sinatra/test'
|
1
|
+
require File.dirname(__FILE__) + '/helper'
|
4
2
|
|
5
3
|
describe 'Exception Mappings' do
|
6
|
-
include Sinatra::Test
|
7
|
-
|
8
4
|
class FooError < RuntimeError
|
9
5
|
end
|
10
6
|
|
@@ -17,8 +13,8 @@ describe 'Exception Mappings' do
|
|
17
13
|
end
|
18
14
|
}
|
19
15
|
get '/'
|
20
|
-
|
21
|
-
|
16
|
+
assert_equal 500, status
|
17
|
+
assert_equal 'Foo!', body
|
22
18
|
end
|
23
19
|
|
24
20
|
it 'uses the Exception handler if no matching handler found' do
|
@@ -30,16 +26,16 @@ describe 'Exception Mappings' do
|
|
30
26
|
end
|
31
27
|
}
|
32
28
|
get '/'
|
33
|
-
|
34
|
-
|
29
|
+
assert_equal 500, status
|
30
|
+
assert_equal 'Exception!', body
|
35
31
|
end
|
36
32
|
|
37
33
|
it "sets env['sinatra.error'] to the rescued exception" do
|
38
34
|
mock_app {
|
39
35
|
set :raise_errors, false
|
40
36
|
error(FooError) {
|
41
|
-
env.
|
42
|
-
env['sinatra.error'].
|
37
|
+
assert env.include?('sinatra.error')
|
38
|
+
assert env['sinatra.error'].kind_of?(FooError)
|
43
39
|
'looks good'
|
44
40
|
}
|
45
41
|
get '/' do
|
@@ -47,7 +43,19 @@ describe 'Exception Mappings' do
|
|
47
43
|
end
|
48
44
|
}
|
49
45
|
get '/'
|
50
|
-
|
46
|
+
assert_equal 'looks good', body
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'dumps errors to rack.errors when dump_errors is enabled' do
|
50
|
+
mock_app {
|
51
|
+
set :raise_errors, false
|
52
|
+
set :dump_errors, true
|
53
|
+
get('/') { raise FooError, 'BOOM!' }
|
54
|
+
}
|
55
|
+
|
56
|
+
get '/'
|
57
|
+
assert_equal 500, status
|
58
|
+
assert @response.errors =~ /FooError - BOOM!:/
|
51
59
|
end
|
52
60
|
|
53
61
|
it "raises without calling the handler when the raise_errors options is set" do
|
@@ -58,7 +66,7 @@ describe 'Exception Mappings' do
|
|
58
66
|
raise FooError
|
59
67
|
end
|
60
68
|
}
|
61
|
-
|
69
|
+
assert_raise(FooError) { get '/' }
|
62
70
|
end
|
63
71
|
|
64
72
|
it "never raises Sinatra::NotFound beyond the application" do
|
@@ -68,8 +76,8 @@ describe 'Exception Mappings' do
|
|
68
76
|
raise Sinatra::NotFound
|
69
77
|
end
|
70
78
|
}
|
71
|
-
|
72
|
-
|
79
|
+
assert_nothing_raised { get '/' }
|
80
|
+
assert_equal 404, status
|
73
81
|
end
|
74
82
|
|
75
83
|
class FooNotFound < Sinatra::NotFound
|
@@ -83,11 +91,22 @@ describe 'Exception Mappings' do
|
|
83
91
|
raise FooNotFound
|
84
92
|
end
|
85
93
|
}
|
86
|
-
|
87
|
-
|
88
|
-
|
94
|
+
assert_nothing_raised { get '/' }
|
95
|
+
assert_equal 404, status
|
96
|
+
assert_equal 'foo! not found.', body
|
89
97
|
end
|
90
98
|
|
99
|
+
it 'has a not_found method for backwards compatibility' do
|
100
|
+
mock_app {
|
101
|
+
not_found do
|
102
|
+
"Lost, are we?"
|
103
|
+
end
|
104
|
+
}
|
105
|
+
|
106
|
+
get '/test'
|
107
|
+
assert_equal 404, status
|
108
|
+
assert_equal "Lost, are we?", body
|
109
|
+
end
|
91
110
|
end
|
92
111
|
|
93
112
|
describe 'Custom Error Pages' do
|
@@ -100,8 +119,8 @@ describe 'Custom Error Pages' do
|
|
100
119
|
end
|
101
120
|
}
|
102
121
|
get '/'
|
103
|
-
|
104
|
-
|
122
|
+
assert_equal 500, status
|
123
|
+
assert_equal 'Foo!', body
|
105
124
|
end
|
106
125
|
|
107
126
|
it 'allows ranges of status code mappings to be registered with :error' do
|
@@ -113,8 +132,8 @@ describe 'Custom Error Pages' do
|
|
113
132
|
end
|
114
133
|
}
|
115
134
|
get '/'
|
116
|
-
|
117
|
-
|
135
|
+
assert_equal 507, status
|
136
|
+
assert_equal 'Error: 507', body
|
118
137
|
end
|
119
138
|
|
120
139
|
class FooError < RuntimeError
|
@@ -135,7 +154,7 @@ describe 'Custom Error Pages' do
|
|
135
154
|
end
|
136
155
|
}
|
137
156
|
get '/'
|
138
|
-
|
139
|
-
|
157
|
+
assert_equal 502, status
|
158
|
+
assert_equal 'from custom error page', body
|
140
159
|
end
|
141
160
|
end
|
data/test/middleware_test.rb
CHANGED
@@ -1,10 +1,6 @@
|
|
1
|
-
require '
|
2
|
-
require 'sinatra/base'
|
3
|
-
require 'sinatra/test'
|
1
|
+
require File.dirname(__FILE__) + '/helper'
|
4
2
|
|
5
3
|
describe "Middleware" do
|
6
|
-
include Sinatra::Test
|
7
|
-
|
8
4
|
before do
|
9
5
|
@app = mock_app(Sinatra::Default) {
|
10
6
|
get '/*' do
|
@@ -31,8 +27,8 @@ describe "Middleware" do
|
|
31
27
|
it "is added with Sinatra::Application.use" do
|
32
28
|
@app.use UpcaseMiddleware
|
33
29
|
get '/hello-world'
|
34
|
-
|
35
|
-
|
30
|
+
assert ok?
|
31
|
+
assert_equal '/HELLO-WORLD', body
|
36
32
|
end
|
37
33
|
|
38
34
|
class DowncaseMiddleware < MockMiddleware
|
@@ -46,18 +42,17 @@ describe "Middleware" do
|
|
46
42
|
@app.use UpcaseMiddleware
|
47
43
|
@app.use DowncaseMiddleware
|
48
44
|
get '/Foo'
|
49
|
-
|
50
|
-
response['X-Tests']
|
45
|
+
assert_equal "/foo", body
|
46
|
+
assert_equal "UpcaseMiddleware, DowncaseMiddleware", response['X-Tests']
|
51
47
|
end
|
52
48
|
|
53
49
|
specify "resets the prebuilt pipeline when new middleware is added" do
|
54
50
|
@app.use UpcaseMiddleware
|
55
51
|
get '/Foo'
|
56
|
-
|
52
|
+
assert_equal "/FOO", body
|
57
53
|
@app.use DowncaseMiddleware
|
58
54
|
get '/Foo'
|
59
|
-
|
60
|
-
response['X-Tests']
|
55
|
+
assert_equal '/foo', body
|
56
|
+
assert_equal "UpcaseMiddleware, DowncaseMiddleware", response['X-Tests']
|
61
57
|
end
|
62
|
-
|
63
58
|
end
|
data/test/options_test.rb
CHANGED
@@ -1,33 +1,27 @@
|
|
1
|
-
require '
|
2
|
-
require 'sinatra/base'
|
3
|
-
require 'sinatra/test'
|
1
|
+
require File.dirname(__FILE__) + '/helper'
|
4
2
|
|
5
3
|
describe 'Options' do
|
6
|
-
|
7
|
-
|
8
|
-
before do
|
9
|
-
@app = Class.new(Sinatra::Base)
|
10
|
-
end
|
4
|
+
before { @app = Class.new(Sinatra::Base) }
|
11
5
|
|
12
6
|
it 'sets options to literal values' do
|
13
7
|
@app.set(:foo, 'bar')
|
14
|
-
@app.
|
15
|
-
@app.foo
|
8
|
+
assert @app.respond_to?(:foo)
|
9
|
+
assert_equal 'bar', @app.foo
|
16
10
|
end
|
17
11
|
|
18
12
|
it 'sets options to Procs' do
|
19
13
|
@app.set(:foo, Proc.new { 'baz' })
|
20
|
-
@app.
|
21
|
-
@app.foo
|
14
|
+
assert @app.respond_to?(:foo)
|
15
|
+
assert_equal 'baz', @app.foo
|
22
16
|
end
|
23
17
|
|
24
18
|
it "sets multiple options with a Hash" do
|
25
19
|
@app.set :foo => 1234,
|
26
20
|
:bar => 'Hello World',
|
27
21
|
:baz => Proc.new { 'bizzle' }
|
28
|
-
@app.foo
|
29
|
-
|
30
|
-
@app.baz
|
22
|
+
assert_equal 1234, @app.foo
|
23
|
+
assert_equal 'Hello World', @app.bar
|
24
|
+
assert_equal 'bizzle', @app.baz
|
31
25
|
end
|
32
26
|
|
33
27
|
it 'inherits option methods when subclassed' do
|
@@ -35,10 +29,10 @@ describe 'Options' do
|
|
35
29
|
@app.set :biz, Proc.new { 'baz' }
|
36
30
|
|
37
31
|
sub = Class.new(@app)
|
38
|
-
sub.
|
39
|
-
|
40
|
-
sub.
|
41
|
-
|
32
|
+
assert sub.respond_to?(:foo)
|
33
|
+
assert_equal 'bar', sub.foo
|
34
|
+
assert sub.respond_to?(:biz)
|
35
|
+
assert_equal 'baz', sub.biz
|
42
36
|
end
|
43
37
|
|
44
38
|
it 'overrides options in subclass' do
|
@@ -46,23 +40,23 @@ describe 'Options' do
|
|
46
40
|
@app.set :biz, Proc.new { 'baz' }
|
47
41
|
sub = Class.new(@app)
|
48
42
|
sub.set :foo, 'bling'
|
49
|
-
|
50
|
-
@app.foo
|
43
|
+
assert_equal 'bling', sub.foo
|
44
|
+
assert_equal 'bar', @app.foo
|
51
45
|
end
|
52
46
|
|
53
47
|
it 'creates setter methods when first defined' do
|
54
48
|
@app.set :foo, 'bar'
|
55
|
-
@app.
|
49
|
+
assert @app.respond_to?('foo=')
|
56
50
|
@app.foo = 'biz'
|
57
|
-
@app.foo
|
51
|
+
assert_equal 'biz', @app.foo
|
58
52
|
end
|
59
53
|
|
60
54
|
it 'creates predicate methods when first defined' do
|
61
55
|
@app.set :foo, 'hello world'
|
62
|
-
@app.
|
63
|
-
@app.foo
|
56
|
+
assert @app.respond_to?(:foo?)
|
57
|
+
assert @app.foo?
|
64
58
|
@app.set :foo, nil
|
65
|
-
|
59
|
+
assert !@app.foo?
|
66
60
|
end
|
67
61
|
|
68
62
|
it 'uses existing setter methods if detected' do
|
@@ -76,28 +70,28 @@ describe 'Options' do
|
|
76
70
|
end
|
77
71
|
|
78
72
|
@app.set :foo, 'bam'
|
79
|
-
@app.foo
|
73
|
+
assert_equal 'oops', @app.foo
|
80
74
|
end
|
81
75
|
|
82
76
|
it "sets multiple options to true with #enable" do
|
83
77
|
@app.enable :sessions, :foo, :bar
|
84
|
-
@app.sessions
|
85
|
-
@app.foo
|
86
|
-
@app.bar
|
78
|
+
assert @app.sessions
|
79
|
+
assert @app.foo
|
80
|
+
assert @app.bar
|
87
81
|
end
|
88
82
|
|
89
83
|
it "sets multiple options to false with #disable" do
|
90
84
|
@app.disable :sessions, :foo, :bar
|
91
|
-
|
92
|
-
|
93
|
-
|
85
|
+
assert !@app.sessions
|
86
|
+
assert !@app.foo
|
87
|
+
assert !@app.bar
|
94
88
|
end
|
95
89
|
|
96
90
|
it 'enables MethodOverride middleware when :methodoverride is enabled' do
|
97
91
|
@app.set :methodoverride, true
|
98
92
|
@app.put('/') { 'okay' }
|
99
93
|
post '/', {'_method'=>'PUT'}, {}
|
100
|
-
|
101
|
-
|
94
|
+
assert_equal 200, status
|
95
|
+
assert_equal 'okay', body
|
102
96
|
end
|
103
97
|
end
|