rack 1.1.6 → 1.6.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (212) hide show
  1. checksums.yaml +7 -0
  2. data/COPYING +1 -1
  3. data/HISTORY.md +375 -0
  4. data/KNOWN-ISSUES +23 -0
  5. data/README.rdoc +312 -0
  6. data/Rakefile +124 -0
  7. data/SPEC +125 -32
  8. data/contrib/rack.png +0 -0
  9. data/contrib/rack.svg +150 -0
  10. data/contrib/rack_logo.svg +1 -1
  11. data/contrib/rdoc.css +412 -0
  12. data/example/protectedlobster.rb +1 -1
  13. data/lib/rack/auth/abstract/handler.rb +4 -4
  14. data/lib/rack/auth/abstract/request.rb +7 -5
  15. data/lib/rack/auth/basic.rb +1 -1
  16. data/lib/rack/auth/digest/md5.rb +7 -3
  17. data/lib/rack/auth/digest/nonce.rb +1 -1
  18. data/lib/rack/auth/digest/params.rb +7 -9
  19. data/lib/rack/auth/digest/request.rb +10 -9
  20. data/lib/rack/backports/uri/common_18.rb +56 -0
  21. data/lib/rack/backports/uri/common_192.rb +52 -0
  22. data/lib/rack/backports/uri/common_193.rb +29 -0
  23. data/lib/rack/body_proxy.rb +39 -0
  24. data/lib/rack/builder.rb +106 -22
  25. data/lib/rack/cascade.rb +17 -6
  26. data/lib/rack/chunked.rb +44 -24
  27. data/lib/rack/commonlogger.rb +36 -13
  28. data/lib/rack/conditionalget.rb +49 -17
  29. data/lib/rack/config.rb +5 -0
  30. data/lib/rack/content_length.rb +14 -6
  31. data/lib/rack/content_type.rb +7 -1
  32. data/lib/rack/deflater.rb +73 -15
  33. data/lib/rack/directory.rb +18 -8
  34. data/lib/rack/etag.rb +59 -9
  35. data/lib/rack/file.rb +106 -44
  36. data/lib/rack/handler/cgi.rb +11 -11
  37. data/lib/rack/handler/fastcgi.rb +18 -6
  38. data/lib/rack/handler/lsws.rb +2 -4
  39. data/lib/rack/handler/mongrel.rb +22 -6
  40. data/lib/rack/handler/scgi.rb +16 -8
  41. data/lib/rack/handler/thin.rb +19 -4
  42. data/lib/rack/handler/webrick.rb +72 -19
  43. data/lib/rack/handler.rb +47 -14
  44. data/lib/rack/head.rb +10 -2
  45. data/lib/rack/lint.rb +260 -75
  46. data/lib/rack/lobster.rb +13 -8
  47. data/lib/rack/lock.rb +13 -3
  48. data/lib/rack/logger.rb +0 -2
  49. data/lib/rack/methodoverride.rb +27 -8
  50. data/lib/rack/mime.rb +625 -167
  51. data/lib/rack/mock.rb +78 -53
  52. data/lib/rack/multipart/generator.rb +93 -0
  53. data/lib/rack/multipart/parser.rb +253 -0
  54. data/lib/rack/multipart/uploaded_file.rb +34 -0
  55. data/lib/rack/multipart.rb +34 -0
  56. data/lib/rack/nulllogger.rb +21 -2
  57. data/lib/rack/recursive.rb +10 -5
  58. data/lib/rack/reloader.rb +3 -2
  59. data/lib/rack/request.rb +201 -74
  60. data/lib/rack/response.rb +41 -28
  61. data/lib/rack/rewindable_input.rb +15 -11
  62. data/lib/rack/runtime.rb +16 -3
  63. data/lib/rack/sendfile.rb +47 -29
  64. data/lib/rack/server.rb +223 -47
  65. data/lib/rack/session/abstract/id.rb +289 -30
  66. data/lib/rack/session/cookie.rb +133 -44
  67. data/lib/rack/session/memcache.rb +30 -56
  68. data/lib/rack/session/pool.rb +19 -43
  69. data/lib/rack/showexceptions.rb +53 -15
  70. data/lib/rack/showstatus.rb +14 -7
  71. data/lib/rack/static.rb +124 -12
  72. data/lib/rack/tempfile_reaper.rb +22 -0
  73. data/lib/rack/urlmap.rb +49 -15
  74. data/lib/rack/utils/okjson.rb +600 -0
  75. data/lib/rack/utils.rb +363 -361
  76. data/lib/rack.rb +17 -23
  77. data/rack.gemspec +11 -20
  78. data/test/builder/anything.rb +5 -0
  79. data/test/builder/comment.ru +4 -0
  80. data/test/builder/end.ru +5 -0
  81. data/test/builder/line.ru +1 -0
  82. data/test/builder/options.ru +2 -0
  83. data/test/cgi/assets/folder/test.js +1 -0
  84. data/test/cgi/assets/fonts/font.eot +1 -0
  85. data/test/cgi/assets/images/image.png +1 -0
  86. data/test/cgi/assets/index.html +1 -0
  87. data/test/cgi/assets/javascripts/app.js +1 -0
  88. data/test/cgi/assets/stylesheets/app.css +1 -0
  89. data/test/cgi/lighttpd.conf +26 -0
  90. data/test/cgi/rackup_stub.rb +6 -0
  91. data/test/cgi/sample_rackup.ru +5 -0
  92. data/test/cgi/test +9 -0
  93. data/test/cgi/test+directory/test+file +1 -0
  94. data/test/cgi/test.fcgi +8 -0
  95. data/test/cgi/test.ru +5 -0
  96. data/test/gemloader.rb +10 -0
  97. data/test/multipart/bad_robots +259 -0
  98. data/test/multipart/binary +0 -0
  99. data/test/multipart/content_type_and_no_filename +6 -0
  100. data/test/multipart/empty +10 -0
  101. data/test/multipart/fail_16384_nofile +814 -0
  102. data/test/multipart/file1.txt +1 -0
  103. data/test/multipart/filename_and_modification_param +7 -0
  104. data/test/multipart/filename_and_no_name +6 -0
  105. data/test/multipart/filename_with_escaped_quotes +6 -0
  106. data/test/multipart/filename_with_escaped_quotes_and_modification_param +7 -0
  107. data/test/multipart/filename_with_null_byte +7 -0
  108. data/test/multipart/filename_with_percent_escaped_quotes +6 -0
  109. data/test/multipart/filename_with_unescaped_percentages +6 -0
  110. data/test/multipart/filename_with_unescaped_percentages2 +6 -0
  111. data/test/multipart/filename_with_unescaped_percentages3 +6 -0
  112. data/test/multipart/filename_with_unescaped_quotes +6 -0
  113. data/test/multipart/ie +6 -0
  114. data/test/multipart/invalid_character +6 -0
  115. data/test/multipart/mixed_files +21 -0
  116. data/test/multipart/nested +10 -0
  117. data/test/multipart/none +9 -0
  118. data/test/multipart/semicolon +6 -0
  119. data/test/multipart/text +15 -0
  120. data/test/multipart/three_files_three_fields +31 -0
  121. data/test/multipart/webkit +32 -0
  122. data/test/rackup/config.ru +31 -0
  123. data/test/registering_handler/rack/handler/registering_myself.rb +8 -0
  124. data/test/{spec_rack_auth_basic.rb → spec_auth_basic.rb} +23 -15
  125. data/test/{spec_rack_auth_digest.rb → spec_auth_digest.rb} +56 -29
  126. data/test/spec_body_proxy.rb +85 -0
  127. data/test/spec_builder.rb +223 -0
  128. data/test/{spec_rack_cascade.rb → spec_cascade.rb} +28 -15
  129. data/test/{spec_rack_cgi.rb → spec_cgi.rb} +44 -31
  130. data/test/spec_chunked.rb +101 -0
  131. data/test/spec_commonlogger.rb +93 -0
  132. data/test/spec_conditionalget.rb +102 -0
  133. data/test/{spec_rack_config.rb → spec_config.rb} +6 -8
  134. data/test/spec_content_length.rb +85 -0
  135. data/test/spec_content_type.rb +45 -0
  136. data/test/spec_deflater.rb +339 -0
  137. data/test/{spec_rack_directory.rb → spec_directory.rb} +37 -10
  138. data/test/spec_etag.rb +107 -0
  139. data/test/{spec_rack_fastcgi.rb → spec_fastcgi.rb} +47 -29
  140. data/test/spec_file.rb +221 -0
  141. data/test/spec_handler.rb +72 -0
  142. data/test/spec_head.rb +45 -0
  143. data/test/{spec_rack_lint.rb → spec_lint.rb} +82 -60
  144. data/test/spec_lobster.rb +58 -0
  145. data/test/spec_lock.rb +164 -0
  146. data/test/spec_logger.rb +23 -0
  147. data/test/spec_methodoverride.rb +95 -0
  148. data/test/spec_mime.rb +51 -0
  149. data/test/{spec_rack_mock.rb → spec_mock.rb} +92 -38
  150. data/test/{spec_rack_mongrel.rb → spec_mongrel.rb} +46 -53
  151. data/test/spec_multipart.rb +600 -0
  152. data/test/spec_nulllogger.rb +20 -0
  153. data/test/spec_recursive.rb +72 -0
  154. data/test/spec_request.rb +1227 -0
  155. data/test/spec_response.rb +407 -0
  156. data/test/spec_rewindable_input.rb +118 -0
  157. data/test/spec_runtime.rb +49 -0
  158. data/test/spec_sendfile.rb +130 -0
  159. data/test/spec_server.rb +167 -0
  160. data/test/spec_session_abstract_id.rb +53 -0
  161. data/test/spec_session_cookie.rb +410 -0
  162. data/test/{spec_rack_session_memcache.rb → spec_session_memcache.rb} +119 -71
  163. data/test/{spec_rack_session_pool.rb → spec_session_pool.rb} +106 -69
  164. data/test/spec_showexceptions.rb +85 -0
  165. data/test/spec_showstatus.rb +103 -0
  166. data/test/spec_static.rb +145 -0
  167. data/test/spec_tempfile_reaper.rb +63 -0
  168. data/test/{spec_rack_thin.rb → spec_thin.rb} +35 -35
  169. data/test/{spec_rack_urlmap.rb → spec_urlmap.rb} +40 -19
  170. data/test/spec_utils.rb +647 -0
  171. data/test/spec_version.rb +17 -0
  172. data/test/spec_webrick.rb +184 -0
  173. data/test/static/another/index.html +1 -0
  174. data/test/static/index.html +1 -0
  175. data/test/testrequest.rb +78 -0
  176. data/test/unregistered_handler/rack/handler/unregistered.rb +7 -0
  177. data/test/unregistered_handler/rack/handler/unregistered_long_one.rb +7 -0
  178. metadata +220 -239
  179. data/RDOX +0 -0
  180. data/README +0 -592
  181. data/lib/rack/adapter/camping.rb +0 -22
  182. data/test/spec_auth.rb +0 -57
  183. data/test/spec_rack_builder.rb +0 -84
  184. data/test/spec_rack_camping.rb +0 -55
  185. data/test/spec_rack_chunked.rb +0 -62
  186. data/test/spec_rack_commonlogger.rb +0 -61
  187. data/test/spec_rack_conditionalget.rb +0 -41
  188. data/test/spec_rack_content_length.rb +0 -43
  189. data/test/spec_rack_content_type.rb +0 -30
  190. data/test/spec_rack_deflater.rb +0 -127
  191. data/test/spec_rack_etag.rb +0 -17
  192. data/test/spec_rack_file.rb +0 -75
  193. data/test/spec_rack_handler.rb +0 -43
  194. data/test/spec_rack_head.rb +0 -30
  195. data/test/spec_rack_lobster.rb +0 -45
  196. data/test/spec_rack_lock.rb +0 -38
  197. data/test/spec_rack_logger.rb +0 -21
  198. data/test/spec_rack_methodoverride.rb +0 -60
  199. data/test/spec_rack_nulllogger.rb +0 -13
  200. data/test/spec_rack_recursive.rb +0 -77
  201. data/test/spec_rack_request.rb +0 -594
  202. data/test/spec_rack_response.rb +0 -221
  203. data/test/spec_rack_rewindable_input.rb +0 -118
  204. data/test/spec_rack_runtime.rb +0 -35
  205. data/test/spec_rack_sendfile.rb +0 -86
  206. data/test/spec_rack_session_cookie.rb +0 -92
  207. data/test/spec_rack_showexceptions.rb +0 -21
  208. data/test/spec_rack_showstatus.rb +0 -72
  209. data/test/spec_rack_static.rb +0 -37
  210. data/test/spec_rack_utils.rb +0 -557
  211. data/test/spec_rack_webrick.rb +0 -130
  212. data/test/spec_rackup.rb +0 -164
