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/test/filter_test.rb CHANGED
@@ -1,24 +1,28 @@
1
- require File.dirname(__FILE__) + '/helper'
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
- assert_equal 0, count
13
+ count.should.be 0
10
14
  count = 1
11
15
  }
12
16
  before {
13
- assert_equal 1, count
17
+ count.should.be 1
14
18
  count = 2
15
19
  }
16
20
  end
17
21
 
18
22
  get '/'
19
- assert ok?
20
- assert_equal 2, count
21
- assert_equal 'Hello World', body
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
- assert ok?
33
- assert_equal 'bar', body
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 File.dirname(__FILE__) + '/helper'
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
- assert ok?
15
- assert_equal "<h1>Hiya</h1>\n", body
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
- assert ok?
21
- assert_equal "<h1>Hello From Haml</h1>\n", body
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
- assert ok?
31
- assert_equal "<h1>THIS. IS. <EM>SPARTA</EM></h1>\n", body
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
- assert ok?
39
- assert_equal "<h1>HAML Layout!</h1>\n<p>Hello World</p>\n", body
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
- assert_raise(Errno::ENOENT) { get('/') }
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
- assert ok?
54
- assert_equal "<!DOCTYPE html>\n<h1>Hello World</h1>\n", body
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
- assert ok?
66
- assert_equal "<!DOCTYPE html>\n<h1>Hello World</h1>\n", body
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 File.dirname(__FILE__) + '/helper'
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
- assert_equal 207, response.status
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
- assert_equal 'Hello World', body
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
- assert_equal 'Hello World', body
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
- assert_equal 302, status
55
- assert_equal '', body
56
- assert_equal '/foo', response['Location']
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
- assert_equal 301, status
69
- assert_equal '', body
70
- assert_equal '/foo', response['Location']
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
- assert_equal 501, status
85
- assert_equal '', body
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
- assert_equal 501, status
98
- assert_equal 'FAIL', body
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
- assert_equal 500, status
111
- assert_equal 'FAIL', body
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
- assert_equal 404, status
126
- assert_equal '', body
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
- assert_equal 'bar', body
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
- assert session.empty?
151
+ session.should.be.empty
146
152
  session[:foo] = 'bar'
147
153
  'Hi'
148
154
  end
149
155
  }
150
156
 
151
157
  get '/'
152
- assert_equal 'Hi', body
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
- assert_equal 'application/foo', media_type('foo')
161
- assert_equal 'application/foo', media_type('.foo')
162
- assert_equal 'application/foo', media_type(: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'
163
169
  end
164
170
  it 'returns nil when given nil' do
165
- assert media_type(nil).nil?
171
+ media_type(nil).should.be.nil
166
172
  end
167
173
  it 'returns nil when media type not registered' do
168
- assert media_type(:bizzle).nil?
174
+ media_type(:bizzle).should.be.nil
169
175
  end
170
176
  it 'returns the argument when given a media type string' do
171
- assert_equal 'text/plain', media_type('text/plain')
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
- assert_equal 'text/plain', response['Content-Type']
186
- assert_equal 'Hello World', body
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
- assert ok?
199
- assert_equal 'text/html;charset=utf-8', response['Content-Type']
200
- assert_equal "<h1>Hello, World</h1>", body
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
- assert ok?
214
- assert_equal 'application/foo', response['Content-Type']
215
- assert_equal 'I AM FOO', body
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
- assert_raise(RuntimeError) { get '/foo.xml' }
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
- assert ok?
252
- assert_equal 'Hello World', body
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
- assert_equal 'text/plain', response['Content-Type']
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
- assert_equal 'Hello World'.length.to_s, response['Content-Length']
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
- assert_equal File.mtime(@file).httpdate, response['Last-Modified']
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
- assert not_found?
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
- assert_equal @now.httpdate, response['Last-Modified']
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
- assert_equal 200, status
305
- assert_equal 'Boo!', body
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
- assert_equal 304, status
311
- assert_equal '', body
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
- assert_equal '"FOO"', response['ETag']
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
- assert_equal 200, status
334
- assert_equal 'Boo!', body
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
- assert_equal 304, status
340
- assert_equal '', body
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
- assert_equal 304, status
346
- assert_equal '', body
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
- assert_equal 'W/"FOO"', response['ETag']
364
+ response['ETag'].should.equal 'W/"FOO"'
358
365
  end
359
366
 
360
367
  end
@@ -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 '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
- assert_equal 500, status
17
- assert_equal 'Foo!', body
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
- assert_equal 500, status
30
- assert_equal 'Exception!', body
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
- assert env.include?('sinatra.error')
38
- assert env['sinatra.error'].kind_of?(FooError)
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
- 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!:/
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
- assert_raise(FooError) { get '/' }
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
- assert_nothing_raised { get '/' }
80
- assert_equal 404, status
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
- assert_nothing_raised { get '/' }
95
- assert_equal 404, status
96
- assert_equal 'foo! not found.', body
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
- assert_equal 500, status
123
- assert_equal 'Foo!', body
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
- assert_equal 507, status
136
- assert_equal 'Error: 507', body
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
- assert_equal 502, status
158
- assert_equal 'from custom error page', body
138
+ status.should.equal 502
139
+ body.should.equal 'from custom error page'
159
140
  end
160
141
  end