bmizerany-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/test/reload_test.rb CHANGED
@@ -1,9 +1,13 @@
1
- require File.dirname(__FILE__) + '/helper'
1
+ require 'test/spec'
2
+ require 'sinatra/base'
3
+ require 'sinatra/test'
2
4
 
3
5
  $reload_count = 0
4
6
  $reload_app = nil
5
7
 
6
8
  describe "Reloading" do
9
+ include Sinatra::Test
10
+
7
11
  before {
8
12
  @app = mock_app(Sinatra::Default)
9
13
  $reload_app = @app
@@ -16,31 +20,31 @@ describe "Reloading" do
16
20
  it 'is enabled by default when in development and the app_file is set' do
17
21
  @app.set :app_file, __FILE__
18
22
  @app.set :environment, :development
19
- assert_same true, @app.reload
20
- assert_same true, @app.reload?
23
+ @app.reload.should.be true
24
+ @app.reload?.should.be true
21
25
  end
22
26
 
23
27
  it 'is disabled by default when running in non-development environment' do
24
28
  @app.set :app_file, __FILE__
25
29
  @app.set :environment, :test
26
- assert !@app.reload
27
- assert_same false, @app.reload?
30
+ @app.reload.should.not.be true
31
+ @app.reload?.should.be false
28
32
  end
29
33
 
30
34
  it 'is disabled by default when no app_file is available' do
31
35
  @app.set :app_file, nil
32
36
  @app.set :environment, :development
33
- assert !@app.reload
34
- assert_same false, @app.reload?
37
+ @app.reload.should.not.be true
38
+ @app.reload?.should.be false
35
39
  end
36
40
 
37
41
  it 'can be turned off explicitly' do
38
42
  @app.set :app_file, __FILE__
39
43
  @app.set :environment, :development
40
- assert_same true, @app.reload
44
+ @app.reload.should.be true
41
45
  @app.set :reload, false
42
- assert_same false, @app.reload
43
- assert_same false, @app.reload?
46
+ @app.reload.should.be false
47
+ @app.reload?.should.be false
44
48
  end
45
49
 
46
50
  it 'reloads the app_file each time a request is made' do
@@ -49,13 +53,13 @@ describe "Reloading" do
49
53
  @app.get('/') { 'Hello World' }
50
54
 
51
55
  get '/'
52
- assert_equal 200, status
53
- assert_equal 'Hello from reload file', body
54
- assert_equal 1, $reload_count
56
+ status.should.equal 200
57
+ body.should.equal 'Hello from reload file'
58
+ $reload_count.should.equal 1
55
59
 
56
60
  get '/'
57
- assert_equal 200, status
58
- assert_equal 'Hello from reload file', body
59
- assert_equal 2, $reload_count
61
+ status.should.equal 200
62
+ body.should.equal 'Hello from reload file'
63
+ $reload_count.should.equal 2
60
64
  end
61
65
  end
data/test/request_test.rb CHANGED
@@ -1,18 +1,11 @@
1
- require File.dirname(__FILE__) + '/helper'
1
+ require 'test/spec'
2
+ require 'sinatra/base'
3
+ require 'sinatra/test'
2
4
 
3
5
  describe 'Sinatra::Request' do
4
6
  it 'responds to #user_agent' do
5
7
  request = Sinatra::Request.new({'HTTP_USER_AGENT' => 'Test'})
6
- assert request.respond_to?(:user_agent)
7
- assert_equal 'Test', request.user_agent
8
- end
9
-
10
- it 'parses POST params when Content-Type is form-dataish' do
11
- request = Sinatra::Request.new(
12
- 'REQUEST_METHOD' => 'PUT',
13
- 'CONTENT_TYPE' => 'application/x-www-form-urlencoded',
14
- 'rack.input' => StringIO.new('foo=bar')
15
- )
16
- assert_equal 'bar', request.params['foo']
8
+ request.should.respond_to :user_agent
9
+ request.user_agent.should.equal 'Test'
17
10
  end
18
11
  end
data/test/result_test.rb CHANGED
@@ -1,6 +1,10 @@
1
- require File.dirname(__FILE__) + '/helper'
1
+ require 'test/spec'
2
+ require 'sinatra/base'
3
+ require 'sinatra/test'
2
4
 
3
5
  describe 'Result Handling' do
6
+ include Sinatra::Test
7
+
4
8
  it "sets response.body when result is a String" do
5
9
  mock_app {
6
10
  get '/' do
@@ -9,8 +13,8 @@ describe 'Result Handling' do
9
13
  }
10
14
 
11
15
  get '/'
12
- assert ok?
13
- assert_equal 'Hello World', body
16
+ should.be.ok
17
+ body.should.equal 'Hello World'
14
18
  end
15
19
 
16
20
  it "sets response.body when result is an Array of Strings" do
@@ -21,8 +25,8 @@ describe 'Result Handling' do
21
25
  }
