rack 1.6.13 → 2.0.1

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 (144) hide show
  1. checksums.yaml +5 -5
  2. data/COPYING +1 -1
  3. data/HISTORY.md +138 -8
  4. data/README.rdoc +17 -25
  5. data/Rakefile +6 -14
  6. data/SPEC +8 -9
  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/{conditionalget.rb → conditional_get.rb} +0 -0
  18. data/lib/rack/content_length.rb +2 -2
  19. data/lib/rack/deflater.rb +4 -4
  20. data/lib/rack/directory.rb +66 -54
  21. data/lib/rack/etag.rb +4 -3
  22. data/lib/rack/events.rb +154 -0
  23. data/lib/rack/file.rb +63 -39
  24. data/lib/rack/handler/cgi.rb +15 -16
  25. data/lib/rack/handler/fastcgi.rb +13 -14
  26. data/lib/rack/handler/lsws.rb +11 -11
  27. data/lib/rack/handler/scgi.rb +15 -15
  28. data/lib/rack/handler/thin.rb +3 -0
  29. data/lib/rack/handler/webrick.rb +22 -24
  30. data/lib/rack/handler.rb +3 -25
  31. data/lib/rack/head.rb +15 -17
  32. data/lib/rack/lint.rb +38 -38
  33. data/lib/rack/lobster.rb +1 -1
  34. data/lib/rack/lock.rb +6 -10
  35. data/lib/rack/logger.rb +2 -2
  36. data/lib/rack/media_type.rb +38 -0
  37. data/lib/rack/{methodoverride.rb → method_override.rb} +4 -11
  38. data/lib/rack/mime.rb +18 -5
  39. data/lib/rack/mock.rb +35 -53
  40. data/lib/rack/multipart/generator.rb +5 -5
  41. data/lib/rack/multipart/parser.rb +272 -158
  42. data/lib/rack/multipart/uploaded_file.rb +1 -2
  43. data/lib/rack/multipart.rb +35 -6
  44. data/lib/rack/{nulllogger.rb → null_logger.rb} +1 -1
  45. data/lib/rack/query_parser.rb +192 -0
  46. data/lib/rack/recursive.rb +8 -8
  47. data/lib/rack/request.rb +383 -307
  48. data/lib/rack/response.rb +129 -56
  49. data/lib/rack/rewindable_input.rb +1 -12
  50. data/lib/rack/runtime.rb +10 -18
  51. data/lib/rack/sendfile.rb +5 -7
  52. data/lib/rack/server.rb +31 -25
  53. data/lib/rack/session/abstract/id.rb +95 -135
  54. data/lib/rack/session/cookie.rb +26 -28
  55. data/lib/rack/session/memcache.rb +8 -14
  56. data/lib/rack/session/pool.rb +14 -21
  57. data/lib/rack/show_exceptions.rb +386 -0
  58. data/lib/rack/{showstatus.rb → show_status.rb} +3 -3
  59. data/lib/rack/static.rb +30 -5
  60. data/lib/rack/tempfile_reaper.rb +2 -2
  61. data/lib/rack/urlmap.rb +15 -14
  62. data/lib/rack/utils.rb +135 -210
  63. data/lib/rack.rb +70 -21
  64. data/rack.gemspec +7 -5
  65. data/test/builder/an_underscore_app.rb +5 -0
  66. data/test/builder/options.ru +1 -1
  67. data/test/cgi/test.fcgi +1 -0
  68. data/test/cgi/test.gz +0 -0
  69. data/test/helper.rb +34 -0
  70. data/test/multipart/filename_with_encoded_words +7 -0
  71. data/test/multipart/{filename_with_null_byte → filename_with_single_quote} +1 -1
  72. data/test/multipart/quoted +15 -0
  73. data/test/multipart/rack-logo.png +0 -0
  74. data/test/multipart/unity3d_wwwform +11 -0
  75. data/test/registering_handler/rack/handler/registering_myself.rb +1 -1
  76. data/test/spec_auth_basic.rb +27 -19
  77. data/test/spec_auth_digest.rb +47 -46
  78. data/test/spec_body_proxy.rb +27 -27
  79. data/test/spec_builder.rb +51 -41
  80. data/test/spec_cascade.rb +24 -22
  81. data/test/spec_cgi.rb +49 -67
  82. data/test/spec_chunked.rb +36 -34
  83. data/test/{spec_commonlogger.rb → spec_common_logger.rb} +23 -21
  84. data/test/{spec_conditionalget.rb → spec_conditional_get.rb} +29 -28
  85. data/test/spec_config.rb +3 -2
  86. data/test/spec_content_length.rb +18 -17
  87. data/test/spec_content_type.rb +13 -12
  88. data/test/spec_deflater.rb +66 -40
  89. data/test/spec_directory.rb +87 -27
  90. data/test/spec_etag.rb +32 -31
  91. data/test/spec_events.rb +133 -0
  92. data/test/spec_fastcgi.rb +50 -72
  93. data/test/spec_file.rb +107 -77
  94. data/test/spec_handler.rb +19 -34
  95. data/test/spec_head.rb +15 -14
  96. data/test/spec_lint.rb +162 -197
  97. data/test/spec_lobster.rb +24 -23
  98. data/test/spec_lock.rb +69 -39
  99. data/test/spec_logger.rb +4 -3
  100. data/test/spec_media_type.rb +42 -0
  101. data/test/spec_method_override.rb +83 -0
  102. data/test/spec_mime.rb +19 -19
  103. data/test/spec_mock.rb +196 -151
  104. data/test/spec_multipart.rb +317 -201
  105. data/test/{spec_nulllogger.rb → spec_null_logger.rb} +5 -4
  106. data/test/spec_recursive.rb +17 -14
  107. data/test/spec_request.rb +768 -607
  108. data/test/spec_response.rb +214 -111
  109. data/test/spec_rewindable_input.rb +50 -40
  110. data/test/spec_runtime.rb +11 -10
  111. data/test/spec_sendfile.rb +30 -35
  112. data/test/spec_server.rb +78 -52
  113. data/test/spec_session_abstract_id.rb +11 -33
  114. data/test/spec_session_abstract_session_hash.rb +28 -0
  115. data/test/spec_session_cookie.rb +97 -65
  116. data/test/spec_session_memcache.rb +63 -101
  117. data/test/spec_session_pool.rb +48 -84
  118. data/test/spec_show_exceptions.rb +80 -0
  119. data/test/{spec_showstatus.rb → spec_show_status.rb} +36 -35
  120. data/test/spec_static.rb +71 -32
  121. data/test/spec_tempfile_reaper.rb +11 -10
  122. data/test/spec_thin.rb +55 -50
  123. data/test/spec_urlmap.rb +79 -78
  124. data/test/spec_utils.rb +441 -346
  125. data/test/spec_version.rb +2 -8
  126. data/test/spec_webrick.rb +91 -67
  127. data/test/static/foo.html +1 -0
  128. data/test/testrequest.rb +1 -1
  129. data/test/unregistered_handler/rack/handler/unregistered.rb +1 -1
  130. data/test/unregistered_handler/rack/handler/unregistered_long_one.rb +1 -1
  131. metadata +103 -69
  132. data/KNOWN-ISSUES +0 -44
  133. data/lib/rack/backports/uri/common_18.rb +0 -56
  134. data/lib/rack/backports/uri/common_192.rb +0 -52
  135. data/lib/rack/backports/uri/common_193.rb +0 -29
  136. data/lib/rack/handler/evented_mongrel.rb +0 -8
  137. data/lib/rack/handler/mongrel.rb +0 -106
  138. data/lib/rack/handler/swiftiplied_mongrel.rb +0 -8
  139. data/lib/rack/showexceptions.rb +0 -387
  140. data/lib/rack/utils/okjson.rb +0 -600
  141. data/test/spec_methodoverride.rb +0 -111
  142. data/test/spec_mongrel.rb +0 -182
  143. data/test/spec_session_persisted_secure_secure_session_hash.rb +0 -73
  144. data/test/spec_showexceptions.rb +0 -98
