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
data/test/spec_lobster.rb CHANGED
@@ -1,3 +1,4 @@
1
+ require 'minitest/autorun'
1
2
  require 'rack/lobster'
2
3
  require 'rack/lint'
3
4
  require 'rack/mock'
@@ -13,46 +14,46 @@ module LobsterHelpers
13
14
  end
14
15
 
15
16
  describe Rack::Lobster::LambdaLobster do
16
- extend LobsterHelpers
17
-
18
- should "be a single lambda" do
19
- Rack::Lobster::LambdaLobster.should.be.kind_of Proc
17
+ include LobsterHelpers
18
+
19
+ it "be a single lambda" do
20
+ Rack::Lobster::LambdaLobster.must_be_kind_of Proc
20
21
  end
21
22
 
22
- should "look like a lobster" do
23
+ it "look like a lobster" do
23
24
  res = lambda_lobster.get("/")
24
- res.should.be.ok
25
- res.body.should.include "(,(,,(,,,("
26
- res.body.should.include "?flip"
25
+ res.must_be :ok?
26
+ res.body.must_include "(,(,,(,,,("
27
+ res.body.must_include "?flip"
27
28
  end
28
29
 
29
- should "be flippable" do
30
+ it "be flippable" do
30
31
  res = lambda_lobster.get("/?flip")
31
- res.should.be.ok
32
- res.body.should.include "(,,,(,,(,("
32
+ res.must_be :ok?
33
+ res.body.must_include "(,,,(,,(,("
33
34
  end
34
35
  end
35
36
 
36
37
  describe Rack::Lobster do
37
- extend LobsterHelpers
38
-
39
- should "look like a lobster" do
38
+ include LobsterHelpers
39
+
40
+ it "look like a lobster" do
40
41
  res = lobster.get("/")
41
- res.should.be.ok
42
- res.body.should.include "(,(,,(,,,("
43
- res.body.should.include "?flip"
44
- res.body.should.include "crash"
42
+ res.must_be :ok?
43
+ res.body.must_include "(,(,,(,,,("
44
+ res.body.must_include "?flip"
45
+ res.body.must_include "crash"
45
46
  end
46
47
 
47
- should "be flippable" do
48
+ it "be flippable" do
48
49
  res = lobster.get("/?flip=left")
49
- res.should.be.ok
50
- res.body.should.include "),,,),,),)"
50
+ res.must_be :ok?
51
+ res.body.must_include "),,,),,),)"
51
52
  end
52
53
 
53
- should "provide crashing for testing purposes" do
54
+ it "provide crashing for testing purposes" do
54
55
  lambda {
55
56
  lobster.get("/?flip=crash")
56
- }.should.raise
57
+ }.must_raise RuntimeError
57
58
  end
58
59
  end
data/test/spec_lock.rb CHANGED
@@ -1,3 +1,4 @@
1
+ require 'minitest/autorun'
1
2
  require 'rack/lint'
2
3
  require 'rack/lock'
3
4
  require 'rack/mock'
@@ -9,11 +10,6 @@ class Lock
9
10
  @synchronized = false
10
11
  end
11
12
 
12
- def synchronize
13
- @synchronized = true
14
- yield
15
- end
16
-
17
13
  def lock
18
14
  @synchronized = true
19
15
  end
@@ -35,12 +31,12 @@ module LockHelpers
35
31
  end
36
32
 
37
33
  describe Rack::Lock do
38
- extend LockHelpers
34
+ include LockHelpers
39
35
 
40
36
  describe 'Proxy' do
41
- extend LockHelpers
37
+ include LockHelpers
42
38
 
43
- should 'delegate each' do
39
+ it 'delegate each' do
44
40
  env = Rack::MockRequest.env_for("/")
