rack 1.6.13 → 2.0.9

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of rack might be problematic. Click here for more details.

Files changed (141) hide show
  1. checksums.yaml +4 -4
  2. data/COPYING +1 -1
  3. data/HISTORY.md +138 -8
  4. data/README.rdoc +18 -28
  5. data/Rakefile +6 -14
  6. data/SPEC +3 -3
  7. data/contrib/rack_logo.svg +164 -111
  8. data/example/protectedlobster.rb +1 -1
  9. data/example/protectedlobster.ru +1 -1
  10. data/lib/rack/auth/abstract/request.rb +5 -1
  11. data/lib/rack/auth/digest/params.rb +2 -3
  12. data/lib/rack/auth/digest/request.rb +1 -1
  13. data/lib/rack/body_proxy.rb +14 -9
  14. data/lib/rack/builder.rb +3 -3
  15. data/lib/rack/chunked.rb +5 -5
  16. data/lib/rack/{commonlogger.rb → common_logger.rb} +3 -3
  17. data/lib/rack/content_length.rb +2 -2
  18. data/lib/rack/deflater.rb +4 -39
  19. data/lib/rack/directory.rb +66 -54
  20. data/lib/rack/etag.rb +5 -4
  21. data/lib/rack/events.rb +154 -0
  22. data/lib/rack/file.rb +64 -40
  23. data/lib/rack/handler/cgi.rb +15 -16
  24. data/lib/rack/handler/fastcgi.rb +13 -14
  25. data/lib/rack/handler/lsws.rb +11 -11
  26. data/lib/rack/handler/scgi.rb +15 -15
  27. data/lib/rack/handler/thin.rb +3 -0
  28. data/lib/rack/handler/webrick.rb +24 -26
  29. data/lib/rack/handler.rb +3 -25
  30. data/lib/rack/head.rb +15 -17
  31. data/lib/rack/lint.rb +40 -40
  32. data/lib/rack/lobster.rb +1 -1
  33. data/lib/rack/lock.rb +15 -10
  34. data/lib/rack/logger.rb +2 -2
  35. data/lib/rack/media_type.rb +38 -0
  36. data/lib/rack/{methodoverride.rb → method_override.rb} +6 -6
  37. data/lib/rack/mime.rb +18 -5
  38. data/lib/rack/mock.rb +36 -54
  39. data/lib/rack/multipart/generator.rb +5 -5
  40. data/lib/rack/multipart/parser.rb +270 -157
  41. data/lib/rack/multipart/uploaded_file.rb +1 -2
  42. data/lib/rack/multipart.rb +35 -6
  43. data/lib/rack/{nulllogger.rb → null_logger.rb} +1 -1
  44. data/lib/rack/query_parser.rb +192 -0
  45. data/lib/rack/recursive.rb +8 -8
  46. data/lib/rack/request.rb +394 -305
  47. data/lib/rack/response.rb +130 -57
  48. data/lib/rack/rewindable_input.rb +1 -12
  49. data/lib/rack/runtime.rb +10 -18
  50. data/lib/rack/sendfile.rb +5 -7
  51. data/lib/rack/server.rb +30 -23
  52. data/lib/rack/session/abstract/id.rb +110 -75
  53. data/lib/rack/session/cookie.rb +24 -17
  54. data/lib/rack/session/memcache.rb +9 -9
  55. data/lib/rack/session/pool.rb +8 -8
  56. data/lib/rack/show_exceptions.rb +386 -0
  57. data/lib/rack/{showstatus.rb → show_status.rb} +3 -3
  58. data/lib/rack/static.rb +30 -5
  59. data/lib/rack/tempfile_reaper.rb +2 -2
  60. data/lib/rack/urlmap.rb +15 -14
  61. data/lib/rack/utils.rb +138 -211
  62. data/lib/rack.rb +70 -21
  63. data/rack.gemspec +10 -9
  64. data/test/builder/an_underscore_app.rb +5 -0
  65. data/test/builder/options.ru +1 -1
  66. data/test/cgi/test.fcgi +1 -0
  67. data/test/cgi/test.gz +0 -0
  68. data/test/helper.rb +34 -0
  69. data/test/multipart/filename_with_encoded_words +7 -0
  70. data/test/multipart/filename_with_single_quote +7 -0
  71. data/test/multipart/quoted +15 -0
  72. data/test/multipart/rack-logo.png +0 -0
  73. data/test/multipart/unity3d_wwwform +11 -0
  74. data/test/registering_handler/rack/handler/registering_myself.rb +1 -1
  75. data/test/spec_auth_basic.rb +27 -19
  76. data/test/spec_auth_digest.rb +47 -46
  77. data/test/spec_body_proxy.rb +27 -27
  78. data/test/spec_builder.rb +51 -41
  79. data/test/spec_cascade.rb +24 -22
  80. data/test/spec_cgi.rb +49 -67
  81. data/test/spec_chunked.rb +37 -35
  82. data/test/{spec_commonlogger.rb → spec_common_logger.rb} +23 -21
  83. data/test/{spec_conditionalget.rb → spec_conditional_get.rb} +29 -28
  84. data/test/spec_config.rb +3 -2
  85. data/test/spec_content_length.rb +18 -17
  86. data/test/spec_content_type.rb +13 -12
  87. data/test/spec_deflater.rb +85 -49
  88. data/test/spec_directory.rb +87 -27
  89. data/test/spec_etag.rb +32 -31
  90. data/test/spec_events.rb +133 -0
  91. data/test/spec_fastcgi.rb +50 -72
  92. data/test/spec_file.rb +120 -77
  93. data/test/spec_handler.rb +19 -34
  94. data/test/spec_head.rb +15 -14
  95. data/test/spec_lint.rb +164 -199
  96. data/test/spec_lobster.rb +24 -23
  97. data/test/spec_lock.rb +79 -39
  98. data/test/spec_logger.rb +4 -3
  99. data/test/spec_media_type.rb +42 -0
  100. data/test/{spec_methodoverride.rb → spec_method_override.rb} +34 -35
  101. data/test/spec_mime.rb +19 -19
  102. data/test/spec_mock.rb +206 -144
  103. data/test/spec_multipart.rb +322 -200
  104. data/test/{spec_nulllogger.rb → spec_null_logger.rb} +5 -4
  105. data/test/spec_recursive.rb +17 -14
  106. data/test/spec_request.rb +780 -605
  107. data/test/spec_response.rb +233 -112
  108. data/test/spec_rewindable_input.rb +50 -40
  109. data/test/spec_runtime.rb +11 -10
  110. data/test/spec_sendfile.rb +30 -35
  111. data/test/spec_server.rb +78 -52
  112. data/test/spec_session_abstract_id.rb +11 -33
  113. data/test/spec_session_abstract_session_hash.rb +45 -0
  114. data/test/spec_session_cookie.rb +99 -67
  115. data/test/spec_session_memcache.rb +67 -68
  116. data/test/spec_session_pool.rb +52 -51
  117. data/test/{spec_showexceptions.rb → spec_show_exceptions.rb} +23 -28
  118. data/test/{spec_showstatus.rb → spec_show_status.rb} +36 -35
  119. data/test/spec_static.rb +71 -32
  120. data/test/spec_tempfile_reaper.rb +11 -10
  121. data/test/spec_thin.rb +55 -50
  122. data/test/spec_urlmap.rb +79 -78
  123. data/test/spec_utils.rb +441 -346
  124. data/test/spec_version.rb +2 -8
  125. data/test/spec_webrick.rb +93 -71
  126. data/test/static/foo.html +1 -0
  127. data/test/testrequest.rb +1 -1
  128. data/test/unregistered_handler/rack/handler/unregistered.rb +1 -1
  129. data/test/unregistered_handler/rack/handler/unregistered_long_one.rb +1 -1
  130. metadata +57 -36
  131. data/KNOWN-ISSUES +0 -44
  132. data/lib/rack/backports/uri/common_18.rb +0 -56
  133. data/lib/rack/backports/uri/common_192.rb +0 -52
  134. data/lib/rack/backports/uri/common_193.rb +0 -29
  135. data/lib/rack/handler/evented_mongrel.rb +0 -8
  136. data/lib/rack/handler/mongrel.rb +0 -106
  137. data/lib/rack/handler/swiftiplied_mongrel.rb +0 -8
  138. data/lib/rack/showexceptions.rb +0 -387
  139. data/lib/rack/utils/okjson.rb +0 -600
  140. data/test/spec_mongrel.rb +0 -182
  141. /data/lib/rack/{conditionalget.rb → conditional_get.rb} +0 -0