22
26
 
23
27
  get '/'
24
- assert ok?
25
- assert_equal 'HelloWorld', body
28
+ should.be.ok
29
+ body.should.equal 'HelloWorld'
26
30
  end
27
31
 
28
32
  it "sets response.body when result responds to #each" do
@@ -35,8 +39,8 @@ describe 'Result Handling' do
35
39
  }
36
40
 
37
41
  get '/'
38
- assert ok?
39
- assert_equal 'Hello World', body
42
+ should.be.ok
43
+ body.should.equal 'Hello World'
40
44
  end
41
45
 
42
46
  it "sets response.body to [] when result is nil" do
@@ -47,8 +51,8 @@ describe 'Result Handling' do
47
51
  }
48
52
 
49
53
  get '/'
50
- assert ok?
51
- assert_equal '', body
54
+ should.be.ok
55
+ body.should.equal ''
52
56
  end
53
57
 
54
58
  it "sets status, headers, and body when result is a Rack response tuple" do
@@ -59,9 +63,9 @@ describe 'Result Handling' do
59
63
  }
60
64
 
61
65
  get '/'
62
- assert_equal 205, status
63
- assert_equal 'foo/bar', response['Content-Type']
64
- assert_equal 'Hello World', body
66
+ status.should.equal 205
67
+ response['Content-Type'].should.equal 'foo/bar'
68
+ body.should.equal 'Hello World'
65
69
  end
66
70
 
67
71
  it "sets status and body when result is a two-tuple" do
@@ -72,8 +76,8 @@ describe 'Result Handling' do
72
76
  }
73
77
 
74
78
  get '/'
75
- assert_equal 409, status
76
- assert_equal 'formula of', body
79
+ status.should.equal 409
80
+ body.should.equal 'formula of'
77
81
  end
78
82
 
79
83
  it "sets status when result is a Fixnum status code" do
@@ -82,7 +86,7 @@ describe 'Result Handling' do
82
86
  }
83
87
 
84
88
  get '/'
85
- assert_equal 205, status
86
- assert_equal '', body
89
+ status.should.equal 205
90
+ body.should.be.empty
87
91
  end
88
92
  end
data/test/routing_test.rb CHANGED
@@ -1,6 +1,10 @@
1
- require File.dirname(__FILE__) + '/helper'
1
+ require 'test/spec'
2
+ require 'sinatra/base'
3
+ require 'sinatra/test'
2
4
 
3
5
  describe "Routing" do
6
+ include Sinatra::Test
7
+
4
8
  %w[get put post delete head].each do |verb|
5
9
  it "defines #{verb.upcase} request handlers with #{verb}" do
6
10
  mock_app {
@@ -11,8 +15,8 @@ describe "Routing" do
11
15
 
12
16
  request = Rack::MockRequest.new(@app)
13
17
  response = request.request(verb.upcase, '/hello', {})
14
- assert response.ok?
15
- assert_equal 'Hello World', response.body
18
+ response.should.be.ok
19
+ response.body.should.equal 'Hello World'
16
20
  end
17
21
  end
18
22
 
@@ -21,30 +25,30 @@ describe "Routing" do
21
25
  get('/foo') { }
22
26
  }