45
41
  response = Class.new {
46
42
  attr_accessor :close_called
@@ -52,10 +48,10 @@ describe Rack::Lock do
52
48
  response = app.call(env)[2]
53
49
  list = []
54
50
  response.each { |x| list << x }
55
- list.should.equal %w{ hi mom }
51
+ list.must_equal %w{ hi mom }
56
52
  end
57
53
 
58
- should 'delegate to_path' do
54
+ it 'delegate to_path' do
59
55
  lock = Lock.new
60
56
  env = Rack::MockRequest.env_for("/")
61
57
 
@@ -65,11 +61,11 @@ describe Rack::Lock do
65
61
  app = Rack::Lock.new(lambda { |inner_env| [200, {"Content-Type" => "text/plain"}, res] }, lock)
66
62
  body = app.call(env)[2]
67
63
 
68
- body.should.respond_to :to_path
69
- body.to_path.should.equal "/tmp/hello.txt"
64
+ body.must_respond_to :to_path
65
+ body.to_path.must_equal "/tmp/hello.txt"
70
66
  end
71
67
 
72
- should 'not delegate to_path if body does not implement it' do
68
+ it 'not delegate to_path if body does not implement it' do
73
69
  env = Rack::MockRequest.env_for("/")
74
70
 
75
71
  res = ['Hello World']
@@ -77,11 +73,11 @@ describe Rack::Lock do
77
73
  app = lock_app(lambda { |inner_env| [200, {"Content-Type" => "text/plain"}, res] })
78
74
  body = app.call(env)[2]
79
75
 
80
- body.should.not.respond_to :to_path
76
+ body.wont_respond_to :to_path
81
77
  end
82
78
  end
83
79
 
84
- should 'call super on close' do
80
+ it 'call super on close' do
85
81
  env = Rack::MockRequest.env_for("/")
86
82
  response = Class.new {
87
83
  attr_accessor :close_called
@@ -91,74 +87,118 @@ describe Rack::Lock do
91
87
 
92
88
  app = lock_app(lambda { |inner_env| [200, {"Content-Type" => "text/plain"}, response] })
93
89
  app.call(env)
94
- response.close_called.should.equal false
90
+ response.close_called.must_equal false
95
91
  response.close
96
- response.close_called.should.equal true
92
+ response.close_called.must_equal true
97
93
  end
98
94
 
99
- should "not unlock until body is closed" do
95
+ it "not unlock until body is closed" do
100
96
  lock = Lock.new
101
97
  env = Rack::MockRequest.env_for("/")
102
98
  response = Object.new
103
99
  app = lock_app(lambda { |inner_env| [200, {"Content-Type" => "text/plain"}, response] }, lock)
104
- lock.synchronized.should.equal false
100
+ lock.synchronized.must_equal false
105
101
  response = app.call(env)[2]
106
- lock.synchronized.should.equal true
102
+ lock.synchronized.must_equal true
107
103
  response.close
108
- lock.synchronized.should.equal false
104
+ lock.synchronized.must_equal false
109
105
  end
110
106
 
111
- should "return value from app" do
107
+ it "return value from app" do
112
108
  env = Rack::MockRequest.env_for("/")
113
109
  body = [200, {"Content-Type" => "text/plain"}, %w{ hi mom }]
114
110
  app = lock_app(lambda { |inner_env| body })
115
111
 
116
112
  res = app.call(env)
117
- res[0].should.equal body[0]
118
- res[1].should.equal body[1]
119
- res[2].to_enum.to_a.should.equal ["hi", "mom"]
113
+ res[0].must_equal body[0]
114
+ res[1].must_equal body[1]
115
+ res[2].to_enum.to_a.must_equal ["hi", "mom"]
120
116
  end
121
117
 
122
- should "call synchronize on lock" do
118
+ it "call synchronize on lock" do
123
119
  lock = Lock.new
124
120
  env = Rack::MockRequest.env_for("/")
125
121
  app = lock_app(lambda { |inner_env| [200, {"Content-Type" => "text/plain"}, %w{ a b c }] }, lock)
126
- lock.synchronized.should.equal false
122
+ lock.synchronized.must_equal false
127
123
  app.call(env)
128
- lock.synchronized.should.equal true
124
+ lock.synchronized.must_equal true
129
125
  end
130
126
 
131
- should "unlock if the app raises" do
127
+ it "unlock if the app raises" do
132
128
  lock = Lock.new
133
129
  env = Rack::MockRequest.env_for("/")
134
130
  app = lock_app(lambda { raise Exception }, lock)
135
- lambda { app.call(env) }.should.raise(Exception)
136
- lock.synchronized.should.equal false
131
+ lambda { app.call(env) }.must_raise Exception
132
+ lock.synchronized.must_equal false
137
133
  end
138
134
 
139
- should "unlock if the app throws" do
135
+ it "unlock if the app throws" do
140
136
  lock = Lock.new
141
137
  env = Rack::MockRequest.env_for("/")
142
138
  app = lock_app(lambda {|_| throw :bacon }, lock)
143
- lambda { app.call(env) }.should.throw(:bacon)
144
- lock.synchronized.should.equal false
139
+ lambda { app.call(env) }.must_throw :bacon
140
+ lock.synchronized.must_equal false
145
141
  end
146
142
 
147
- should "set multithread flag to false" do
143
+ it "set multithread flag to false" do
148
144
  app = lock_app(lambda { |env|
149
- env['rack.multithread'].should.equal false
145
+ env['rack.multithread'].must_equal false
150
146
  [200, {"Content-Type" => "text/plain"}, %w{ a b c }]
151
147
  }, false)
152
- app.call(Rack::MockRequest.env_for("/"))
148
+ env = Rack::MockRequest.env_for("/")
149
+ env['rack.multithread'].must_equal true
150
+ _, _, body = app.call(env)
151
+ body.close
152
+ env['rack.multithread'].must_equal true
153
153
  end
154
154
 
155
- should "reset original multithread flag when exiting lock" do
155
+ it "reset original multithread flag when exiting lock" do
156
156
  app = Class.new(Rack::Lock) {
157
157
  def call(env)
158
- env['rack.multithread'].should.equal true
158
+ env['rack.multithread'].must_equal true
159
159
  super
160
160
  end
161
161
  }.new(lambda { |env| [200, {"Content-Type" => "text/plain"}, %w{ a b c }] })
162
162
  Rack::Lint.new(app).call(Rack::MockRequest.env_for("/"))
163
163
  end
164
+
165
+ it 'not unlock if an error is raised before the mutex is locked' do
166
+ lock = Class.new do
167
+ def initialize() @unlocked = false end
168
+ def unlocked?() @unlocked end
169
+ def lock() raise Exception end
170
+ def unlock() @unlocked = true end
171
+ end.new
172
+ env = Rack::MockRequest.env_for("/")
173
+ app = lock_app(proc { [200, {"Content-Type" => "text/plain"}, []] }, lock)
174
+ lambda { app.call(env) }.must_raise Exception
175
+ lock.unlocked?.must_equal false
176
+ end
177
+
178
+ it "not reset the environment while the body is proxied" do
179
+ proxy = Class.new do
180
+ attr_reader :env
181
+ def initialize(env) @env = env end
182
+ end
183
+ app = Rack::Lock.new lambda { |env| [200, {"Content-Type" => "text/plain"}, proxy.new(env)] }
184
+ response = app.call(Rack::MockRequest.env_for("/"))[2]
185
+ response.env['rack.multithread'].must_equal false
186
+ end
187
+
188
+ it "unlock if an exception occurs before returning" do
189
+ lock = Lock.new
190
+ env = Rack::MockRequest.env_for("/")
191
+ app = lock_app(proc { [].freeze }, lock)
192
+ lambda { app.call(env) }.must_raise Exception
193
+ lock.synchronized.must_equal false
194
+ end
195
+
196
+ it "not replace the environment" do
197
+ env = Rack::MockRequest.env_for("/")
198
+ app = lock_app(lambda { |inner_env| [200, {"Content-Type" => "text/plain"}, [inner_env.object_id.to_s]] })
199
+
200
+ _, _, body = app.call(env)
201
+
202
+ body.to_enum.to_a.must_equal [env.object_id.to_s]
203
+ end
164
204
  end
data/test/spec_logger.rb CHANGED
@@ -1,3 +1,4 @@
1
+ require 'minitest/autorun'
1
2
  require 'stringio'
2
3
  require 'rack/lint'
3
4
  require 'rack/logger'
@@ -13,11 +14,11 @@ describe Rack::Logger do
13
14
  [200, {'Content-Type' => 'text/plain'}, ["Hello, World!"]]
14
15
  }
15
16
 
16
- should "conform to Rack::Lint" do
17
+ it "conform to Rack::Lint" do
17
18
  errors = StringIO.new
18
19
  a = Rack::Lint.new(Rack::Logger.new(app))
19
20
  Rack::MockRequest.new(a).get('/', 'rack.errors' => errors)
20
- errors.string.should.match(/INFO -- : Program started/)
21
- errors.string.should.match(/WARN -- : Nothing to do/)
21
+ errors.string.must_match(/INFO -- : Program started/)
22
+ errors.string.must_match(/WARN -- : Nothing to do/)
22
23
  end
23
24
  end
@@ -0,0 +1,42 @@
1
+ require 'minitest/autorun'
2
+ require 'rack/media_type'
3
+
4
+ describe Rack::MediaType do
5
+ before { @empty_hash = {} }
6
+
7
+ describe 'when content_type nil' do
8
+ before { @content_type = nil }
9
+
10
+ it '#type is nil' do
11
+ Rack::MediaType.type(@content_type).must_be_nil
12
+ end
13
+
14
+ it '#params is empty' do
15
+ Rack::MediaType.params(@content_type).must_equal @empty_hash
16
+ end
17
+ end
18
+
19
+ describe 'when content_type contains only media_type' do
20
+ before { @content_type = 'application/text' }
21
+
22
+ it '#type is application/text' do
23
+ Rack::MediaType.type(@content_type).must_equal 'application/text'
24
+ end
25
+
26
+ it '#params is empty' do
27
+ Rack::MediaType.params(@content_type).must_equal @empty_hash
28
+ end
29
+ end
30
+
31
+ describe 'when content_type contains media_type and params' do
32
+ before { @content_type = 'application/text;CHARSET="utf-8"' }
33
+
34
+ it '#type is application/text' do
35
+ Rack::MediaType.type(@content_type).must_equal 'application/text'
36
+ end
37
+
38
+ it '#params has key "charset" with value "utf-8"' do
39
+ Rack::MediaType.params(@content_type)['charset'].must_equal 'utf-8'
40
+ end
41
+ end
42
+ end
@@ -1,5 +1,6 @@
1
+ require 'minitest/autorun'
1
2
  require 'stringio'
2
- require 'rack/methodoverride'
3
+ require 'rack/method_override'
3
4
  require 'rack/mock'
4
5
 
5
6
  describe Rack::MethodOverride do
@@ -9,70 +10,68 @@ describe Rack::MethodOverride do
9
10
  }))