data/test/spec_mock.rb CHANGED
@@ -1,3 +1,4 @@
1
+ require 'minitest/autorun'
1
2
  require 'yaml'
2
3
  require 'rack/lint'
3
4
  require 'rack/mock'
@@ -19,279 +20,323 @@ app = Rack::Lint.new(lambda { |env|
19
20
  })
20
21
 
21
22
  describe Rack::MockRequest do
22
- should "return a MockResponse" do
23
+ it "return a MockResponse" do
23
24
  res = Rack::MockRequest.new(app).get("")
24
- res.should.be.kind_of Rack::MockResponse
25
+ res.must_be_kind_of Rack::MockResponse
25
26
  end
26
27
 
27
- should "be able to only return the environment" do
28
+ it "be able to only return the environment" do
28
29
  env = Rack::MockRequest.env_for("")
29
- env.should.be.kind_of Hash
30
- env.should.include "rack.version"
30
+ env.must_be_kind_of Hash
31
+ env.must_include "rack.version"
31
32
  end
32
33
 
33
- should "return an environment with a path" do
34
+ it "return an environment with a path" do
34
35
  env = Rack::MockRequest.env_for("http://www.example.com/parse?location[]=1&location[]=2&age_group[]=2")
35
- env["QUERY_STRING"].should.equal "location[]=1&location[]=2&age_group[]=2"
36
- env["PATH_INFO"].should.equal "/parse"
37
- env.should.be.kind_of Hash
38
- env.should.include "rack.version"
36
+ env["QUERY_STRING"].must_equal "location[]=1&location[]=2&age_group[]=2"
37
+ env["PATH_INFO"].must_equal "/parse"
38
+ env.must_be_kind_of Hash
39
+ env.must_include "rack.version"
39
40
  end