23
27
  get '/bar'
24
- assert_equal 404, status
28
+ status.should.equal 404
25
29
  end
26
30
 
27
31
  it "exposes params with indifferent hash" do
28
32
  mock_app {
29
33
  get '/:foo' do
30
- assert_equal 'bar', params['foo']
31
- assert_equal 'bar', params[:foo]
34
+ params['foo'].should.equal 'bar'
35
+ params[:foo].should.equal 'bar'
32
36
  'well, alright'
33
37
  end
34
38
  }
35
39
  get '/bar'
36
- assert_equal 'well, alright', body
40
+ body.should.equal 'well, alright'
37
41
  end
38
42
 
39
43
  it "merges named params and query string params in params" do
40
44
  mock_app {
41
45
  get '/:foo' do
42
- assert_equal 'bar', params['foo']
43
- assert_equal 'biz', params['baz']
46
+ params['foo'].should.equal 'bar'
47
+ params['baz'].should.equal 'biz'
44
48
  end
45
49
  }
46
50
  get '/bar?baz=biz'
47
- assert ok?
51
+ should.be.ok
48
52
  end
49
53
 
50
54
  it "supports named params like /hello/:person" do
@@ -54,7 +58,7 @@ describe "Routing" do
54
58
  end
55
59
  }
56
60
  get '/hello/Frank'
57
- assert_equal 'Hello Frank', body
61
+ body.should.equal 'Hello Frank'
58
62
  end
59
63
 
60
64
  it "supports optional named params like /?:foo?/?:bar?" do
@@ -65,115 +69,58 @@ describe "Routing" do
65
69
  }
66
70
 
67
71
  get '/hello/world'
68
- assert ok?
69
- assert_equal "foo=hello;bar=world", body
72
+ should.be.ok
73
+ body.should.equal "foo=hello;bar=world"
70
74
 
71
75
  get '/hello'
72
- assert ok?
73
- assert_equal "foo=hello;bar=", body
76
+ should.be.ok
77
+ body.should.equal "foo=hello;bar="
74
78
 
75
79
  get '/'
76
- assert ok?
77
- assert_equal "foo=;bar=", body
80
+ should.be.ok
81
+ body.should.equal "foo=;bar="
78
82
  end
79
83
 
80
84
  it "supports single splat params like /*" do
81
85
  mock_app {
82
86
  get '/*' do
83
- assert params['splat'].kind_of?(Array)
87
+ params['splat'].should.be.kind_of Array
84
88
  params['splat'].join "\n"
85
89
  end
86
90
  }
87
91
 
88
92
  get '/foo'
89
- assert_equal "foo", body
93
+ body.should.equal "foo"
90
94
 
91
95
  get '/foo/bar/baz'
92
- assert_equal "foo/bar/baz", body
96
+ body.should.equal "foo/bar/baz"
93
97
  end
94
98
 
95
99
  it "supports mixing multiple splat params like /*/foo/*/*" do
96
100
  mock_app {
97
101
  get '/*/foo/*/*' do
98
- assert params['splat'].kind_of?(Array)
102
+ params['splat'].should.be.kind_of Array
99
103
  params['splat'].join "\n"
100
104
  end
101
105
  }
102
106
 
103
107
  get '/bar/foo/bling/baz/boom'
104
- assert_equal "bar\nbling\nbaz/boom", body
108
+ body.should.equal "bar\nbling\nbaz/boom"
105
109
 
106
110
  get '/bar/foo/baz'
107
- assert not_found?
111
+ should.be.not_found
108
112
  end
109
113
 
110
114
  it "supports mixing named and splat params like /:foo/*" do
111
115
  mock_app {
112
116
  get '/:foo/*' do
113
- assert_equal 'foo', params['foo']
114
- assert_equal ['bar/baz'], params['splat']
117
+ params['foo'].should.equal 'foo'
118
+ params['splat'].should.equal ['bar/baz']
115
119
  end
116
120
  }