10
11
  end
11
12
 
12
- should "not affect GET requests" do
13
+ it "not affect GET requests" do
13
14
  env = Rack::MockRequest.env_for("/?_method=delete", :method => "GET")
14
15
  app.call env
15
16
 
16
- env["REQUEST_METHOD"].should.equal "GET"
17
+ env["REQUEST_METHOD"].must_equal "GET"
17
18
  end
18
19
 
19
- should "modify REQUEST_METHOD for POST requests when _method parameter is set" do
20
- env = Rack::MockRequest.env_for("/", :method => "POST", :input => "_method=put")
20
+ it "sets rack.errors for invalid UTF8 _method values" do
21
+ errors = StringIO.new
22
+ env = Rack::MockRequest.env_for("/",
23
+ :method => "POST",
24
+ :input => "_method=\xBF".b,
25
+ Rack::RACK_ERRORS => errors)
26
+
21
27
  app.call env
22
28
 
23
- env["REQUEST_METHOD"].should.equal "PUT"
29
+ errors.rewind
30
+ errors.read.must_equal "Invalid string for method\n"
31
+ env["REQUEST_METHOD"].must_equal "POST"
24
32
  end
25
33
 
26
- if RUBY_VERSION >= "1.9"
27
- should "set rack.errors for invalid UTF8 _method values" do
28
- errors = StringIO.new
29
- env = Rack::MockRequest.env_for("/",
30
- :method => "POST",
31
- :input => "_method=\xBF".force_encoding("ASCII-8BIT"),
32
- "rack.errors" => errors)
33
-
34
- app.call env
34
+ it "modify REQUEST_METHOD for POST requests when _method parameter is set" do
35
+ env = Rack::MockRequest.env_for("/", :method => "POST", :input => "_method=put")
36
+ app.call env
35
37
 