@@ -1,3 +1,4 @@
1
+ require 'minitest/autorun'
1
2
  begin
2
3
  require 'rack/session/memcache'
3
4
  require 'rack/lint'
@@ -34,26 +35,26 @@ begin
34
35
  Rack::Session::Memcache.new(incrementor)
35
36
 
36
37
  it "faults on no connection" do
37
- lambda{
38
+ lambda {
38
39
  Rack::Session::Memcache.new(incrementor, :memcache_server => 'nosuchserver')
39
- }.should.raise
40
+ }.must_raise(RuntimeError).message.must_equal 'No memcache servers'
40
41
  end
41
42
 
42
43
  it "connects to existing server" do
43
44
  test_pool = MemCache.new(incrementor, :namespace => 'test:rack:session')
44
- test_pool.namespace.should.equal 'test:rack:session'
45
+ test_pool.namespace.must_equal 'test:rack:session'
45
46
  end
46
47
 
47
48
  it "passes options to MemCache" do
48
49
  pool = Rack::Session::Memcache.new(incrementor, :namespace => 'test:rack:session')
49
- pool.pool.namespace.should.equal 'test:rack:session'
50
+ pool.pool.namespace.must_equal 'test:rack:session'
50
51
  end
51
52
 
52
53
  it "creates a new cookie" do