40
41
 
41
- should "provide sensible defaults" do
42
+ it "provide sensible defaults" do
42
43
  res = Rack::MockRequest.new(app).request
43
44
 
44
45
  env = YAML.load(res.body)
45
- env["REQUEST_METHOD"].should.equal "GET"
46
- env["SERVER_NAME"].should.equal "example.org"
47
- env["SERVER_PORT"].should.equal "80"
48
- env["QUERY_STRING"].should.equal ""
49
- env["PATH_INFO"].should.equal "/"
50
- env["SCRIPT_NAME"].should.equal ""
51
- env["rack.url_scheme"].should.equal "http"
52
- env["mock.postdata"].should.be.empty
46
+ env["REQUEST_METHOD"].must_equal "GET"
47
+ env["SERVER_NAME"].must_equal "example.org"
48
+ env["SERVER_PORT"].must_equal "80"
49
+ env["QUERY_STRING"].must_equal ""
50
+ env["PATH_INFO"].must_equal "/"
51
+ env["SCRIPT_NAME"].must_equal ""
52
+ env["rack.url_scheme"].must_equal "http"
53
+ env["mock.postdata"].must_be :empty?
53
54
  end
54
55
 
55
- should "allow GET/POST/PUT/DELETE/HEAD" do
56
+ it "allow GET/POST/PUT/DELETE/HEAD" do
56
57
  res = Rack::MockRequest.new(app).get("", :input => "foo")
57
58
  env = YAML.load(res.body)
58
- env["REQUEST_METHOD"].should.equal "GET"
59
+ env["REQUEST_METHOD"].must_equal "GET"
59
60
 
60
61
  res = Rack::MockRequest.new(app).post("", :input => "foo")
61
62
  env = YAML.load(res.body)
62
- env["REQUEST_METHOD"].should.equal "POST"
63
+ env["REQUEST_METHOD"].must_equal "POST"
63
64
 
64
65
  res = Rack::MockRequest.new(app).put("", :input => "foo")
65
66
  env = YAML.load(res.body)