117
121
 
118
122
  get '/foo/bar/baz'
119
- assert ok?
120
- end
121
-
122
- it "supports basic nested params" do
123
- mock_app {
124
- get '/hi' do
125
- params["person"]["name"]
126
- end
127
- }
128
-
129
- get "/hi?person[name]=John+Doe"
130
- assert ok?
131
- assert_equal "John Doe", body
132
- end
133
-
134
- it "exposes nested params with indifferent hash" do
135
- mock_app {
136
- get '/testme' do
137
- assert_equal 'baz', params['bar']['foo']
138
- assert_equal 'baz', params['bar'][:foo]
139
- 'well, alright'
140
- end
141
- }
142
- get '/testme?bar[foo]=baz'
143
- assert_equal 'well, alright', body
144
- end
145
-
146
- it "supports deeply nested params" do
147
- input = {
148
- 'browser[chrome][engine][name]' => 'V8',
149
- 'browser[chrome][engine][version]' => '1.0',
150
- 'browser[firefox][engine][name]' => 'spidermonkey',
151
- 'browser[firefox][engine][version]' => '1.7.0',
152
- 'emacs[map][goto-line]' => 'M-g g',
153
- 'emacs[version]' => '22.3.1',
154
- 'paste[name]' => 'hello world',
155
- 'paste[syntax]' => 'ruby'
156
- }
157
- expected = {
158
- "emacs" => {
159
- "map" => { "goto-line" => "M-g g" },
160
- "version" => "22.3.1"
161
- },
162
- "browser" => {
163
- "firefox" => {"engine" => {"name"=>"spidermonkey", "version"=>"1.7.0"}},
164
- "chrome" => {"engine" => {"name"=>"V8", "version"=>"1.0"}}
165
- },
166
- "paste" => {"name"=>"hello world", "syntax"=>"ruby"}
167
- }
168
- mock_app {
169
- get '/foo' do
170
- assert_equal expected, params
171
- 'looks good'
172
- end
173
- }
174
- get "/foo?#{param_string(input)}"
175
- assert ok?
176
- assert_equal 'looks good', body
123
+ should.be.ok
177
124
  end
178
125
 
179
126
  it "supports paths that include spaces" do
@@ -184,21 +131,21 @@ describe "Routing" do
184
131
  }
185
132
 
186
133
  get '/path%20with%20spaces'
187
- assert ok?
188
- assert_equal 'looks good', body
134
+ should.be.ok
135
+ body.should.equal 'looks good'
189
136
  end
190
137
 
191
138
  it "URL decodes named parameters and splats" do
192
139
  mock_app {
193
140
  get '/:foo/*' do
194
- assert_equal 'hello world', params['foo']
195
- assert_equal ['how are you'], params['splat']
141
+ params['foo'].should.equal 'hello world'
142
+ params['splat'].should.equal ['how are you']
196
143
  nil
197
144
  end
198
145
  }
199
146
 
200
147
  get '/hello%20world/how%20are%20you'
201
- assert ok?
148
+ should.be.ok
202
149
  end
203
150
 
204
151
  it 'supports regular expressions' do
@@ -209,21 +156,21 @@ describe "Routing" do
209
156
  }
210
157
 
211
158
  get '/foooom/bar'
212
- assert ok?
213
- assert_equal 'Hello World', body
159
+ should.be.ok
160
+ body.should.equal 'Hello World'
214
161
  end
215
162
 
216
163
  it 'makes regular expression captures available in params[:captures]' do
217
164
  mock_app {
218
165
  get(/^\/fo(.*)\/ba(.*)/) do
219
- assert_equal ['orooomma', 'f'], params[:captures]
166
+ params[:captures].should.equal ['orooomma', 'f']
220
167
  'right on'
221
168
  end
222
169
  }
223
170
 
224
171
  get '/foorooomma/baf'
225
- assert ok?
226
- assert_equal 'right on', body
172
+ should.be.ok
173
+ body.should.equal 'right on'
227
174
  end