53
54
  pool = Rack::Session::Memcache.new(incrementor)
54
55
  res = Rack::MockRequest.new(pool).get("/")
55
- res["Set-Cookie"].should.include("#{session_key}=")
56
- res.body.should.equal '{"counter"=>1}'
56
+ res["Set-Cookie"].must_include "#{session_key}="
57
+ res.body.must_equal '{"counter"=>1}'
57
58
  end
58
59
 
59
60
  it "determines session from a cookie" do
@@ -62,9 +63,9 @@ begin
62
63
  res = req.get("/")
63
64
  cookie = res["Set-Cookie"]
64
65
  req.get("/", "HTTP_COOKIE" => cookie).
65
- body.should.equal '{"counter"=>2}'
66
+ body.must_equal '{"counter"=>2}'
66
67
  req.get("/", "HTTP_COOKIE" => cookie).
67
- body.should.equal '{"counter"=>3}'
68
+ body.must_equal '{"counter"=>3}'
68
69
  end
69
70
 
70
71
  it "determines session only from a cookie by default" do
@@ -73,9 +74,9 @@ begin
73
74
  res = req.get("/")
74
75
  sid = res["Set-Cookie"][session_match, 1]
75
76
  req.get("/?rack.session=#{sid}").
76
- body.should.equal '{"counter"=>1}'
77
+ body.must_equal '{"counter"=>1}'
77
78
  req.get("/?rack.session=#{sid}").
78
- body.should.equal '{"counter"=>1}'
79
+ body.must_equal '{"counter"=>1}'
79
80
  end
80
81
 
81
82
  it "determines session from params" do
@@ -84,9 +85,9 @@ begin
84
85
  res = req.get("/")
85
86
  sid = res["Set-Cookie"][session_match, 1]
86
87
  req.get("/?rack.session=#{sid}").
87
- body.should.equal '{"counter"=>2}'
88
+ body.must_equal '{"counter"=>2}'
88
89
  req.get("/?rack.session=#{sid}").
89
- body.should.equal '{"counter"=>3}'
90
+ body.must_equal '{"counter"=>3}'
90
91
  end
91
92
 
92
93
  it "survives nonexistant cookies" do
@@ -94,24 +95,24 @@ begin
94
95
  pool = Rack::Session::Memcache.new(incrementor)
95
96
  res = Rack::MockRequest.new(pool).
96
97
  get("/", "HTTP_COOKIE" => bad_cookie)
97
- res.body.should.equal '{"counter"=>1}'
98
+ res.body.must_equal '{"counter"=>1}'
98
99
  cookie = res["Set-Cookie"][session_match]