36
- errors.rewind
37
- errors.read.should.equal "Invalid string for method\n"
38
- env["REQUEST_METHOD"].should.equal "POST"
39
- end
38
+ env["REQUEST_METHOD"].must_equal "PUT"
40
39
  end
41
40
 
42
- should "modify REQUEST_METHOD for POST requests when X-HTTP-Method-Override is set" do
41
+ it "modify REQUEST_METHOD for POST requests when X-HTTP-Method-Override is set" do
43
42
  env = Rack::MockRequest.env_for("/",
44
43
  :method => "POST",
45
44
  "HTTP_X_HTTP_METHOD_OVERRIDE" => "PATCH"
46
45
  )
47
46
  app.call env
48
47
 
49
- env["REQUEST_METHOD"].should.equal "PATCH"
48
+ env["REQUEST_METHOD"].must_equal "PATCH"
50
49
  end
51
50
 
52
- should "not modify REQUEST_METHOD if the method is unknown" do
51
+ it "not modify REQUEST_METHOD if the method is unknown" do
53
52
  env = Rack::MockRequest.env_for("/", :method => "POST", :input => "_method=foo")
54
53
  app.call env
55
54
 
56
- env["REQUEST_METHOD"].should.equal "POST"
55
+ env["REQUEST_METHOD"].must_equal "POST"
57
56
  end
