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