99
- cookie.should.not.match(/#{bad_cookie}/)
100
+ cookie.wont_match(/#{bad_cookie}/)
100
101
  end
101
102
 
102
103
  it "maintains freshness" do
103
104
  pool = Rack::Session::Memcache.new(incrementor, :expire_after => 3)
104
105
  res = Rack::MockRequest.new(pool).get('/')
105
- res.body.should.include '"counter"=>1'
106
+ res.body.must_include '"counter"=>1'
106
107
  cookie = res["Set-Cookie"]
107
108
  res = Rack::MockRequest.new(pool).get('/', "HTTP_COOKIE" => cookie)
108
- res["Set-Cookie"].should.equal cookie
109
- res.body.should.include '"counter"=>2'
109
+ res["Set-Cookie"].must_equal cookie
110
+ res.body.must_include '"counter"=>2'
110
111
  puts 'Sleeping to expire session' if $DEBUG
111
112
  sleep 4
112
113
  res = Rack::MockRequest.new(pool).get('/', "HTTP_COOKIE" => cookie)
113
- res["Set-Cookie"].should.not.equal cookie
114
- res.body.should.include '"counter"=>1'
114
+ res["Set-Cookie"].wont_equal cookie
115
+ res.body.must_include '"counter"=>1'
115
116
  end
116
117
 
117
118
  it "does not send the same session id if it did not change" do
@@ -120,15 +121,15 @@ begin
120
121
 
121
122
  res0 = req.get("/")
122
123
  cookie = res0["Set-Cookie"][session_match]
123
- res0.body.should.equal '{"counter"=>1}'
124
+ res0.body.must_equal '{"counter"=>1}'
124
125
 
125
126
  res1 = req.get("/", "HTTP_COOKIE" => cookie)
126
- res1["Set-Cookie"].should.be.nil
127
- res1.body.should.equal '{"counter"=>2}'
127
+ res1["Set-Cookie"].must_be_nil
128
+ res1.body.must_equal '{"counter"=>2}'
128
129
 
129
130
  res2 = req.get("/", "HTTP_COOKIE" => cookie)
130
- res2["Set-Cookie"].should.be.nil
131
- res2.body.should.equal '{"counter"=>3}'
131
+ res2["Set-Cookie"].must_be_nil
132
+ res2.body.must_equal '{"counter"=>3}'
132
133
  end
133
134
 
134
135
  it "deletes cookies with :drop option" do
@@ -139,15 +140,15 @@ begin
139
140
 
140
141
  res1 = req.get("/")
141
142
  session = (cookie = res1["Set-Cookie"])[session_match]
142
- res1.body.should.equal '{"counter"=>1}'
143
+ res1.body.must_equal '{"counter"=>1}'
143
144
 
144
145
  res2 = dreq.get("/", "HTTP_COOKIE" => cookie)
145
- res2["Set-Cookie"].should.equal nil
146
- res2.body.should.equal '{"counter"=>2}'
146
+ res2["Set-Cookie"].must_be_nil
147
+ res2.body.must_equal '{"counter"=>2}'
147
148
 
148
149
  res3 = req.get("/", "HTTP_COOKIE" => cookie)
149
- res3["Set-Cookie"][session_match].should.not.equal session
150
- res3.body.should.equal '{"counter"=>1}'
150
+ res3["Set-Cookie"][session_match].wont_equal session
151
+ res3.body.must_equal '{"counter"=>1}'
151
152
  end
152
153
 
153
154
  it "provides new session id with :renew option" do
@@ -158,20 +159,20 @@ begin
158
159
 
159
160
  res1 = req.get("/")
160
161
  session = (cookie = res1["Set-Cookie"])[session_match]
161
- res1.body.should.equal '{"counter"=>1}'
162
+ res1.body.must_equal '{"counter"=>1}'
162
163
 
163
164
  res2 = rreq.get("/", "HTTP_COOKIE" => cookie)
164
165
  new_cookie = res2["Set-Cookie"]
165
166
  new_session = new_cookie[session_match]
166
- new_session.should.not.equal session
167
- res2.body.should.equal '{"counter"=>2}'
167
+ new_session.wont_equal session
168
+ res2.body.must_equal '{"counter"=>2}'
168
169
 
169
170
  res3 = req.get("/", "HTTP_COOKIE" => new_cookie)
170
- res3.body.should.equal '{"counter"=>3}'
171
+ res3.body.must_equal '{"counter"=>3}'
171
172
 
172
173
  # Old cookie was deleted
173
174
  res4 = req.get("/", "HTTP_COOKIE" => cookie)
174
- res4.body.should.equal '{"counter"=>1}'
175
+ res4.body.must_equal '{"counter"=>1}'
175
176
  end
176
177
 
177
178
  it "omits cookie with :defer option but still updates the state" do
@@ -182,14 +183,14 @@ begin
182
183
  creq = Rack::MockRequest.new(count)
183
184
 
184
185
  res0 = dreq.get("/")
185
- res0["Set-Cookie"].should.equal nil
186
- res0.body.should.equal '{"counter"=>1}'
186
+ res0["Set-Cookie"].must_be_nil
187
+ res0.body.must_equal '{"counter"=>1}'
187
188
 
188
189
  res0 = creq.get("/")
189
190
  res1 = dreq.get("/", "HTTP_COOKIE" => res0["Set-Cookie"])
190
- res1.body.should.equal '{"counter"=>2}'
191
+ res1.body.must_equal '{"counter"=>2}'
191
192
  res2 = dreq.get("/", "HTTP_COOKIE" => res0["Set-Cookie"])
192
- res2.body.should.equal '{"counter"=>3}'
193
+ res2.body.must_equal '{"counter"=>3}'
193
194
  end
194
195
 
195
196
  it "omits cookie and state update with :skip option" do
@@ -200,14 +201,14 @@ begin
200
201
  creq = Rack::MockRequest.new(count)
201
202
 
202
203
  res0 = sreq.get("/")
203
- res0["Set-Cookie"].should.equal nil
204
- res0.body.should.equal '{"counter"=>1}'
204
+ res0["Set-Cookie"].must_be_nil
205
+ res0.body.must_equal '{"counter"=>1}'
205
206
 
206
207
  res0 = creq.get("/")
207
208
  res1 = sreq.get("/", "HTTP_COOKIE" => res0["Set-Cookie"])
208
- res1.body.should.equal '{"counter"=>2}'
209
+ res1.body.must_equal '{"counter"=>2}'
209
210
  res2 = sreq.get("/", "HTTP_COOKIE" => res0["Set-Cookie"])
210
- res2.body.should.equal '{"counter"=>2}'
211
+ res2.body.must_equal '{"counter"=>2}'
211
212
  end
212
213
 
213
214
  it "updates deep hashes correctly" do
@@ -231,7 +232,7 @@ begin
231
232
  req.get("/", "HTTP_COOKIE" => cookie)
232
233
  ses1 = pool.pool.get(session_id.private_id, true)
233
234
 
234
- ses1.should.not.equal ses0
235
+ ses1.wont_equal ses0
235
236
  end
236
237
 
237
238
  it "can read the session with the legacy id" do
@@ -246,9 +247,9 @@ begin
246
247
  pool.pool.delete(session_id.private_id)
247
248
 
248
249
  res1 = req.get("/", "HTTP_COOKIE" => cookie)
249
- res1["Set-Cookie"].should.be.nil
250
- res1.body.should.equal '{"counter"=>2}'
251
- pool.pool.get(session_id.private_id, true).should.not.be.nil
250
+ res1["Set-Cookie"].must_be_nil
251
+ res1.body.must_equal '{"counter"=>2}'
252
+ pool.pool.get(session_id.private_id, true).wont_be_nil
252
253
  end
253
254
 
254
255
  it "drops the session in the legacy id as well" do
@@ -265,24 +266,22 @@ begin
265
266
  pool.pool.delete(session_id.private_id)
266
267
 
267
268
  res2 = dreq.get("/", "HTTP_COOKIE" => cookie)
268
- res2["Set-Cookie"].should.be.nil
269
- res2.body.should.equal '{"counter"=>2}'
270
- pool.pool.get(session_id.private_id, true).should.be.nil
271
- pool.pool.get(session_id.public_id, true).should.be.nil
269
+ res2["Set-Cookie"].must_be_nil
270
+ res2.body.must_equal '{"counter"=>2}'
271
+ pool.pool.get(session_id.private_id, true).must_be_nil
272
+ pool.pool.get(session_id.public_id, true).must_be_nil
272
273
  end
273
274
 
274
275
  # anyone know how to do this better?
275
276
  it "cleanly merges sessions when multithreaded" do
276
- unless $DEBUG
277
- 1.should.equal 1 # fake assertion to appease the mighty bacon
278
- next
279
- end
277
+ skip unless $DEBUG
278
+
280
279
  warn 'Running multithread test for Session::Memcache'
281
280
  pool = Rack::Session::Memcache.new(incrementor)
282
281
  req = Rack::MockRequest.new(pool)
283
282
 
284
283
  res = req.get('/')
285
- res.body.should.equal '{"counter"=>1}'
284
+ res.body.must_equal '{"counter"=>1}'
286
285
  cookie = res["Set-Cookie"]
287
286
  session_id = cookie[session_match, 1]
288
287
 
@@ -302,13 +301,13 @@ begin
302
301
  end
303
302
  end.reverse.map{|t| t.run.join.value }
304
303
  r.each do |request|
305
- request['Set-Cookie'].should.equal cookie
306
- request.body.should.include '"counter"=>2'
304
+ request['Set-Cookie'].must_equal cookie
305
+ request.body.must_include '"counter"=>2'
307
306
  end
308
307
 
309
308
  session = pool.pool.get(session_id)
310
- session.size.should.equal tnum+1 # counter
311
- session['counter'].should.equal 2 # meeeh
309
+ session.size.must_equal tnum+1 # counter
310
+ session['counter'].must_equal 2 # meeeh
312
311
 
313
312
  tnum = rand(7).to_i+5
314
313
  r = Array.new(tnum) do
@@ -319,13 +318,13 @@ begin
319
318
  end
320
319
  end.reverse.map{|t| t.run.join.value }
321
320
  r.each do |request|
322
- request['Set-Cookie'].should.equal cookie
323
- request.body.should.include '"counter"=>3'
321
+ request['Set-Cookie'].must_equal cookie
322
+ request.body.must_include '"counter"=>3'
324
323
  end
325
324
 
326
325
  session = pool.pool.get(session_id)
327
- session.size.should.be tnum+1
328
- session['counter'].should.be 3
326
+ session.size.must_equal tnum+1
327
+ session['counter'].must_equal 3
329
328
 
330
329
  drop_counter = proc do |env|
331
330
  env['rack.session'].delete 'counter'
@@ -341,14 +340,14 @@ begin
341
340
  end
342
341
  end.reverse.map{|t| t.run.join.value }
343
342
  r.each do |request|
344
- request['Set-Cookie'].should.equal cookie
345
- request.body.should.include '"foo"=>"bar"'
343
+ request['Set-Cookie'].must_equal cookie
344
+ request.body.must_include '"foo"=>"bar"'
346
345
  end
347
346
 
348
347
  session = pool.pool.get(session_id)
349
- session.size.should.be r.size+1
350
- session['counter'].should.be.nil?
351
- session['foo'].should.equal 'bar'
348
+ session.size.must_equal r.size+1
349
+ session['counter'].must_be_nil?
350
+ session['foo'].must_equal 'bar'
352
351
  end
353
352
  end
354
353
  rescue RuntimeError
@@ -1,3 +1,4 @@
1
+ require 'minitest/autorun'
1
2
  require 'thread'
2
3
  require 'rack/lint'
3
4
  require 'rack/mock'
@@ -35,14 +36,14 @@ describe Rack::Session::Pool do
35
36
  env['rack.session.options'][:defer] = true
36
37
  incrementor.call(env)
37
38
  end)
38
-
39
+
39
40
  incrementor = Rack::Lint.new(incrementor)
40
41
 
41
42
  it "creates a new cookie" do
42
43
  pool = Rack::Session::Pool.new(incrementor)
43
44
  res = Rack::MockRequest.new(pool).get("/")
44
- res["Set-Cookie"].should.match session_match
45
- res.body.should.equal '{"counter"=>1}'
45
+ res["Set-Cookie"].must_match(session_match)
46
+ res.body.must_equal '{"counter"=>1}'
46
47
  end
47
48
 
48
49
  it "determines session from a cookie" do
@@ -50,16 +51,16 @@ describe Rack::Session::Pool do
50
51
  req = Rack::MockRequest.new(pool)
51
52
  cookie = req.get("/")["Set-Cookie"]
52
53
  req.get("/", "HTTP_COOKIE" => cookie).
53
- body.should.equal '{"counter"=>2}'
54
+ body.must_equal '{"counter"=>2}'
54
55
  req.get("/", "HTTP_COOKIE" => cookie).
55
- body.should.equal '{"counter"=>3}'
56
+ body.must_equal '{"counter"=>3}'
56
57
  end
57
58
 
58
59
  it "survives nonexistant cookies" do
59
60
  pool = Rack::Session::Pool.new(incrementor)
60
61
  res = Rack::MockRequest.new(pool).
61
62
  get("/", "HTTP_COOKIE" => "#{session_key}=blarghfasel")
62
- res.body.should.equal '{"counter"=>1}'
63
+ res.body.must_equal '{"counter"=>1}'
63
64
  end
64
65
 
65
66
  it "does not send the same session id if it did not change" do
@@ -68,18 +69,18 @@ describe Rack::Session::Pool do
68
69
 
69
70
  res0 = req.get("/")
70
71
  cookie = res0["Set-Cookie"][session_match]
71
- res0.body.should.equal '{"counter"=>1}'
72
- pool.pool.size.should.equal 1
72
+ res0.body.must_equal '{"counter"=>1}'
73
+ pool.pool.size.must_equal 1
73
74
 
74
75
  res1 = req.get("/", "HTTP_COOKIE" => cookie)
75
- res1["Set-Cookie"].should.be.nil
76
- res1.body.should.equal '{"counter"=>2}'
77
- pool.pool.size.should.equal 1
76
+ res1["Set-Cookie"].must_be_nil
77
+ res1.body.must_equal '{"counter"=>2}'
78
+ pool.pool.size.must_equal 1
78
79
 
79
80
  res2 = req.get("/", "HTTP_COOKIE" => cookie)
80
- res2["Set-Cookie"].should.be.nil
81
- res2.body.should.equal '{"counter"=>3}'
82
- pool.pool.size.should.equal 1
81
+ res2["Set-Cookie"].must_be_nil
82
+ res2.body.must_equal '{"counter"=>3}'
83
+ pool.pool.size.must_equal 1
83
84
  end
84
85
 
85
86
  it "deletes cookies with :drop option" do
@@ -90,18 +91,18 @@ describe Rack::Session::Pool do
90
91
 
91
92
  res1 = req.get("/")
92
93
  session = (cookie = res1["Set-Cookie"])[session_match]
93
- res1.body.should.equal '{"counter"=>1}'
94
- pool.pool.size.should.equal 1
94
+ res1.body.must_equal '{"counter"=>1}'
95
+ pool.pool.size.must_equal 1
95
96
 
96
97
  res2 = dreq.get("/", "HTTP_COOKIE" => cookie)
97
- res2["Set-Cookie"].should.be.nil
98
- res2.body.should.equal '{"counter"=>2}'
99
- pool.pool.size.should.equal 0
98
+ res2["Set-Cookie"].must_be_nil
99
+ res2.body.must_equal '{"counter"=>2}'
100
+ pool.pool.size.must_equal 0
100
101
 
101
102
  res3 = req.get("/", "HTTP_COOKIE" => cookie)
102
- res3["Set-Cookie"][session_match].should.not.equal session
103
- res3.body.should.equal '{"counter"=>1}'
104
- pool.pool.size.should.equal 1
103
+ res3["Set-Cookie"][session_match].wont_equal session
104
+ res3.body.must_equal '{"counter"=>1}'
105
+ pool.pool.size.must_equal 1
105
106
  end
106
107
 
107
108
  it "provides new session id with :renew option" do
@@ -112,23 +113,23 @@ describe Rack::Session::Pool do
112
113
 
113
114
  res1 = req.get("/")
114
115
  session = (cookie = res1["Set-Cookie"])[session_match]
115
- res1.body.should.equal '{"counter"=>1}'
116
- pool.pool.size.should.equal 1
116
+ res1.body.must_equal '{"counter"=>1}'
117
+ pool.pool.size.must_equal 1
117
118
 
118
119
  res2 = rreq.get("/", "HTTP_COOKIE" => cookie)
119
120
  new_cookie = res2["Set-Cookie"]
120
121
  new_session = new_cookie[session_match]
121
- new_session.should.not.equal session
122
- res2.body.should.equal '{"counter"=>2}'
123
- pool.pool.size.should.equal 1
122
+ new_session.wont_equal session
123
+ res2.body.must_equal '{"counter"=>2}'
124
+ pool.pool.size.must_equal 1
124
125
 
125
126
  res3 = req.get("/", "HTTP_COOKIE" => new_cookie)
126
- res3.body.should.equal '{"counter"=>3}'
127
- pool.pool.size.should.equal 1
127
+ res3.body.must_equal '{"counter"=>3}'
128
+ pool.pool.size.must_equal 1
128
129
 
129
130
  res4 = req.get("/", "HTTP_COOKIE" => cookie)
130
- res4.body.should.equal '{"counter"=>1}'
131
- pool.pool.size.should.equal 2
131
+ res4.body.must_equal '{"counter"=>1}'
132
+ pool.pool.size.must_equal 2
132
133
  end
133
134
 
134
135
  it "omits cookie with :defer option" do
@@ -137,9 +138,9 @@ describe Rack::Session::Pool do
137
138
  dreq = Rack::MockRequest.new(defer)
138
139
 
139
140
  res1 = dreq.get("/")
140
- res1["Set-Cookie"].should.equal nil
141
- res1.body.should.equal '{"counter"=>1}'
142
- pool.pool.size.should.equal 1
141
+ res1["Set-Cookie"].must_be_nil
142
+ res1.body.must_equal '{"counter"=>1}'
143
+ pool.pool.size.must_equal 1
143
144
  end
144
145
 
145
146
  it "can read the session with the legacy id" do
@@ -154,9 +155,9 @@ describe Rack::Session::Pool do
154
155
  pool.pool.delete(session_id.private_id)
155
156
 
156
157
  res1 = req.get("/", "HTTP_COOKIE" => cookie)
157
- res1["Set-Cookie"].should.be.nil
158
- res1.body.should.equal '{"counter"=>2}'
159
- pool.pool[session_id.private_id].should.not.be.nil
158
+ res1["Set-Cookie"].must_be_nil
159
+ res1.body.must_equal '{"counter"=>2}'
160
+ pool.pool[session_id.private_id].wont_be_nil
160
161
  end
161
162
 
162
163
  it "drops the session in the legacy id as well" do
@@ -173,16 +174,16 @@ describe Rack::Session::Pool do
173
174
  pool.pool.delete(session_id.private_id)
174
175
 
175
176
  res2 = dreq.get("/", "HTTP_COOKIE" => cookie)
176
- res2["Set-Cookie"].should.be.nil
177
- res2.body.should.equal '{"counter"=>2}'
178
- pool.pool[session_id.private_id].should.be.nil
179
- pool.pool[session_id.public_id].should.be.nil
177
+ res2["Set-Cookie"].must_be_nil
178
+ res2.body.must_equal '{"counter"=>2}'
179
+ pool.pool[session_id.private_id].must_be_nil
180
+ pool.pool[session_id.public_id].must_be_nil
180
181
  end
181
182
 
182
183
  # anyone know how to do this better?
183
184
  it "should merge sessions when multithreaded" do
184
185
  unless $DEBUG
185
- 1.should.equal 1
186
+ 1.must_equal 1
186
187
  next
187
188
  end
188
189
 
@@ -191,7 +192,7 @@ describe Rack::Session::Pool do
191
192
  req = Rack::MockRequest.new(pool)
192
193
 
193
194
  res = req.get('/')
194
- res.body.should.equal '{"counter"=>1}'
195
+ res.body.must_equal '{"counter"=>1}'
195
196
  cookie = res["Set-Cookie"]
196
197
  sess_id = cookie[/#{pool.key}=([^,;]+)/,1]
197
198
 
@@ -211,36 +212,36 @@ describe Rack::Session::Pool do
211
212
  end
212
213
  end.reverse.map{|t| t.run.join.value }
213
214
  r.each do |resp|
214
- resp['Set-Cookie'].should.equal cookie
215
- resp.body.should.include '"counter"=>2'
215
+ resp['Set-Cookie'].must_equal cookie
216
+ resp.body.must_include '"counter"=>2'
216
217
  end
217
218
 
218
219
  session = pool.pool[sess_id]
219
- session.size.should.equal tnum+1 # counter
220
- session['counter'].should.equal 2 # meeeh
220
+ session.size.must_equal tnum+1 # counter
221
+ session['counter'].must_equal 2 # meeeh
221
222
  end
222
223
 
223
224
  it "does not return a cookie if cookie was not read/written" do
224
225
  app = Rack::Session::Pool.new(nothing)
225
226
  res = Rack::MockRequest.new(app).get("/")
226
- res["Set-Cookie"].should.be.nil
227
+ res["Set-Cookie"].must_be_nil
227
228
  end
228
229
 
229
230
  it "does not return a cookie if cookie was not written (only read)" do
230
231
  app = Rack::Session::Pool.new(get_session_id)
231
232
  res = Rack::MockRequest.new(app).get("/")
232
- res["Set-Cookie"].should.be.nil
233
+ res["Set-Cookie"].must_be_nil
233
234
  end
234
235
 
235
236
  it "returns even if not read/written if :expire_after is set" do
236
237
  app = Rack::Session::Pool.new(nothing, :expire_after => 3600)
237
238
  res = Rack::MockRequest.new(app).get("/", 'rack.session' => {'not' => 'empty'})
238
- res["Set-Cookie"].should.not.be.nil
239
+ res["Set-Cookie"].wont_be :nil?
239
240
  end
240
241
 
241
242
  it "returns no cookie if no data was written and no session was created previously, even if :expire_after is set" do
242
243
  app = Rack::Session::Pool.new(nothing, :expire_after => 3600)
243
244
  res = Rack::MockRequest.new(app).get("/")
244
- res["Set-Cookie"].should.be.nil
245
+ res["Set-Cookie"].must_be_nil
245
246
  end
246
247
  end
@@ -1,4 +1,5 @@
1
- require 'rack/showexceptions'
1
+ require 'minitest/autorun'
2
+ require 'rack/show_exceptions'
2
3
  require 'rack/lint'
3
4
  require 'rack/mock'
4
5
 
@@ -6,7 +7,7 @@ describe Rack::ShowExceptions do
6
7
  def show_exceptions(app)
7
8
  Rack::Lint.new Rack::ShowExceptions.new(app)
8
9
  end
9
-
10
+
10
11
  it "catches exceptions" do
11
12
  res = nil
12
13
 
@@ -15,15 +16,13 @@ describe Rack::ShowExceptions do
15
16
  lambda{|env| raise RuntimeError }
16
17
  ))