58
57
 
59
- should "not modify REQUEST_METHOD when _method is nil" do
58
+ it "not modify REQUEST_METHOD when _method is nil" do
60
59
  env = Rack::MockRequest.env_for("/", :method => "POST", :input => "foo=bar")
61
60
  app.call env
62
61
 
63
- env["REQUEST_METHOD"].should.equal "POST"
62
+ env["REQUEST_METHOD"].must_equal "POST"
64
63
  end
65
64
 
66
- should "store the original REQUEST_METHOD prior to overriding" do
65
+ it "store the original REQUEST_METHOD prior to overriding" do
67
66
  env = Rack::MockRequest.env_for("/",
68
67
  :method => "POST",
69
68
  :input => "_method=options")
70
69
  app.call env
71
70
 
72
- env["rack.methodoverride.original_method"].should.equal "POST"
71
+ env["rack.methodoverride.original_method"].must_equal "POST"
73
72
  end
74
73
 
75
- should "not modify REQUEST_METHOD when given invalid multipart form data" do
74
+ it "not modify REQUEST_METHOD when given invalid multipart form data" do
76
75
  input = <<EOF
77
76
  --AaB03x\r
78
77
  content-disposition: form-data; name="huge"; filename="huge"\r
@@ -83,10 +82,10 @@ EOF
83
82
  :method => "POST", :input => input)
84
83
  app.call env
85
84
 
86
- env["REQUEST_METHOD"].should.equal "POST"
85
+ env["REQUEST_METHOD"].must_equal "POST"
87
86
  end
88
87
 
89
- should "write error to RACK_ERRORS when given invalid multipart form data" do
88
+ it "writes error to RACK_ERRORS when given invalid multipart form data" do
90
89
  input = <<EOF
91
90
  --AaB03x\r
92
91
  content-disposition: form-data; name="huge"; filename="huge"\r
@@ -94,18 +93,18 @@ EOF
94
93
  env = Rack::MockRequest.env_for("/",
95
94
  "CONTENT_TYPE" => "multipart/form-data, boundary=AaB03x",
96
95
  "CONTENT_LENGTH" => input.size.to_s,
97
- "rack.errors" => StringIO.new,
96
+ Rack::RACK_ERRORS => StringIO.new,
98
97
  :method => "POST", :input => input)
99
98
  Rack::MethodOverride.new(proc { [200, {"Content-Type" => "text/plain"}, []] }).call env
100
99
 
101
- env["rack.errors"].rewind
102
- env["rack.errors"].read.should =~ /Bad request content body/
100
+ env[Rack::RACK_ERRORS].rewind
101
+ env[Rack::RACK_ERRORS].read.must_match /Bad request content body/
103
102
  end
104
103
 
105
- should "not modify REQUEST_METHOD for POST requests when the params are unparseable" do
104
+ it "not modify REQUEST_METHOD for POST requests when the params are unparseable" do
106
105
  env = Rack::MockRequest.env_for("/", :method => "POST", :input => "(%bad-params%)")
