rtomayko-sinatra 0.8.10 → 0.9.0
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/ChangeLog +96 -0
- data/README.rdoc +87 -135
- data/Rakefile +1 -6
- data/compat/events_test.rb +7 -10
- data/compat/helper.rb +1 -13
- data/lib/sinatra.rb +0 -5
- data/lib/sinatra/base.rb +45 -108
- data/lib/sinatra/compat.rb +44 -142
- data/lib/sinatra/test.rb +90 -94
- data/lib/sinatra/test/rspec.rb +0 -7
- data/lib/sinatra/test/spec.rb +0 -7
- data/lib/sinatra/test/unit.rb +1 -1
- data/sinatra.gemspec +5 -8
- data/test/base_test.rb +14 -33
- data/test/builder_test.rb +16 -12
- data/test/erb_test.rb +16 -11
- data/test/filter_test.rb +12 -8
- data/test/haml_test.rb +18 -14
- data/test/helpers_test.rb +62 -55
- data/test/mapped_error_test.rb +24 -43
- data/test/middleware_test.rb +13 -8
- data/test/options_test.rb +35 -29
- data/test/reload_test.rb +20 -16
- data/test/request_test.rb +5 -12
- data/test/result_test.rb +20 -16
- data/test/routing_test.rb +64 -150
- data/test/sass_test.rb +12 -8
- data/test/sinatra_test.rb +4 -2
- data/test/static_test.rb +19 -16
- data/test/templates_test.rb +19 -23
- metadata +6 -8
- data/AUTHORS +0 -40
- data/CHANGES +0 -185
- data/lib/sinatra/test/bacon.rb +0 -17
- data/test/helper.rb +0 -25
data/test/filter_test.rb
CHANGED
@@ -1,24 +1,28 @@
|
|
1
|
-
require
|
1
|
+
require 'test/spec'
|
2
|
+
require 'sinatra/base'
|
3
|
+
require 'sinatra/test'
|
2
4
|
|
3
5
|
describe "Filters" do
|
6
|
+
include Sinatra::Test
|
7
|
+
|
4
8
|
it "executes filters in the order defined" do
|
5
9
|
count = 0
|
6
10
|
mock_app do
|
7
11
|
get('/') { 'Hello World' }
|
8
12
|
before {
|
9
|
-
|
13
|
+
count.should.be 0
|
10
14
|
count = 1
|
11
15
|
}
|
12
16
|
before {
|
13
|
-
|
17
|
+
count.should.be 1
|
14
18
|
count = 2
|
15
19
|
}
|
16
20
|
end
|
17
21
|
|
18
22
|
get '/'
|
19
|
-
|
20
|
-
|
21
|
-
|
23
|
+
should.be.ok
|
24
|
+
count.should.be 2
|
25
|
+
body.should.equal 'Hello World'
|
22
26
|
end
|
23
27
|
|
24
28
|
it "allows filters to modify the request" do
|
@@ -29,7 +33,7 @@ describe "Filters" do
|
|
29
33
|
}
|
30
34
|
|
31
35
|
get '/foo'
|
32
|
-
|
33
|
-
|
36
|
+
should.be.ok
|
37
|
+
body.should.be == 'bar'
|
34
38
|
end
|
35
39
|
end
|
data/test/haml_test.rb
CHANGED
@@ -1,6 +1,10 @@
|
|
1
|
-
require
|
1
|
+
require 'test/spec'
|
2
|
+
require 'sinatra/base'
|
3
|
+
require 'sinatra/test'
|
2
4
|
|
3
5
|
describe "HAML Templates" do
|
6
|
+
include Sinatra::Test
|
7
|
+
|
4
8
|
def haml_app(&block)
|
5
9
|
mock_app {
|
6
10
|
set :views, File.dirname(__FILE__) + '/views'
|
@@ -11,14 +15,14 @@ describe "HAML Templates" do
|
|
11
15
|
|
12
16
|
it 'renders inline HAML strings' do
|
13
17
|
haml_app { haml '%h1 Hiya' }
|
14
|
-
|
15
|
-
|
18
|
+
should.be.ok
|
19
|
+
body.should.equal "<h1>Hiya</h1>\n"
|
16
20
|
end
|
17
21
|
|
18
22
|
it 'renders .haml files in views path' do
|
19
23
|
haml_app { haml :hello }
|
20
|
-
|
21
|
-
|
24
|
+
should.be.ok
|
25
|
+
body.should.equal "<h1>Hello From Haml</h1>\n"
|
22
26
|
end
|
23
27
|
|
24
28
|
it "renders with inline layouts" do
|
@@ -27,31 +31,31 @@ describe "HAML Templates" do
|
|
27
31
|
get('/') { haml '%em Sparta' }
|
28
32
|
}
|
29
33
|
get '/'
|
30
|
-
|
31
|
-
|
34
|
+
should.be.ok
|
35
|
+
body.should.equal "<h1>THIS. IS. <EM>SPARTA</EM></h1>\n"
|
32
36
|
end
|
33
37
|
|
34
38
|
it "renders with file layouts" do
|
35
39
|
haml_app {
|
36
40
|
haml 'Hello World', :layout => :layout2
|
37
41
|
}
|
38
|
-
|
39
|
-
|
42
|
+
should.be.ok
|
43
|
+
body.should.equal "<h1>HAML Layout!</h1>\n<p>Hello World</p>\n"
|
40
44
|
end
|
41
45
|
|
42
46
|
it "raises error if template not found" do
|
43
47
|
mock_app {
|
44
48
|
get('/') { haml :no_such_template }
|
45
49
|
}
|
46
|
-
|
50
|
+
lambda { get('/') }.should.raise(Errno::ENOENT)
|
47
51
|
end
|
48
52
|
|
49
53
|
it "passes HAML options to the Haml engine" do
|
50
54
|
haml_app {
|
51
55
|
haml "!!!\n%h1 Hello World", :options => {:format => :html5}
|
52
56
|
}
|
53
|
-
|
54
|
-
|
57
|
+
should.be.ok
|
58
|
+
body.should.equal "<!DOCTYPE html>\n<h1>Hello World</h1>\n"
|
55
59
|
end
|
56
60
|
|
57
61
|
it "passes default HAML options to the Haml engine" do
|
@@ -62,7 +66,7 @@ describe "HAML Templates" do
|
|
62
66
|
end
|
63
67
|
}
|
64
68
|
get '/'
|
65
|
-
|
66
|
-
|
69
|
+
should.be.ok
|
70
|
+
body.should.equal "<!DOCTYPE html>\n<h1>Hello World</h1>\n"
|
67
71
|
end
|
68
72
|
end
|
data/test/helpers_test.rb
CHANGED
@@ -1,4 +1,10 @@
|
|
1
|
-
require
|
1
|
+
require 'test/spec'
|
2
|
+
require 'sinatra/base'
|
3
|
+
require 'sinatra/test'
|
4
|
+
|
5
|
+
class Test::Unit::TestCase
|
6
|
+
include Sinatra::Test
|
7
|
+
end
|
2
8
|
|
3
9
|
describe 'Sinatra::Helpers' do
|
4
10
|
describe '#status' do
|
@@ -13,7 +19,7 @@ describe 'Sinatra::Helpers' do
|
|
13
19
|
|
14
20
|
it 'sets the response status code' do
|
15
21
|
get '/'
|
16
|
-
|
22
|
+
response.status.should.equal 207
|
17
23
|
end
|
18
24
|
end
|
19
25
|
|
@@ -26,7 +32,7 @@ describe 'Sinatra::Helpers' do
|
|
26
32
|
}
|
27
33
|
|
28
34
|
get '/'
|
29
|
-
|
35
|
+
body.should.equal 'Hello World'
|
30
36
|
end
|
31
37
|
|
32
38
|
it 'takes a String, Array, or other object responding to #each' do
|
@@ -37,7 +43,7 @@ describe 'Sinatra::Helpers' do
|
|
37
43
|
}
|
38
44
|
|
39
45
|
get '/'
|
40
|
-
|
46
|
+
body.should.equal 'Hello World'
|
41
47
|
end
|
42
48
|
end
|
43
49
|
|
@@ -51,9 +57,9 @@ describe 'Sinatra::Helpers' do
|
|
51
57
|
}
|
52
58
|
|
53
59
|
get '/'
|
54
|
-
|
55
|
-
|
56
|
-
|
60
|
+
status.should.equal 302
|
61
|
+
body.should.be.empty
|
62
|
+
response['Location'].should.equal '/foo'
|
57
63
|
end
|
58
64
|
|
59
65
|
it 'uses the code given when specified' do
|
@@ -65,9 +71,9 @@ describe 'Sinatra::Helpers' do
|
|
65
71
|
}
|
66
72
|
|
67
73
|
get '/'
|
68
|
-
|
69
|
-
|
70
|
-
|
74
|
+
status.should.equal 301
|
75
|
+
body.should.be.empty
|
76
|
+
response['Location'].should.equal '/foo'
|
71
77
|
end
|
72
78
|
end
|
73
79
|
|
@@ -81,8 +87,8 @@ describe 'Sinatra::Helpers' do
|
|
81
87
|
}
|
82
88
|
|
83
89
|
get '/'
|
84
|
-
|
85
|
-
|
90
|
+
status.should.equal 501
|
91
|
+
body.should.be.empty
|
86
92
|
end
|
87
93
|
|
88
94
|
it 'takes an optional body' do
|
@@ -94,8 +100,8 @@ describe 'Sinatra::Helpers' do
|
|
94
100
|
}
|
95
101
|
|
96
102
|
get '/'
|
97
|
-
|
98
|
-
|
103
|
+
status.should.equal 501
|
104
|
+
body.should.equal 'FAIL'
|
99
105
|
end
|
100
106
|
|
101
107
|
it 'uses a 500 status code when first argument is a body' do
|
@@ -107,8 +113,8 @@ describe 'Sinatra::Helpers' do
|
|
107
113
|
}
|
108
114
|
|
109
115
|
get '/'
|
110
|
-
|
111
|
-
|
116
|
+
status.should.equal 500
|
117
|
+
body.should.equal 'FAIL'
|
112
118
|
end
|
113
119
|
end
|
114
120
|
|
@@ -122,8 +128,8 @@ describe 'Sinatra::Helpers' do
|
|
122
128
|
}
|
123
129
|
|
124
130
|
get '/'
|
125
|
-
|
126
|
-
|
131
|
+
status.should.equal 404
|
132
|
+
body.should.be.empty
|
127
133
|
end
|
128
134
|
end
|
129
135
|
|
@@ -136,20 +142,20 @@ describe 'Sinatra::Helpers' do
|
|
136
142
|
}
|
137
143
|
|
138
144
|
get '/', :env => { 'rack.session' => { :foo => 'bar' } }
|
139
|
-
|
145
|
+
body.should.equal 'bar'
|
140
146
|
end
|
141
147
|
|
142
148
|
it 'creates a new session when none provided' do
|
143
149
|
mock_app {
|
144
150
|
get '/' do
|
145
|
-
|
151
|
+
session.should.be.empty
|
146
152
|
session[:foo] = 'bar'
|
147
153
|
'Hi'
|
148
154
|
end
|
149
155
|
}
|
150
156
|
|
151
157
|
get '/'
|
152
|
-
|
158
|
+
body.should.equal 'Hi'
|
153
159
|
end
|
154
160
|
end
|
155
161
|
|
@@ -157,18 +163,18 @@ describe 'Sinatra::Helpers' do
|
|
157
163
|
include Sinatra::Helpers
|
158
164
|
it "looks up media types in Rack's MIME registry" do
|
159
165
|
Rack::Mime::MIME_TYPES['.foo'] = 'application/foo'
|
160
|
-
|
161
|
-
|
162
|
-
|
166
|
+
media_type('foo').should.equal 'application/foo'
|
167
|
+
media_type('.foo').should.equal 'application/foo'
|
168
|
+
media_type(:foo).should.equal 'application/foo'
|
163
169
|
end
|
164
170
|
it 'returns nil when given nil' do
|
165
|
-
|
171
|
+
media_type(nil).should.be.nil
|
166
172
|
end
|
167
173
|
it 'returns nil when media type not registered' do
|
168
|
-
|
174
|
+
media_type(:bizzle).should.be.nil
|
169
175
|
end
|
170
176
|
it 'returns the argument when given a media type string' do
|
171
|
-
|
177
|
+
media_type('text/plain').should.equal 'text/plain'
|
172
178
|
end
|
173
179
|
end
|
174
180
|
|
@@ -182,8 +188,8 @@ describe 'Sinatra::Helpers' do
|
|
182
188
|
}
|
183
189
|
|
184
190
|
get '/'
|
185
|
-
|
186
|
-
|
191
|
+
response['Content-Type'].should.equal 'text/plain'
|
192
|
+
body.should.equal 'Hello World'
|
187
193
|
end
|
188
194
|
|
189
195
|
it 'takes media type parameters (like charset=)' do
|
@@ -195,9 +201,9 @@ describe 'Sinatra::Helpers' do
|
|
195
201
|
}
|
196
202
|
|
197
203
|
get '/'
|
198
|
-
|
199
|
-
|
200
|
-
|
204
|
+
should.be.ok
|
205
|
+
response['Content-Type'].should.equal 'text/html;charset=utf-8'
|
206
|
+
body.should.equal "<h1>Hello, World</h1>"
|
201
207
|
end
|
202
208
|
|
203
209
|
it "looks up symbols in Rack's mime types dictionary" do
|
@@ -210,9 +216,9 @@ describe 'Sinatra::Helpers' do
|
|
210
216
|
}
|
211
217
|
|
212
218
|
get '/foo.xml'
|
213
|
-
|
214
|
-
|
215
|
-
|
219
|
+
should.be.ok
|
220
|
+
response['Content-Type'].should.equal 'application/foo'
|
221
|
+
body.should.equal 'I AM FOO'
|
216
222
|
end
|
217
223
|
|
218
224
|
it 'fails when no mime type is registered for the argument provided' do
|
@@ -222,7 +228,8 @@ describe 'Sinatra::Helpers' do
|
|
222
228
|
"I AM FOO"
|
223
229
|
end
|
224
230
|
}
|
225
|
-
|
231
|
+
|
232
|
+
lambda { get '/foo.xml' }.should.raise RuntimeError
|
226
233
|
end
|
227
234
|
end
|
228
235
|
|
@@ -248,26 +255,26 @@ describe 'Sinatra::Helpers' do
|
|
248
255
|
it "sends the contents of the file" do
|
249
256
|
send_file_app
|
250
257
|
get '/file.txt'
|
251
|
-
|
252
|
-
|
258
|
+
should.be.ok
|
259
|
+
body.should.equal 'Hello World'
|
253
260
|
end
|
254
261
|
|
255
262
|
it 'sets the Content-Type response header if a mime-type can be located' do
|
256
263
|
send_file_app
|
257
264
|
get '/file.txt'
|
258
|
-
|
265
|
+
response['Content-Type'].should.equal 'text/plain'
|
259
266
|
end
|
260
267
|
|
261
268
|
it 'sets the Content-Length response header' do
|
262
269
|
send_file_app
|
263
270
|
get '/file.txt'
|
264
|
-
|
271
|
+
response['Content-Length'].should.equal 'Hello World'.length.to_s
|
265
272
|
end
|
266
273
|
|
267
274
|
it 'sets the Last-Modified response header' do
|
268
275
|
send_file_app
|
269
276
|
get '/file.txt'
|
270
|
-
|
277
|
+
response['Last-Modified'].should.equal File.mtime(@file).httpdate
|
271
278
|
end
|
272
279
|
|
273
280
|
it "returns a 404 when not found" do
|
@@ -277,7 +284,7 @@ describe 'Sinatra::Helpers' do
|
|
277
284
|
end
|
278
285
|
}
|
279
286
|
get '/'
|
280
|
-
|
287
|
+
should.be.not_found
|
281
288
|
end
|
282
289
|
end
|
283
290
|
|
@@ -296,19 +303,19 @@ describe 'Sinatra::Helpers' do
|
|
296
303
|
|
297
304
|
it 'sets the Last-Modified header to a valid RFC 2616 date value' do
|
298
305
|
get '/'
|
299
|
-
|
306
|
+
response['Last-Modified'].should.equal @now.httpdate
|
300
307
|
end
|
301
308
|
|
302
309
|
it 'returns a body when conditional get misses' do
|
303
310
|
get '/'
|
304
|
-
|
305
|
-
|
311
|
+
status.should.be 200
|
312
|
+
body.should.equal 'Boo!'
|
306
313
|
end
|
307
314
|
|
308
315
|
it 'halts when a conditional GET matches' do
|
309
316
|
get '/', :env => { 'HTTP_IF_MODIFIED_SINCE' => @now.httpdate }
|
310
|
-
|
311
|
-
|
317
|
+
status.should.be 304
|
318
|
+
body.should.be.empty
|
312
319
|
end
|
313
320
|
end
|
314
321
|
|
@@ -325,25 +332,25 @@ describe 'Sinatra::Helpers' do
|
|
325
332
|
|
326
333
|
it 'sets the ETag header' do
|
327
334
|
get '/'
|
328
|
-
|
335
|
+
response['ETag'].should.equal '"FOO"'
|
329
336
|
end
|
330
337
|
|
331
338
|
it 'returns a body when conditional get misses' do
|
332
339
|
get '/'
|
333
|
-
|
334
|
-
|
340
|
+
status.should.be 200
|
341
|
+
body.should.equal 'Boo!'
|
335
342
|
end
|
336
343
|
|
337
344
|
it 'halts when a conditional GET matches' do
|
338
345
|
get '/', :env => { 'HTTP_IF_NONE_MATCH' => '"FOO"' }
|
339
|
-
|
340
|
-
|
346
|
+
status.should.be 304
|
347
|
+
body.should.be.empty
|
341
348
|
end
|
342
349
|
|
343
350
|
it 'should handle multiple ETag values in If-None-Match header' do
|
344
351
|
get '/', :env => { 'HTTP_IF_NONE_MATCH' => '"BAR", *' }
|
345
|
-
|
346
|
-
|
352
|
+
status.should.be 304
|
353
|
+
body.should.be.empty
|
347
354
|
end
|
348
355
|
|
349
356
|
it 'uses a weak etag with the :weak option' do
|
@@ -354,7 +361,7 @@ describe 'Sinatra::Helpers' do
|
|
354
361
|
end
|
355
362
|
}
|
356
363
|
get '/'
|
357
|
-
|
364
|
+
response['ETag'].should.equal 'W/"FOO"'
|
358
365
|
end
|
359
366
|
|
360
367
|
end
|
data/test/mapped_error_test.rb
CHANGED
@@ -1,6 +1,10 @@
|
|
1
|
-
require
|
1
|
+
require 'test/spec'
|
2
|
+
require 'sinatra/base'
|
3
|
+
require 'sinatra/test'
|
2
4
|
|
3
5
|
describe 'Exception Mappings' do
|
6
|
+
include Sinatra::Test
|
7
|
+
|
4
8
|
class FooError < RuntimeError
|
5
9
|
end
|
6
10
|
|
@@ -13,8 +17,8 @@ describe 'Exception Mappings' do
|
|
13
17
|
end
|
14
18
|
}
|
15
19
|
get '/'
|
16
|
-
|
17
|
-
|
20
|
+
status.should.equal 500
|
21
|
+
body.should.equal 'Foo!'
|
18
22
|
end
|
19
23
|
|
20
24
|
it 'uses the Exception handler if no matching handler found' do
|
@@ -26,16 +30,16 @@ describe 'Exception Mappings' do
|
|
26
30
|
end
|
27
31
|
}
|
28
32
|
get '/'
|
29
|
-
|
30
|
-
|
33
|
+
status.should.equal 500
|
34
|
+
body.should.equal 'Exception!'
|
31
35
|
end
|
32
36
|
|
33
37
|
it "sets env['sinatra.error'] to the rescued exception" do
|
34
38
|
mock_app {
|
35
39
|
set :raise_errors, false
|
36
40
|
error(FooError) {
|
37
|
-
|
38
|
-
|
41
|
+
env.should.include 'sinatra.error'
|
42
|
+
env['sinatra.error'].should.be.kind_of FooError
|
39
43
|
'looks good'
|
40
44
|
}
|
41
45
|
get '/' do
|
@@ -43,19 +47,7 @@ describe 'Exception Mappings' do
|
|
43
47
|
end
|
44
48
|
}
|
45
49
|
get '/'
|
46
|
-
|
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!:/
|
50
|
+
body.should.equal 'looks good'
|
59
51
|
end
|
60
52
|
|
61
53
|
it "raises without calling the handler when the raise_errors options is set" do
|
@@ -66,7 +58,7 @@ describe 'Exception Mappings' do
|
|
66
58
|
raise FooError
|
67
59
|
end
|
68
60
|
}
|
69
|
-
|
61
|
+
lambda { get '/' }.should.raise FooError
|
70
62
|
end
|
71
63
|
|
72
64
|
it "never raises Sinatra::NotFound beyond the application" do
|
@@ -76,8 +68,8 @@ describe 'Exception Mappings' do
|
|
76
68
|
raise Sinatra::NotFound
|
77
69
|
end
|
78
70
|
}
|
79
|
-
|
80
|
-
|
71
|
+
lambda { get '/' }.should.not.raise Sinatra::NotFound
|
72
|
+
status.should.equal 404
|
81
73
|
end
|
82
74
|
|
83
75
|
class FooNotFound < Sinatra::NotFound
|
@@ -91,22 +83,11 @@ describe 'Exception Mappings' do
|
|
91
83
|
raise FooNotFound
|
92
84
|
end
|
93
85
|
}
|
94
|
-
|
95
|
-
|
96
|
-
|
86
|
+
lambda { get '/' }.should.not.raise FooNotFound
|
87
|
+
status.should.equal 404
|
88
|
+
body.should.equal 'foo! not found.'
|
97
89
|
end
|
98
90
|
|
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
|
110
91
|
end
|
111
92
|
|
112
93
|
describe 'Custom Error Pages' do
|
@@ -119,8 +100,8 @@ describe 'Custom Error Pages' do
|
|
119
100
|
end
|
120
101
|
}
|
121
102
|
get '/'
|
122
|
-
|
123
|
-
|
103
|
+
status.should.equal 500
|
104
|
+
body.should.equal 'Foo!'
|
124
105
|
end
|
125
106
|
|
126
107
|
it 'allows ranges of status code mappings to be registered with :error' do
|
@@ -132,8 +113,8 @@ describe 'Custom Error Pages' do
|
|
132
113
|
end
|
133
114
|
}
|
134
115
|
get '/'
|
135
|
-
|
136
|
-
|
116
|
+
status.should.equal 507
|
117
|
+
body.should.equal 'Error: 507'
|
137
118
|
end
|
138
119
|
|
139
120
|
class FooError < RuntimeError
|
@@ -154,7 +135,7 @@ describe 'Custom Error Pages' do
|
|
154
135
|
end
|
155
136
|
}
|
156
137
|
get '/'
|
157
|
-
|
158
|
-
|
138
|
+
status.should.equal 502
|
139
|
+
body.should.equal 'from custom error page'
|
159
140
|
end
|
160
141
|
end
|