17
18
 
18
- lambda{
19
- res = req.get("/", "HTTP_ACCEPT" => "text/html")
20
- }.should.not.raise
19
+ res = req.get("/", "HTTP_ACCEPT" => "text/html")
21
20
 
22
- res.should.be.a.server_error
23
- res.status.should.equal 500
21
+ res.must_be :server_error?
22
+ res.status.must_equal 500
24
23
 
25
- res.should =~ /RuntimeError/
26
- res.should =~ /ShowExceptions/
24
+ assert_match(res, /RuntimeError/)
25
+ assert_match(res, /ShowExceptions/)
27
26
  end
28
27
 
29
28
  it "responds with HTML only to requests accepting HTML" do
@@ -42,22 +41,20 @@ describe Rack::ShowExceptions do
42
41
  ["text/plain", ["/"]],
43
42
  ["text/plain", ["/", {"HTTP_ACCEPT" => "application/json"}]]
44
43
  ].each do |exmime, rargs|
45
- lambda{
46
- res = req.get(*rargs)
47
- }.should.not.raise
44
+ res = req.get(*rargs)
48
45
 
49
- res.should.be.a.server_error
50
- res.status.should.equal 500
46
+ res.must_be :server_error?
47
+ res.status.must_equal 500
51
48
 
52
- res.content_type.should.equal exmime
49
+ res.content_type.must_equal exmime
53
50
 