66
- env["REQUEST_METHOD"].should.equal "PUT"
67
+ env["REQUEST_METHOD"].must_equal "PUT"
67
68
 
68
69
  res = Rack::MockRequest.new(app).patch("", :input => "foo")
69
70
  env = YAML.load(res.body)
70
- env["REQUEST_METHOD"].should.equal "PATCH"
71
+ env["REQUEST_METHOD"].must_equal "PATCH"
71
72
 
72
73
  res = Rack::MockRequest.new(app).delete("", :input => "foo")
73
74
  env = YAML.load(res.body)
74
- env["REQUEST_METHOD"].should.equal "DELETE"
75
-
76
- Rack::MockRequest.env_for("/", :method => "HEAD")["REQUEST_METHOD"].
77
- should.equal "HEAD"
75
+ env["REQUEST_METHOD"].must_equal "DELETE"
78
76
 
79
- Rack::MockRequest.env_for("/", :method => "OPTIONS")["REQUEST_METHOD"].
80
- should.equal "OPTIONS"
77
+ Rack::MockRequest.env_for("/", :method => "HEAD")["REQUEST_METHOD"]
78
+ .must_equal "HEAD"
79
+
80
+ Rack::MockRequest.env_for("/", :method => "OPTIONS")["REQUEST_METHOD"]
81
+ .must_equal "OPTIONS"
81
82
  end
82
83
 
83
- should "set content length" do
84
+ it "set content length" do
84
85
  env = Rack::MockRequest.env_for("/", :input => "foo")
85
- env["CONTENT_LENGTH"].should.equal "3"
86
+ env["CONTENT_LENGTH"].must_equal "3"
86
87
  end
87
88
 
88
- should "allow posting" do
89
+ it "allow posting" do
89
90
  res = Rack::MockRequest.new(app).get("", :input => "foo")
90
91
  env = YAML.load(res.body)
91
- env["mock.postdata"].should.equal "foo"
92
+ env["mock.postdata"].must_equal "foo"
92
93
 
93
94
  res = Rack::MockRequest.new(app).post("", :input => StringIO.new("foo"))
94
95
  env = YAML.load(res.body)
95
- env["mock.postdata"].should.equal "foo"
96
+ env["mock.postdata"].must_equal "foo"
96
97
  end
97
98
 
98
- should "use all parts of an URL" do
99
+ it "use all parts of an URL" do
99
100
  res = Rack::MockRequest.new(app).
100
101
  get("https://bla.example.org:9292/meh/foo?bar")
101
- res.should.be.kind_of Rack::MockResponse
102
+ res.must_be_kind_of Rack::MockResponse
102
103
 
103
104
  env = YAML.load(res.body)
104
- env["REQUEST_METHOD"].should.equal "GET"
105
- env["SERVER_NAME"].should.equal "bla.example.org"
106
- env["SERVER_PORT"].should.equal "9292"
107
- env["QUERY_STRING"].should.equal "bar"
108
- env["PATH_INFO"].should.equal "/meh/foo"
109
- env["rack.url_scheme"].should.equal "https"
105
+ env["REQUEST_METHOD"].must_equal "GET"
106
+ env["SERVER_NAME"].must_equal "bla.example.org"
107
+ env["SERVER_PORT"].must_equal "9292"
108
+ env["QUERY_STRING"].must_equal "bar"
109
+ env["PATH_INFO"].must_equal "/meh/foo"
110
+ env["rack.url_scheme"].must_equal "https"
110
111
  end
111
112
 
112
- should "set SSL port and HTTP flag on when using https" do
113
+ it "set SSL port and HTTP flag on when using https" do
113
114
  res = Rack::MockRequest.new(app).
114
115
  get("https://example.org/foo")
115
- res.should.be.kind_of Rack::MockResponse
116
+ res.must_be_kind_of Rack::MockResponse
116
117
 
117
118
  env = YAML.load(res.body)