228
175
 
229
176
  it "returns response immediately on halt" do
@@ -235,8 +182,8 @@ describe "Routing" do
235
182
  }
236
183
 
237
184
  get '/'
238
- assert ok?
239
- assert_equal 'Hello World', body
185
+ should.be.ok
186
+ body.should.equal 'Hello World'
240
187
  end
241
188
 
242
189
  it "transitions to the next matching route on pass" do
@@ -247,14 +194,14 @@ describe "Routing" do
247
194
  end
248
195
 
249
196
  get '/*' do
250
- assert !params.include?('foo')
197
+ params.should.not.include 'foo'
251
198
  'Hello World'
252
199
  end
253
200
  }
254
201
 
255
202
  get '/bar'
256
- assert ok?
257
- assert_equal 'Hello World', body
203
+ should.be.ok
204
+ body.should.equal 'Hello World'
258
205
  end
259
206
 
260
207
  it "transitions to 404 when passed and no subsequent route matches" do
@@ -266,7 +213,7 @@ describe "Routing" do
266
213
  }
267
214
 
268
215
  get '/bar'
269
- assert not_found?
216
+ should.be.not_found
270
217
  end
271
218
 
272
219
  it "passes when matching condition returns false" do
@@ -278,11 +225,11 @@ describe "Routing" do
278
225
  }
279
226
 
280
227
  get '/bar'
281
- assert ok?
282
- assert_equal 'Hello World', body
228
+ should.be.ok
229
+ body.should.equal 'Hello World'
283
230
 
284
231
  get '/foo'
285
- assert not_found?
232
+ should.be.not_found
286
233
  end
287
234
 
288
235
  it "does not pass when matching condition returns nil" do
@@ -294,8 +241,8 @@ describe "Routing" do
294
241
  }
295
242
 
296
243
  get '/bar'
297
- assert ok?
298
- assert_equal 'Hello World', body
244
+ should.be.ok
245
+ body.should.equal 'Hello World'
299
246
  end
300
247
 
301
248
  it "passes to next route when condition calls pass explicitly" do
@@ -307,11 +254,11 @@ describe "Routing" do
307
254
  }
308
255
 
309
256
  get '/bar'
310
- assert ok?
311
- assert_equal 'Hello World', body
257
+ should.be.ok
258
+ body.should.equal 'Hello World'
312
259
 
313
260
  get '/foo'
314
- assert not_found?
261
+ should.be.not_found
315
262
  end
316
263
 
317
264
  it "passes to the next route when host_name does not match" do
@@ -322,38 +269,38 @@ describe "Routing" do
322
269
  end
323
270
  }
324
271
  get '/foo'
325
- assert not_found?
272
+ should.be.not_found
326
273
 
327
274
  get '/foo', :env => { 'HTTP_HOST' => 'example.com' }
328
- assert_equal 200, status
329
- assert_equal 'Hello World', body
275
+ status.should.equal 200
276
+ body.should.equal 'Hello World'
330
277
  end
331
278
 
332
279
  it "passes to the next route when user_agent does not match" do
333
280
  mock_app {
334
- user_agent(/Foo/)
281
+ user_agent /Foo/
335
282
  get '/foo' do
336
283
  'Hello World'
337
284
  end
338
285
  }
339
286
  get '/foo'
340
- assert not_found?
287
+ should.be.not_found
341
288
 
342
289
  get '/foo', :env => { 'HTTP_USER_AGENT' => 'Foo Bar' }
343
- assert_equal 200, status
344
- assert_equal 'Hello World', body
290
+ status.should.equal 200
291
+ body.should.equal 'Hello World'
345
292
  end
346
293
 
347
294
  it "makes captures in user agent pattern available in params[:agent]" do
348
295
  mock_app {
349
- user_agent(/Foo (.*)/)
296
+ user_agent /Foo (.*)/
350
297
  get '/foo' do
351
298
  'Hello ' + params[:agent].first
352
299
  end
353
300
  }