54
- res.body.should.include "RuntimeError"
55
- res.body.should.include "It was never supposed to work"
51
+ res.body.must_include "RuntimeError"
52
+ res.body.must_include "It was never supposed to work"
56
53
 
57
54
  if exmime == "text/html"
58
- res.body.should.include '</html>'
55
+ res.body.must_include '</html>'
59
56
  else
60
- res.body.should.not.include '</html>'
57
+ res.body.wont_include '</html>'
61
58
  end
62
59
  end
63
60
  end
@@ -71,16 +68,14 @@ describe Rack::ShowExceptions do
71
68
  )
72
69
  )
73
70
 
74
- lambda{
75
- res = req.get("/", "HTTP_ACCEPT" => "text/html")
76
- }.should.not.raise
71
+ res = req.get("/", "HTTP_ACCEPT" => "text/html")
77
72
 
78
- res.should.be.a.server_error
79
- res.status.should.equal 500
73
+ res.must_be :server_error?
74
+ res.status.must_equal 500
80
75
 
81
- res.should =~ /RuntimeError/
82
- res.should =~ /ShowExceptions/
83
- res.should =~ /unknown location/
76
+ assert_match(res, /RuntimeError/)
77
+ assert_match(res, /ShowExceptions/)
78
+ assert_match(res, /unknown location/)
84
79
  end
85
80
 
86
81
  it "knows to prefer plaintext for non-html" do
@@ -92,7 +87,7 @@ describe Rack::ShowExceptions do
92
87
  [{ "HTTP_ACCEPT" => "text/foo" }, true],
93
88
  [{ "HTTP_ACCEPT" => "text/html" }, false]
94
89
  ].each do |env, expected|
95
- expected.should.equal exc.prefers_plaintext?(env)
90
+ assert_equal(expected, exc.prefers_plaintext?(env))
96
91
  end
97
92
  end
98
93
  end