118
- env["REQUEST_METHOD"].should.equal "GET"
119
- env["SERVER_NAME"].should.equal "example.org"
120
- env["SERVER_PORT"].should.equal "443"
121
- env["QUERY_STRING"].should.equal ""
122
- env["PATH_INFO"].should.equal "/foo"
123
- env["rack.url_scheme"].should.equal "https"
124
- env["HTTPS"].should.equal "on"
119
+ env["REQUEST_METHOD"].must_equal "GET"
120
+ env["SERVER_NAME"].must_equal "example.org"
121
+ env["SERVER_PORT"].must_equal "443"
122
+ env["QUERY_STRING"].must_equal ""
123
+ env["PATH_INFO"].must_equal "/foo"
124
+ env["rack.url_scheme"].must_equal "https"
125
+ env["HTTPS"].must_equal "on"
125
126
  end
126
127
 
127
- should "prepend slash to uri path" do
128
+ it "prepend slash to uri path" do
128
129
  res = Rack::MockRequest.new(app).
129
130
  get("foo")
130
- res.should.be.kind_of Rack::MockResponse
131
+ res.must_be_kind_of Rack::MockResponse
131
132
 
132
133
  env = YAML.load(res.body)
133
- env["REQUEST_METHOD"].should.equal "GET"
134
- env["SERVER_NAME"].should.equal "example.org"
135
- env["SERVER_PORT"].should.equal "80"
136
- env["QUERY_STRING"].should.equal ""
137
- env["PATH_INFO"].should.equal "/foo"
138
- env["rack.url_scheme"].should.equal "http"
134
+ env["REQUEST_METHOD"].must_equal "GET"
135
+ env["SERVER_NAME"].must_equal "example.org"
136
+ env["SERVER_PORT"].must_equal "80"
137
+ env["QUERY_STRING"].must_equal ""
138
+ env["PATH_INFO"].must_equal "/foo"
139
+ env["rack.url_scheme"].must_equal "http"
139
140
  end
140
141
 
141
- should "properly convert method name to an uppercase string" do
142
+ it "properly convert method name to an uppercase string" do
142
143
  res = Rack::MockRequest.new(app).request(:get)
143
144
  env = YAML.load(res.body)
144
- env["REQUEST_METHOD"].should.equal "GET"
145
+ env["REQUEST_METHOD"].must_equal "GET"
145
146
  end
146
147
 
147
- should "accept params and build query string for GET requests" do
148
+ it "accept params and build query string for GET requests" do
148
149
  res = Rack::MockRequest.new(app).get("/foo?baz=2", :params => {:foo => {:bar => "1"}})
149
150
  env = YAML.load(res.body)
150
- env["REQUEST_METHOD"].should.equal "GET"
151
- env["QUERY_STRING"].should.include "baz=2"
152
- env["QUERY_STRING"].should.include "foo[bar]=1"
153
- env["PATH_INFO"].should.equal "/foo"
154
- env["mock.postdata"].should.equal ""
151
+ env["REQUEST_METHOD"].must_equal "GET"
152
+ env["QUERY_STRING"].must_include "baz=2"
153
+ env["QUERY_STRING"].must_include "foo[bar]=1"
154
+ env["PATH_INFO"].must_equal "/foo"
155
+ env["mock.postdata"].must_equal ""
155
156
  end
156
157
 
157
- should "accept raw input in params for GET requests" do
158
+ it "accept raw input in params for GET requests" do
158
159
  res = Rack::MockRequest.new(app).get("/foo?baz=2", :params => "foo[bar]=1")
159
160
  env = YAML.load(res.body)
160
- env["REQUEST_METHOD"].should.equal "GET"
161
- env["QUERY_STRING"].should.include "baz=2"
162
- env["QUERY_STRING"].should.include "foo[bar]=1"
163
- env["PATH_INFO"].should.equal "/foo"
164
- env["mock.postdata"].should.equal ""
161
+ env["REQUEST_METHOD"].must_equal "GET"
162
+ env["QUERY_STRING"].must_include "baz=2"
163
+ env["QUERY_STRING"].must_include "foo[bar]=1"
164
+ env["PATH_INFO"].must_equal "/foo"
165
+ env["mock.postdata"].must_equal ""
165
166
  end
