bmizerany-sinatra 0.9.0 → 0.9.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/test/helpers_test.rb CHANGED
@@ -1,10 +1,4 @@
1
- require 'test/spec'
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.should.equal 207
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
- body.should.equal 'Hello World'
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
- body.should.equal 'Hello World'
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
- status.should.equal 302
61
- body.should.be.empty
62
- response['Location'].should.equal '/foo'
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
- status.should.equal 301
75
- body.should.be.empty
76
- response['Location'].should.equal '/foo'
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
- status.should.equal 501
91
- body.should.be.empty
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
- status.should.equal 501
104
- body.should.equal 'FAIL'
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
- status.should.equal 500
117
- body.should.equal 'FAIL'
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
- status.should.equal 404
132
- body.should.be.empty
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
- body.should.equal 'bar'
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.should.be.empty
145
+ assert session.empty?
152
146
  session[:foo] = 'bar'
153
147
  'Hi'
154
148
  end
155
149
  }
156
150
 
157
151
  get '/'
158
- body.should.equal 'Hi'
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
- media_type('foo').should.equal 'application/foo'
167
- media_type('.foo').should.equal 'application/foo'
168
- media_type(:foo).should.equal 'application/foo'
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).should.be.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).should.be.nil
168
+ assert media_type(:bizzle).nil?
175
169
  end
176
170
  it 'returns the argument when given a media type string' do
177
- media_type('text/plain').should.equal 'text/plain'
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'].should.equal 'text/plain'
192
- body.should.equal 'Hello World'
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
- should.be.ok
205
- response['Content-Type'].should.equal 'text/html;charset=utf-8'
206
- body.should.equal "<h1>Hello, World</h1>"
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
- should.be.ok
220
- response['Content-Type'].should.equal 'application/foo'
221
- body.should.equal 'I AM FOO'
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
- should.be.ok
259
- body.should.equal 'Hello World'
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'].should.equal 'text/plain'
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
- response['Content-Length'].should.equal 'Hello World'.length.to_s
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
- response['Last-Modified'].should.equal File.mtime(@file).httpdate
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
- should.be.not_found
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'].should.equal @now.httpdate
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
- status.should.be 200
312
- body.should.equal 'Boo!'
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
- status.should.be 304
318
- body.should.be.empty
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'].should.equal '"FOO"'
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
- status.should.be 200
341
- body.should.equal 'Boo!'
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
- status.should.be 304
347
- body.should.be.empty
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
- status.should.be 304
353
- body.should.be.empty
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
- response['ETag'].should.equal 'W/"FOO"'
357
+ assert_equal 'W/"FOO"', response['ETag']
365
358
  end
366
359
 
367
360
  end
@@ -1,10 +1,6 @@
1
- require 'test/spec'
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
- status.should.equal 500
21
- body.should.equal 'Foo!'
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
- status.should.equal 500
34
- body.should.equal 'Exception!'
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.should.include 'sinatra.error'
42
- env['sinatra.error'].should.be.kind_of FooError
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
- body.should.equal 'looks good'
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
- lambda { get '/' }.should.raise FooError
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
- lambda { get '/' }.should.not.raise Sinatra::NotFound
72
- status.should.equal 404
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
- lambda { get '/' }.should.not.raise FooNotFound
87
- status.should.equal 404
88
- body.should.equal 'foo! not found.'
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
- status.should.equal 500
104
- body.should.equal 'Foo!'
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
- status.should.equal 507
117
- body.should.equal 'Error: 507'
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
- status.should.equal 502
139
- body.should.equal 'from custom error page'
157
+ assert_equal 502, status
158
+ assert_equal 'from custom error page', body
140
159
  end
141
160
  end
@@ -1,10 +1,6 @@
1
- require 'test/spec'
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
- response.should.be.ok
35
- body.should.equal '/HELLO-WORLD'
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
- body.should.equal "/foo"
50
- response['X-Tests'].should.equal "UpcaseMiddleware, DowncaseMiddleware"
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
- body.should.equal "/FOO"
52
+ assert_equal "/FOO", body
57
53
  @app.use DowncaseMiddleware
58
54
  get '/Foo'
59
- body.should.equal '/foo'
60
- response['X-Tests'].should.equal "UpcaseMiddleware, DowncaseMiddleware"
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 'test/spec'
2
- require 'sinatra/base'
3
- require 'sinatra/test'
1
+ require File.dirname(__FILE__) + '/helper'
4
2
 
5
3
  describe 'Options' do
6
- include Sinatra::Test
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.should.respond_to? :foo
15
- @app.foo.should.equal 'bar'
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.should.respond_to? :foo
21
- @app.foo.should.equal 'baz'
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.should.equal 1234
29
- @app.bar.should.equal 'Hello World'
30
- @app.baz.should.equal 'bizzle'
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.should.respond_to :foo
39
- sub.foo.should.equal 'bar'
40
- sub.should.respond_to :biz
41
- sub.biz.should.equal 'baz'
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
- sub.foo.should.equal 'bling'
50
- @app.foo.should.equal 'bar'
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.should.respond_to 'foo='
49
+ assert @app.respond_to?('foo=')
56
50
  @app.foo = 'biz'
57
- @app.foo.should.equal 'biz'
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.should.respond_to :foo?
63
- @app.foo?.should.be true
56
+ assert @app.respond_to?(:foo?)
57
+ assert @app.foo?
64
58
  @app.set :foo, nil
65
- @app.foo?.should.be false
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.should.equal 'oops'
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.should.be true
85
- @app.foo.should.be true
86
- @app.bar.should.be true
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
- @app.sessions.should.be false
92
- @app.foo.should.be false
93
- @app.bar.should.be false
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
- status.should.equal 200
101
- body.should.equal 'okay'
94
+ assert_equal 200, status
95
+ assert_equal 'okay', body
102
96
  end
103
97
  end