354
301
  get '/foo', :env => { 'HTTP_USER_AGENT' => 'Foo Bar' }
355
- assert_equal 200, status
356
- assert_equal 'Hello Bar', body
302
+ status.should.equal 200
303
+ body.should.equal 'Hello Bar'
357
304
  end
358
305
 
359
306
  it "filters by accept header" do
@@ -364,12 +311,12 @@ describe "Routing" do
364
311
  }
365
312
 
366
313
  get '/', :env => { :accept => 'application/xml' }
367
- assert ok?
368
- assert_equal 'application/xml', body
369
- assert_equal 'application/xml', response.headers['Content-Type']
314
+ should.be.ok
315
+ body.should.equal 'application/xml'
316
+ response.headers['Content-Type'].should.equal 'application/xml'
370
317
 
371
318
  get '/', :env => { :accept => 'text/html' }
372
- assert !ok?
319
+ should.not.be.ok
373
320
  end
374
321
 
375
322
  it "allows multiple mime types for accept header" do
@@ -383,9 +330,9 @@ describe "Routing" do
383
330
 
384
331
  types.each do |type|
385
332
  get '/', :env => { :accept => type }
386
- assert ok?
387
- assert_equal type, body
388
- assert_equal type, response.headers['Content-Type']
333
+ should.be.ok
334
+ body.should.equal type
335
+ response.headers['Content-Type'].should.equal type
389
336
  end
390
337
  end
391
338
  end
data/test/sass_test.rb CHANGED
@@ -1,6 +1,10 @@
1
- require File.dirname(__FILE__) + '/helper'
1
+ require 'test/spec'
2
+ require 'sinatra/base'
3
+ require 'sinatra/test'
2
4
 
3
5
  describe "Sass Templates" do
6
+ include Sinatra::Test
7
+
4
8
  def sass_app(&block)
5
9
  mock_app {
6
10
  set :views, File.dirname(__FILE__) + '/views'
@@ -11,26 +15,26 @@ describe "Sass Templates" do
11
15
 
12
16
  it 'renders inline Sass strings' do
13
17
  sass_app { sass "#sass\n :background-color #FFF\n" }
14
- assert ok?
15
- assert_equal "#sass {\n background-color: #FFF; }\n", body
18
+ should.be.ok
19
+ body.should.equal "#sass {\n background-color: #FFF; }\n"
16
20
  end
17
21
 
18
22
  it 'renders .sass files in views path' do
19
23
  sass_app { sass :hello }
20
- assert ok?
21
- assert_equal "#sass {\n background-color: #FFF; }\n", body
24
+ should.be.ok
25
+ body.should.equal "#sass {\n background-color: #FFF; }\n"
22
26
  end
23
27
 
24
28
  it 'ignores the layout option' do
25
29
  sass_app { sass :hello, :layout => :layout2 }
26
- assert ok?
27
- assert_equal "#sass {\n background-color: #FFF; }\n", body
30
+ should.be.ok
31
+ body.should.equal "#sass {\n background-color: #FFF; }\n"
28
32
  end
29
33
 
30
34
  it "raises error if template not found" do
31
35
  mock_app {
32
36
  get('/') { sass :no_such_template }
33
37
  }
34
- assert_raise(Errno::ENOENT) { get('/') }
38
+ lambda { get('/') }.should.raise(Errno::ENOENT)
35
39
  end
36
40
  end
data/test/sinatra_test.rb CHANGED
@@ -1,4 +1,6 @@
1
- require File.dirname(__FILE__) + '/helper'
1
+ require 'test/spec'
2
+ require 'sinatra/base'
3
+ require 'sinatra/test'
2
4
 
3
5
  describe 'Sinatra' do
4
6
  it 'creates a new Sinatra::Base subclass on new' do
@@ -8,6 +10,6 @@ describe 'Sinatra' do
8
10
  'Hello World'
9
11
  end
10
12
  end
11
- assert_same Sinatra::Base, app.superclass
13
+ app.superclass.should.be Sinatra::Base
12
14
  end
13
15
  end