166
167
 
167
- should "accept params and build url encoded params for POST requests" do
168
+ it "accept params and build url encoded params for POST requests" do
168
169
  res = Rack::MockRequest.new(app).post("/foo", :params => {:foo => {:bar => "1"}})
169
170
  env = YAML.load(res.body)
170
- env["REQUEST_METHOD"].should.equal "POST"
171
- env["QUERY_STRING"].should.equal ""
172
- env["PATH_INFO"].should.equal "/foo"
173
- env["CONTENT_TYPE"].should.equal "application/x-www-form-urlencoded"
174
- env["mock.postdata"].should.equal "foo[bar]=1"
171
+ env["REQUEST_METHOD"].must_equal "POST"
172
+ env["QUERY_STRING"].must_equal ""
173
+ env["PATH_INFO"].must_equal "/foo"
174
+ env["CONTENT_TYPE"].must_equal "application/x-www-form-urlencoded"
175
+ env["mock.postdata"].must_equal "foo[bar]=1"
175
176
  end
176
177
 
177
- should "accept raw input in params for POST requests" do
178
+ it "accept raw input in params for POST requests" do
178
179
  res = Rack::MockRequest.new(app).post("/foo", :params => "foo[bar]=1")
179
180
  env = YAML.load(res.body)
180
- env["REQUEST_METHOD"].should.equal "POST"
181
- env["QUERY_STRING"].should.equal ""
182
- env["PATH_INFO"].should.equal "/foo"
183
- env["CONTENT_TYPE"].should.equal "application/x-www-form-urlencoded"
184
- env["mock.postdata"].should.equal "foo[bar]=1"
181
+ env["REQUEST_METHOD"].must_equal "POST"
182
+ env["QUERY_STRING"].must_equal ""
183
+ env["PATH_INFO"].must_equal "/foo"
184
+ env["CONTENT_TYPE"].must_equal "application/x-www-form-urlencoded"
185
+ env["mock.postdata"].must_equal "foo[bar]=1"
185
186
  end
186
187
 
187
- should "accept params and build multipart encoded params for POST requests" do
188
+ it "accept params and build multipart encoded params for POST requests" do
188
189
  files = Rack::Multipart::UploadedFile.new(File.join(File.dirname(__FILE__), "multipart", "file1.txt"))
189
190
  res = Rack::MockRequest.new(app).post("/foo", :params => { "submit-name" => "Larry", "files" => files })
190
191
  env = YAML.load(res.body)
191
- env["REQUEST_METHOD"].should.equal "POST"
192
- env["QUERY_STRING"].should.equal ""
193
- env["PATH_INFO"].should.equal "/foo"
194
- env["CONTENT_TYPE"].should.equal "multipart/form-data; boundary=AaB03x"
192
+ env["REQUEST_METHOD"].must_equal "POST"
193
+ env["QUERY_STRING"].must_equal ""
194
+ env["PATH_INFO"].must_equal "/foo"
195
+ env["CONTENT_TYPE"].must_equal "multipart/form-data; boundary=AaB03x"
195
196
  # The gsub accounts for differences in YAMLs affect on the data.
196
- env["mock.postdata"].gsub("\r", "").length.should.equal 206
197
+ env["mock.postdata"].gsub("\r", "").length.must_equal 206
197
198
  end
198
199
 
199
- should "behave valid according to the Rack spec" do
200
- lambda {
201
- Rack::MockRequest.new(app).
202
- get("https://bla.example.org:9292/meh/foo?bar", :lint => true)
203
- }.should.not.raise(Rack::Lint::LintError)
200
+ it "behave valid according to the Rack spec" do
201
+ url = "https://bla.example.org:9292/meh/foo?bar"
202
+ Rack::MockRequest.new(app).get(url, :lint => true).
203
+ must_be_kind_of Rack::MockResponse
204
204
  end