@@ -1,35 +1,44 @@
1
1
  require 'yaml'
2
+ require 'rack/lint'
2
3
  require 'rack/mock'
3
- require 'rack/request'
4
- require 'rack/response'
4
+ require 'stringio'
5
5
 
6
- app = lambda { |env|
6
+ app = Rack::Lint.new(lambda { |env|
7
7
  req = Rack::Request.new(env)
8
-
8
+
9
9
  env["mock.postdata"] = env["rack.input"].read
10
10
  if req.GET["error"]
11
11
  env["rack.errors"].puts req.GET["error"]
12
12
  env["rack.errors"].flush
13
13
  end
14
-
15
- Rack::Response.new(env.to_yaml,
14
+
15
+ body = req.head? ? "" : env.to_yaml
16
+ Rack::Response.new(body,
16
17
  req.GET["status"] || 200,
17
18
  "Content-Type" => "text/yaml").finish
18
- }
19
+ })
19
20
 
20
- context "Rack::MockRequest" do
21
- specify "should return a MockResponse" do
21
+ describe Rack::MockRequest do
22
+ should "return a MockResponse" do
22
23
  res = Rack::MockRequest.new(app).get("")
23
24
  res.should.be.kind_of Rack::MockResponse
24
25
  end
25
26
 
26
- specify "should be able to only return the environment" do
27
+ should "be able to only return the environment" do
27
28
  env = Rack::MockRequest.env_for("")
28
29
  env.should.be.kind_of Hash
29
30
  env.should.include "rack.version"
30
31
  end
31
32
 
32
- specify "should provide sensible defaults" do
33
+ should "return an environment with a path" do
34
+ 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"
39
+ end
40
+
41
+ should "provide sensible defaults" do
33
42
  res = Rack::MockRequest.new(app).request
34
43
 
35
44
  env = YAML.load(res.body)
@@ -43,7 +52,7 @@ context "Rack::MockRequest" do
43
52
  env["mock.postdata"].should.be.empty
44
53
  end
45
54
 
46
- specify "should allow GET/POST/PUT/DELETE" do
55
+ should "allow GET/POST/PUT/DELETE/HEAD" do
47
56
  res = Rack::MockRequest.new(app).get("", :input => "foo")
48
57
  env = YAML.load(res.body)
49
58
  env["REQUEST_METHOD"].should.equal "GET"
@@ -56,20 +65,27 @@ context "Rack::MockRequest" do
56
65
  env = YAML.load(res.body)
57
66
  env["REQUEST_METHOD"].should.equal "PUT"
58
67
 
68
+ res = Rack::MockRequest.new(app).patch("", :input => "foo")
69
+ env = YAML.load(res.body)
70
+ env["REQUEST_METHOD"].should.equal "PATCH"
71
+
59
72
  res = Rack::MockRequest.new(app).delete("", :input => "foo")
60
73
  env = YAML.load(res.body)
61
74
  env["REQUEST_METHOD"].should.equal "DELETE"
75
+
76
+ Rack::MockRequest.env_for("/", :method => "HEAD")["REQUEST_METHOD"].
77
+ should.equal "HEAD"
62
78
 
63
79
  Rack::MockRequest.env_for("/", :method => "OPTIONS")["REQUEST_METHOD"].
64
80
  should.equal "OPTIONS"
65
81
  end
66
82
 
67
- specify "should set content length" do
83
+ should "set content length" do
68
84
  env = Rack::MockRequest.env_for("/", :input => "foo")
69
85
  env["CONTENT_LENGTH"].should.equal "3"
70
86
  end
71
87
 
72
- specify "should allow posting" do
88
+ should "allow posting" do
73
89
  res = Rack::MockRequest.new(app).get("", :input => "foo")
74
90
  env = YAML.load(res.body)
75
91
  env["mock.postdata"].should.equal "foo"
@@ -79,7 +95,7 @@ context "Rack::MockRequest" do
79
95
  env["mock.postdata"].should.equal "foo"
80
96
  end
81
97
 
82
- specify "should use all parts of an URL" do
98
+ should "use all parts of an URL" do
83
99
  res = Rack::MockRequest.new(app).
84
100
  get("https://bla.example.org:9292/meh/foo?bar")
85
101
  res.should.be.kind_of Rack::MockResponse
@@ -93,7 +109,7 @@ context "Rack::MockRequest" do
93
109
  env["rack.url_scheme"].should.equal "https"
94
110
  end
95
111
 
96
- specify "should set SSL port and HTTP flag on when using https" do
112
+ should "set SSL port and HTTP flag on when using https" do
97
113
  res = Rack::MockRequest.new(app).
98
114
  get("https://example.org/foo")
99
115
  res.should.be.kind_of Rack::MockResponse
@@ -108,7 +124,7 @@ context "Rack::MockRequest" do
108
124
  env["HTTPS"].should.equal "on"
109
125
  end
110
126
 
111
- specify "should prepend slash to uri path" do
127
+ should "prepend slash to uri path" do
112
128
  res = Rack::MockRequest.new(app).
113
129
  get("foo")
114
130
  res.should.be.kind_of Rack::MockResponse
@@ -122,33 +138,33 @@ context "Rack::MockRequest" do
122
138
  env["rack.url_scheme"].should.equal "http"
123
139
  end
124
140
 
125
- specify "should properly convert method name to an uppercase string" do
141
+ should "properly convert method name to an uppercase string" do
126
142
  res = Rack::MockRequest.new(app).request(:get)
127
143
  env = YAML.load(res.body)
128
144
  env["REQUEST_METHOD"].should.equal "GET"
129
145
  end
130
146
 
131
- specify "should accept params and build query string for GET requests" do
147
+ should "accept params and build query string for GET requests" do
132
148
  res = Rack::MockRequest.new(app).get("/foo?baz=2", :params => {:foo => {:bar => "1"}})
133
149
  env = YAML.load(res.body)
134
150
  env["REQUEST_METHOD"].should.equal "GET"
135
- env["QUERY_STRING"].should.match "baz=2"
136
- env["QUERY_STRING"].should.match "foo[bar]=1"
151
+ env["QUERY_STRING"].should.include "baz=2"
152
+ env["QUERY_STRING"].should.include "foo[bar]=1"
137
153
  env["PATH_INFO"].should.equal "/foo"
138
154
  env["mock.postdata"].should.equal ""
139
155
  end
140
156
 
141
- specify "should accept raw input in params for GET requests" do
157
+ should "accept raw input in params for GET requests" do
142
158
  res = Rack::MockRequest.new(app).get("/foo?baz=2", :params => "foo[bar]=1")
143
159
  env = YAML.load(res.body)
144
160
  env["REQUEST_METHOD"].should.equal "GET"
145
- env["QUERY_STRING"].should.match "baz=2"
146
- env["QUERY_STRING"].should.match "foo[bar]=1"
161
+ env["QUERY_STRING"].should.include "baz=2"
162
+ env["QUERY_STRING"].should.include "foo[bar]=1"
147
163
  env["PATH_INFO"].should.equal "/foo"
148
164
  env["mock.postdata"].should.equal ""
149
165
  end
150
166
 
151
- specify "should accept params and build url encoded params for POST requests" do
167
+ should "accept params and build url encoded params for POST requests" do
152
168
  res = Rack::MockRequest.new(app).post("/foo", :params => {:foo => {:bar => "1"}})
153
169
  env = YAML.load(res.body)
154
170
  env["REQUEST_METHOD"].should.equal "POST"
@@ -158,7 +174,7 @@ context "Rack::MockRequest" do
158
174
  env["mock.postdata"].should.equal "foo[bar]=1"
159
175
  end
160
176
 
161
- specify "should accept raw input in params for POST requests" do
177
+ should "accept raw input in params for POST requests" do
162
178
  res = Rack::MockRequest.new(app).post("/foo", :params => "foo[bar]=1")
163
179
  env = YAML.load(res.body)
164
180
  env["REQUEST_METHOD"].should.equal "POST"
@@ -168,27 +184,57 @@ context "Rack::MockRequest" do
168
184
  env["mock.postdata"].should.equal "foo[bar]=1"
169
185
  end
170
186
 
171
- specify "should accept params and build multipart encoded params for POST requests" do
172
- files = Rack::Utils::Multipart::UploadedFile.new(File.join(File.dirname(__FILE__), "multipart", "file1.txt"))
187
+ should "accept params and build multipart encoded params for POST requests" do
188
+ files = Rack::Multipart::UploadedFile.new(File.join(File.dirname(__FILE__), "multipart", "file1.txt"))
173
189
  res = Rack::MockRequest.new(app).post("/foo", :params => { "submit-name" => "Larry", "files" => files })
174
190
  env = YAML.load(res.body)
175
191
  env["REQUEST_METHOD"].should.equal "POST"
176
192
  env["QUERY_STRING"].should.equal ""
177
193
  env["PATH_INFO"].should.equal "/foo"
178
194
  env["CONTENT_TYPE"].should.equal "multipart/form-data; boundary=AaB03x"
179
- env["mock.postdata"].length.should.equal 206
195
+ # The gsub accounts for differences in YAMLs affect on the data.
196
+ env["mock.postdata"].gsub("\r", "").length.should.equal 206
180
197
  end
181
198
 
182
- specify "should behave valid according to the Rack spec" do
199
+ should "behave valid according to the Rack spec" do
183
200
  lambda {
184
- res = Rack::MockRequest.new(app).
201
+ Rack::MockRequest.new(app).
185
202
  get("https://bla.example.org:9292/meh/foo?bar", :lint => true)
186
203
  }.should.not.raise(Rack::Lint::LintError)
187
204
  end
205
+
206
+ should "call close on the original body object" do
207
+ called = false
208
+ body = Rack::BodyProxy.new(['hi']) { called = true }
209
+ capp = proc { |e| [200, {'Content-Type' => 'text/plain'}, body] }
210
+ called.should.equal false
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
233
+ end
188
234
  end
189
235
 
190
- context "Rack::MockResponse" do
191
- specify "should provide access to the HTTP status" do
236
+ describe Rack::MockResponse do
237
+ should "provide access to the HTTP status" do
192
238
  res = Rack::MockRequest.new(app).get("")
193
239
  res.should.be.successful
194
240
  res.should.be.ok
@@ -209,18 +255,18 @@ context "Rack::MockResponse" do
209
255
  res.should.be.empty
210
256
  end
211
257
 
212
- specify "should provide access to the HTTP headers" do
258
+ should "provide access to the HTTP headers" do
213
259
  res = Rack::MockRequest.new(app).get("")
214
260
  res.should.include "Content-Type"
215
261
  res.headers["Content-Type"].should.equal "text/yaml"
216
262
  res.original_headers["Content-Type"].should.equal "text/yaml"
217
263
  res["Content-Type"].should.equal "text/yaml"
218
264
  res.content_type.should.equal "text/yaml"
219
- res.content_length.should.be 414 # needs change often.
265
+ res.content_length.should.not.equal 0
220
266
  res.location.should.be.nil
221
267
  end
222
268
 
223
- specify "should provide access to the HTTP body" do
269
+ should "provide access to the HTTP body" do
224
270
  res = Rack::MockRequest.new(app).get("")
225
271
  res.body.should =~ /rack/
226
272
  res.should =~ /rack/
@@ -228,14 +274,22 @@ context "Rack::MockResponse" do
228
274
  res.should.satisfy { |r| r.match(/rack/) }
229
275
  end
230
276
 
231
- specify "should provide access to the Rack errors" do
277
+ should "provide access to the Rack errors" do
232
278
  res = Rack::MockRequest.new(app).get("/?error=foo", :lint => true)
233
279
  res.should.be.ok
234
280
  res.errors.should.not.be.empty
235
281
  res.errors.should.include "foo"
236
282
  end
237
283
 
238
- specify "should optionally make Rack errors fatal" do
284
+ should "allow calling body.close afterwards" do
285
+ # this is exactly what rack-test does
286
+ body = StringIO.new("hi")
287
+ res = Rack::MockResponse.new(200, {}, body)
288
+ body.close if body.respond_to?(:close)
289
+ res.body.should == 'hi'
290
+ end
291
+
292
+ should "optionally make Rack errors fatal" do
239
293
  lambda {
240
294
  Rack::MockRequest.new(app).get("/?error=foo", :fatal => true)
241
295
  }.should.raise(Rack::MockRequest::FatalWarning)
@@ -1,53 +1,48 @@
1
- require 'test/spec'
2
-
3
1
  begin
2
+ require 'rack'
4
3
  require 'rack/handler/mongrel'
5
- require 'rack/urlmap'
6
- require 'rack/lint'
7
- require 'testrequest'
4
+ require File.expand_path('../testrequest', __FILE__)
8
5
  require 'timeout'
9
6
 
10
7
  Thread.abort_on_exception = true
11
8
  $tcp_defer_accept_opts = nil
12
9
  $tcp_cork_opts = nil
13
10
 
14
- context "Rack::Handler::Mongrel" do
15
- include TestRequest::Helpers
11
+ describe Rack::Handler::Mongrel do
12
+ extend TestRequest::Helpers
16
13
 
17
- setup do
18
- server = Mongrel::HttpServer.new(@host='0.0.0.0', @port=9201)
19
- server.register('/test',
20
- Rack::Handler::Mongrel.new(Rack::Lint.new(TestRequest.new)))
21
- server.register('/stream',
22
- Rack::Handler::Mongrel.new(Rack::Lint.new(StreamingRequest)))
23
- @acc = server.run
24
- end
14
+ @server = Mongrel::HttpServer.new(@host='127.0.0.1', @port=9201)
15
+ @server.register('/test',
16
+ Rack::Handler::Mongrel.new(Rack::Lint.new(TestRequest.new)))
17
+ @server.register('/stream',
18
+ Rack::Handler::Mongrel.new(Rack::Lint.new(StreamingRequest)))
19
+ @acc = @server.run
25
20
 
26
- specify "should respond" do
21
+ should "respond" do
27
22
  lambda {
28
23
  GET("/test")
29
24
  }.should.not.raise
30
25
  end
31
26
 
32
- specify "should be a Mongrel" do
27
+ should "be a Mongrel" do
33
28
  GET("/test")
34
- status.should.be 200
29
+ status.should.equal 200
35
30
  response["SERVER_SOFTWARE"].should =~ /Mongrel/
36
31
  response["HTTP_VERSION"].should.equal "HTTP/1.1"
37
32
  response["SERVER_PROTOCOL"].should.equal "HTTP/1.1"
38
33
  response["SERVER_PORT"].should.equal "9201"
39
- response["SERVER_NAME"].should.equal "0.0.0.0"
34
+ response["SERVER_NAME"].should.equal "127.0.0.1"
40
35
  end
41
36
 
42
- specify "should have rack headers" do
37
+ should "have rack headers" do
43
38
  GET("/test")
44
- response["rack.version"].should.equal [1,1]
45
- response["rack.multithread"].should.be true
46
- response["rack.multiprocess"].should.be false
47
- response["rack.run_once"].should.be false
39
+ response["rack.version"].should.equal [1,3]
40
+ response["rack.multithread"].should.be.true
41
+ response["rack.multiprocess"].should.be.false
42
+ response["rack.run_once"].should.be.false
48
43
  end
49
44
 
50
- specify "should have CGI headers on GET" do
45
+ should "have CGI headers on GET" do
51
46
  GET("/test")
52
47
  response["REQUEST_METHOD"].should.equal "GET"
53
48
  response["SCRIPT_NAME"].should.equal "/test"
@@ -64,7 +59,7 @@ context "Rack::Handler::Mongrel" do
64
59
  response["QUERY_STRING"].should.equal "quux=1"
65
60
  end
66
61
 
67
- specify "should have CGI headers on POST" do
62
+ should "have CGI headers on POST" do
68
63
  POST("/test", {"rack-form-data" => "23"}, {'X-test-header' => '42'})
69
64
  status.should.equal 200
70
65
  response["REQUEST_METHOD"].should.equal "POST"
@@ -75,36 +70,36 @@ context "Rack::Handler::Mongrel" do
75
70
  response["test.postdata"].should.equal "rack-form-data=23"
76
71
  end
77
72
 
78
- specify "should support HTTP auth" do
73
+ should "support HTTP auth" do
79
74
  GET("/test", {:user => "ruth", :passwd => "secret"})
80
75
  response["HTTP_AUTHORIZATION"].should.equal "Basic cnV0aDpzZWNyZXQ="
81
76
  end
82
77
 
83
- specify "should set status" do
78
+ should "set status" do
84
79
  GET("/test?secret")
85
80
  status.should.equal 403
86
81
  response["rack.url_scheme"].should.equal "http"
87
82
  end
88
83
 
89
- specify "should provide a .run" do
84
+ should "provide a .run" do
90
85
  block_ran = false
91
86
  Thread.new {
92
- Rack::Handler::Mongrel.run(lambda {}, {:Port => 9211}) { |server|
87
+ Rack::Handler::Mongrel.run(lambda {}, {:Host => '127.0.0.1', :Port => 9211}) { |server|
93
88
  server.should.be.kind_of Mongrel::HttpServer
94
89
  block_ran = true
95
90
  }
96
91
  }
97
92
  sleep 1
98
- block_ran.should.be true
93
+ block_ran.should.be.true
99
94
  end
100
95
 
101
- specify "should provide a .run that maps a hash" do
96
+ should "provide a .run that maps a hash" do
102
97
  block_ran = false
103
98
  Thread.new {
104
99
  map = {'/'=>lambda{},'/foo'=>lambda{}}
105
- Rack::Handler::Mongrel.run(map, :map => true, :Port => 9221) { |server|
100
+ Rack::Handler::Mongrel.run(map, :map => true, :Host => '127.0.0.1', :Port => 9221) { |server|
106
101
  server.should.be.kind_of Mongrel::HttpServer
107
- server.classifier.uris.size.should.be 2
102
+ server.classifier.uris.size.should.equal 2
108
103
  server.classifier.uris.should.not.include '/arf'
109
104
  server.classifier.uris.should.include '/'
110
105
  server.classifier.uris.should.include '/foo'
@@ -112,16 +107,16 @@ context "Rack::Handler::Mongrel" do
112
107
  }
113
108
  }
114
109
  sleep 1
115
- block_ran.should.be true
110
+ block_ran.should.be.true
116
111
  end
117
112
 
118
- specify "should provide a .run that maps a urlmap" do
113
+ should "provide a .run that maps a urlmap" do
119
114
  block_ran = false
120
115
  Thread.new {
121
116
  map = Rack::URLMap.new({'/'=>lambda{},'/bar'=>lambda{}})
122
- Rack::Handler::Mongrel.run(map, {:map => true, :Port => 9231}) { |server|
117
+ Rack::Handler::Mongrel.run(map, {:map => true, :Host => '127.0.0.1', :Port => 9231}) { |server|
123
118
  server.should.be.kind_of Mongrel::HttpServer
124
- server.classifier.uris.size.should.be 2
119
+ server.classifier.uris.size.should.equal 2
125
120
  server.classifier.uris.should.not.include '/arf'
126
121
  server.classifier.uris.should.include '/'
127
122
  server.classifier.uris.should.include '/bar'
@@ -129,41 +124,41 @@ context "Rack::Handler::Mongrel" do
129
124
  }
130
125
  }
131
126
  sleep 1
132
- block_ran.should.be true
127
+ block_ran.should.be.true
133
128
  end
134
129
 
135
- specify "should provide a .run that maps a urlmap restricting by host" do
130
+ should "provide a .run that maps a urlmap restricting by host" do
136
131
  block_ran = false
137
132
  Thread.new {
138
133
  map = Rack::URLMap.new({
139
134
  '/' => lambda{},
140
135
  '/foo' => lambda{},
141
136
  '/bar' => lambda{},
142
- 'http://localhost/' => lambda{},
143
- 'http://localhost/bar' => lambda{},
137
+ 'http://127.0.0.1/' => lambda{},
138
+ 'http://127.0.0.1/bar' => lambda{},
144
139
  'http://falsehost/arf' => lambda{},
145
140
  'http://falsehost/qux' => lambda{}
146
141
  })
147
- opt = {:map => true, :Port => 9241, :Host => 'localhost'}
142
+ opt = {:map => true, :Port => 9241, :Host => '127.0.0.1'}
148
143
  Rack::Handler::Mongrel.run(map, opt) { |server|
149
144
  server.should.be.kind_of Mongrel::HttpServer
150
145
  server.classifier.uris.should.include '/'
151
- server.classifier.handler_map['/'].size.should.be 2
146
+ server.classifier.handler_map['/'].size.should.equal 2
152
147
  server.classifier.uris.should.include '/foo'
153
- server.classifier.handler_map['/foo'].size.should.be 1
148
+ server.classifier.handler_map['/foo'].size.should.equal 1
154
149
  server.classifier.uris.should.include '/bar'
155
- server.classifier.handler_map['/bar'].size.should.be 2
150
+ server.classifier.handler_map['/bar'].size.should.equal 2
156
151
  server.classifier.uris.should.not.include '/qux'
157
152
  server.classifier.uris.should.not.include '/arf'
158
- server.classifier.uris.size.should.be 3
153
+ server.classifier.uris.size.should.equal 3
159
154
  block_ran = true
160
155
  }
161
156
  }
162
157
  sleep 1
163
- block_ran.should.be true
158
+ block_ran.should.be.true
164
159
  end
165
160
 
166
- specify "should stream #each part of the response" do
161
+ should "stream #each part of the response" do
167
162
  body = ''
168
163
  begin
169
164
  Timeout.timeout(1) do
@@ -179,11 +174,9 @@ context "Rack::Handler::Mongrel" do
179
174
  body.should.not.be.empty
180
175
  end
181
176
 
182
- teardown do
183
- @acc.raise Mongrel::StopServer
184
- end
177
+ @acc.raise Mongrel::StopServer
185
178
  end
186
179
 
187
180
  rescue LoadError
188
- $stderr.puts "Skipping Rack::Handler::Mongrel tests (Mongrel is required). `gem install mongrel` and try again."
181
+ warn "Skipping Rack::Handler::Mongrel tests (Mongrel is required). `gem install mongrel` and try again."
189
182
  end