107
106
  app.call env
108
107
 
109
- env["REQUEST_METHOD"].should.equal "POST"
108
+ env["REQUEST_METHOD"].must_equal "POST"
110
109
  end
111
110
  end
data/test/spec_mime.rb CHANGED
@@ -1,51 +1,51 @@
1
+ require 'minitest/autorun'
1
2
  require 'rack/mime'
2
3
 
3
4
  describe Rack::Mime do
4
5
 
5
6
  it "should return the fallback mime-type for files with no extension" do
6
7
  fallback = 'image/jpg'
7
- Rack::Mime.mime_type(File.extname('no_ext'), fallback).should.equal fallback
8
+ Rack::Mime.mime_type(File.extname('no_ext'), fallback).must_equal fallback
8
9
  end
9
10
 
10
11
  it "should always return 'application/octet-stream' for unknown file extensions" do
11
12
  unknown_ext = File.extname('unknown_ext.abcdefg')
12
- Rack::Mime.mime_type(unknown_ext).should.equal 'application/octet-stream'
13
+ Rack::Mime.mime_type(unknown_ext).must_equal 'application/octet-stream'
13
14
  end
14
15
 
15
16
  it "should return the mime-type for a given extension" do
16
17
  # sanity check. it would be infeasible test every single mime-type.
17
- Rack::Mime.mime_type(File.extname('image.jpg')).should.equal 'image/jpeg'
18
+ Rack::Mime.mime_type(File.extname('image.jpg')).must_equal 'image/jpeg'
18
19
  end
19
20
 
20
21
  it "should support null fallbacks" do
21
- Rack::Mime.mime_type('.nothing', nil).should.equal nil
22
+ Rack::Mime.mime_type('.nothing', nil).must_be_nil
22
23
  end
23
24
 
24
25
  it "should match exact mimes" do
25
- Rack::Mime.match?('text/html', 'text/html').should.equal true
26
- Rack::Mime.match?('text/html', 'text/meme').should.equal false
27
- Rack::Mime.match?('text', 'text').should.equal true
28
- Rack::Mime.match?('text', 'binary').should.equal false
26
+ Rack::Mime.match?('text/html', 'text/html').must_equal true
27
+ Rack::Mime.match?('text/html', 'text/meme').must_equal false
28
+ Rack::Mime.match?('text', 'text').must_equal true
29
+ Rack::Mime.match?('text', 'binary').must_equal false
29
30
  end
30
31
 
31
32
  it "should match class wildcard mimes" do
32
- Rack::Mime.match?('text/html', 'text/*').should.equal true
33
- Rack::Mime.match?('text/plain', 'text/*').should.equal true
34
- Rack::Mime.match?('application/json', 'text/*').should.equal false
35
- Rack::Mime.match?('text/html', 'text').should.equal true
33
+ Rack::Mime.match?('text/html', 'text/*').must_equal true
34
+ Rack::Mime.match?('text/plain', 'text/*').must_equal true
35
+ Rack::Mime.match?('application/json', 'text/*').must_equal false
36
+ Rack::Mime.match?('text/html', 'text').must_equal true
36
37
  end
37
38
 
38
39
  it "should match full wildcards" do
39
- Rack::Mime.match?('text/html', '*').should.equal true
40
- Rack::Mime.match?('text/plain', '*').should.equal true
41
- Rack::Mime.match?('text/html', '*/*').should.equal true
42
- Rack::Mime.match?('text/plain', '*/*').should.equal true
40
+ Rack::Mime.match?('text/html', '*').must_equal true
41
+ Rack::Mime.match?('text/plain', '*').must_equal true
42
+ Rack::Mime.match?('text/html', '*/*').must_equal true
43
+ Rack::Mime.match?('text/plain', '*/*').must_equal true
43
44
  end
44
45
 
45
46
  it "should match type wildcard mimes" do
46
- Rack::Mime.match?('text/html', '*/html').should.equal true
47
- Rack::Mime.match?('text/plain', '*/plain').should.equal true
47
+ Rack::Mime.match?('text/html', '*/html').must_equal true
48
+ Rack::Mime.match?('text/plain', '*/plain').must_equal true
48
49
  end
49
50
 
50
51
  end
51
-