205
205
 
206
- should "call close on the original body object" do
206
+ it "call close on the original body object" do
207
207
  called = false
208
208
  body = Rack::BodyProxy.new(['hi']) { called = true }
209
209
  capp = proc { |e| [200, {'Content-Type' => 'text/plain'}, body] }
210
- called.should.equal false
210
+ called.must_equal false
211
211
  Rack::MockRequest.new(capp).get('/', :lint => true)
212
- called.should.equal true
213
- end
214
-
215
- if "<3".respond_to? :b
216
- should "defaults encoding to ASCII 8BIT" do
217
- req = Rack::MockRequest.env_for("/foo")
218
-
219
- keys = [
220
- Rack::REQUEST_METHOD,
221
- "SERVER_NAME",
222
- "SERVER_PORT",
223
- Rack::QUERY_STRING,
224
- Rack::PATH_INFO,
225
- "rack.url_scheme",
226
- "HTTPS"
227
- ]
228
-
229
- keys.each do |k|
230
- req[k].encoding.should.equal Encoding::ASCII_8BIT
231
- end
232
- end
212
+ called.must_equal true
233
213
  end
234
214
  end
235
215
 
236
216
  describe Rack::MockResponse do
237
- should "provide access to the HTTP status" do
217
+ it "provide access to the HTTP status" do
238
218
  res = Rack::MockRequest.new(app).get("")
239
- res.should.be.successful
240
- res.should.be.ok
219
+ res.must_be :successful?
220
+ res.must_be :ok?
241
221
 
242
222
  res = Rack::MockRequest.new(app).get("/?status=404")
243
- res.should.not.be.successful
244
- res.should.be.client_error
245
- res.should.be.not_found
223
+ res.wont_be :successful?
224
+ res.must_be :client_error?
225
+ res.must_be :not_found?
246
226
 
247
227
  res = Rack::MockRequest.new(app).get("/?status=501")
248
- res.should.not.be.successful
249
- res.should.be.server_error
228
+ res.wont_be :successful?
229
+ res.must_be :server_error?
250
230
 
251
231
  res = Rack::MockRequest.new(app).get("/?status=307")
252
- res.should.be.redirect
232
+ res.must_be :redirect?
253
233
 
254
234
  res = Rack::MockRequest.new(app).get("/?status=201", :lint => true)
255
- res.should.be.empty
235
+ res.must_be :empty?
256
236
  end
257
237
 
258
- should "provide access to the HTTP headers" do
238
+ it "provide access to the HTTP headers" do
259
239
  res = Rack::MockRequest.new(app).get("")
260
- res.should.include "Content-Type"
261
- res.headers["Content-Type"].should.equal "text/yaml"
262
- res.original_headers["Content-Type"].should.equal "text/yaml"
263
- res["Content-Type"].should.equal "text/yaml"
264
- res.content_type.should.equal "text/yaml"
265
- res.content_length.should.not.equal 0
266
- res.location.should.be.nil
240
+ res.must_include "Content-Type"
241
+ res.headers["Content-Type"].must_equal "text/yaml"
242
+ res.original_headers["Content-Type"].must_equal "text/yaml"
243
+ res["Content-Type"].must_equal "text/yaml"
244
+ res.content_type.must_equal "text/yaml"
245
+ res.content_length.wont_equal 0
246
+ res.location.must_be_nil
267
247
  end
268
248
 
269
- should "provide access to the HTTP body" do
249
+ it "provide access to the HTTP body" do
270
250
  res = Rack::MockRequest.new(app).get("")
271
- res.body.should =~ /rack/
272
- res.should =~ /rack/
273
- res.should.match(/rack/)
274
- res.should.satisfy { |r| r.match(/rack/) }
251
+ res.body.must_match(/rack/)
252
+ assert_match(res, /rack/)
275
253
  end
276
254
 
277
- should "provide access to the Rack errors" do
255
+ it "provide access to the Rack errors" do
278
256
  res = Rack::MockRequest.new(app).get("/?error=foo", :lint => true)
279
- res.should.be.ok
280
- res.errors.should.not.be.empty
281
- res.errors.should.include "foo"
257
+ res.must_be :ok?
258
+ res.errors.wont_be :empty?
259
+ res.errors.must_include "foo"
282
260
  end
283
261
 
284
- should "allow calling body.close afterwards" do
262
+ it "allow calling body.close afterwards" do
285
263
  # this is exactly what rack-test does
286
264
  body = StringIO.new("hi")
287
265
  res = Rack::MockResponse.new(200, {}, body)
288
266
  body.close if body.respond_to?(:close)
289
- res.body.should == 'hi'
267
+ res.body.must_equal 'hi'
290
268
  end
291
269
 
292
- should "optionally make Rack errors fatal" do
270
+ it "optionally make Rack errors fatal" do
293
271
  lambda {
294
272
  Rack::MockRequest.new(app).get("/?error=foo", :fatal => true)
295
- }.should.raise(Rack::MockRequest::FatalWarning)
273
+ }.must_raise Rack::MockRequest::FatalWarning
274
+ end
275
+ end
276
+
277
+ describe Rack::MockResponse, 'headers' do
278
+ before do
279
+ @res = Rack::MockRequest.new(app).get('')
280
+ @res.set_header 'FOO', '1'
281
+ end
282
+
283
+ it 'has_header?' do
284
+ lambda { @res.has_header? nil }.must_raise NoMethodError
285
+
286
+ @res.has_header?('FOO').must_equal true
287
+ @res.has_header?('Foo').must_equal true
288
+ end
289
+
290
+ it 'get_header' do
291
+ lambda { @res.get_header nil }.must_raise NoMethodError
292
+
293
+ @res.get_header('FOO').must_equal '1'
294
+ @res.get_header('Foo').must_equal '1'
295
+ end
296
+
297
+ it 'set_header' do
298
+ lambda { @res.set_header nil, '1' }.must_raise NoMethodError
299
+
300
+ @res.set_header('FOO', '2').must_equal '2'
301
+ @res.get_header('FOO').must_equal '2'
302
+
303
+ @res.set_header('Foo', '3').must_equal '3'
304
+ @res.get_header('Foo').must_equal '3'
305
+ @res.get_header('FOO').must_equal '3'
306
+
307
+ @res.set_header('FOO', nil).must_be_nil
308
+ @res.get_header('FOO').must_be_nil
309
+ @res.has_header?('FOO').must_equal true
310
+ end
311
+
312
+ it 'add_header' do
313
+ lambda { @res.add_header nil, '1' }.must_raise NoMethodError
314
+
315
+ # Sets header on first addition
316
+ @res.add_header('FOO', '1').must_equal '1,1'
317
+ @res.get_header('FOO').must_equal '1,1'
318
+
319
+ # Ignores nil additions
320
+ @res.add_header('FOO', nil).must_equal '1,1'
321
+ @res.get_header('FOO').must_equal '1,1'
322
+
323
+ # Converts additions to strings
324
+ @res.add_header('FOO', 2).must_equal '1,1,2'
325
+ @res.get_header('FOO').must_equal '1,1,2'
326
+
327
+ # Respects underlying case-sensitivity
328
+ @res.add_header('Foo', 'yep').must_equal '1,1,2,yep'
329
+ @res.get_header('Foo').must_equal '1,1,2,yep'
330
+ @res.get_header('FOO').must_equal '1,1,2,yep'
331
+ end
332
+
333
+ it 'delete_header' do
334
+ lambda { @res.delete_header nil }.must_raise NoMethodError
335
+
336
+ @res.delete_header('FOO').must_equal '1'
337
+ @res.has_header?('FOO').must_equal false
338
+
339
+ @res.has_header?('Foo').must_equal false
340
+ @res.delete_header('Foo').must_be_nil
296
341
  end
297
342
  end