rack 2.0.9.3 → 2.1.4.3
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +92 -0
- data/{COPYING → MIT-LICENSE} +4 -2
- data/README.rdoc +76 -116
- data/Rakefile +25 -18
- data/SPEC +9 -9
- data/bin/rackup +1 -0
- data/example/lobster.ru +2 -0
- data/example/protectedlobster.rb +3 -1
- data/example/protectedlobster.ru +2 -0
- data/lib/rack/auth/abstract/handler.rb +3 -1
- data/lib/rack/auth/abstract/request.rb +2 -0
- data/lib/rack/auth/basic.rb +4 -1
- data/lib/rack/auth/digest/md5.rb +9 -7
- data/lib/rack/auth/digest/nonce.rb +6 -3
- data/lib/rack/auth/digest/params.rb +4 -2
- data/lib/rack/auth/digest/request.rb +2 -0
- data/lib/rack/body_proxy.rb +3 -6
- data/lib/rack/builder.rb +39 -15
- data/lib/rack/cascade.rb +6 -5
- data/lib/rack/chunked.rb +29 -6
- data/lib/rack/common_logger.rb +9 -8
- data/lib/rack/conditional_get.rb +3 -1
- data/lib/rack/config.rb +2 -0
- data/lib/rack/content_length.rb +3 -1
- data/lib/rack/content_type.rb +3 -1
- data/lib/rack/core_ext/regexp.rb +14 -0
- data/lib/rack/deflater.rb +32 -17
- data/lib/rack/directory.rb +19 -16
- data/lib/rack/etag.rb +3 -1
- data/lib/rack/events.rb +5 -3
- data/lib/rack/file.rb +4 -173
- data/lib/rack/files.rb +178 -0
- data/lib/rack/handler/cgi.rb +3 -1
- data/lib/rack/handler/fastcgi.rb +4 -2
- data/lib/rack/handler/lsws.rb +3 -1
- data/lib/rack/handler/scgi.rb +9 -6
- data/lib/rack/handler/thin.rb +3 -1
- data/lib/rack/handler/webrick.rb +4 -2
- data/lib/rack/handler.rb +7 -2
- data/lib/rack/head.rb +2 -0
- data/lib/rack/lint.rb +14 -11
- data/lib/rack/lobster.rb +7 -5
- data/lib/rack/lock.rb +2 -0
- data/lib/rack/logger.rb +2 -0
- data/lib/rack/media_type.rb +10 -5
- data/lib/rack/method_override.rb +4 -2
- data/lib/rack/mime.rb +9 -1
- data/lib/rack/mock.rb +74 -15
- data/lib/rack/multipart/generator.rb +6 -7
- data/lib/rack/multipart/parser.rb +50 -45
- data/lib/rack/multipart/uploaded_file.rb +2 -0
- data/lib/rack/multipart.rb +3 -1
- data/lib/rack/null_logger.rb +2 -0
- data/lib/rack/query_parser.rb +51 -25
- data/lib/rack/recursive.rb +7 -5
- data/lib/rack/reloader.rb +10 -4
- data/lib/rack/request.rb +79 -26
- data/lib/rack/response.rb +71 -31
- data/lib/rack/rewindable_input.rb +4 -2
- data/lib/rack/runtime.rb +4 -2
- data/lib/rack/sendfile.rb +15 -8
- data/lib/rack/server.rb +88 -18
- data/lib/rack/session/abstract/id.rb +30 -20
- data/lib/rack/session/cookie.rb +10 -9
- data/lib/rack/session/memcache.rb +4 -93
- data/lib/rack/session/pool.rb +4 -2
- data/lib/rack/show_exceptions.rb +15 -9
- data/lib/rack/show_status.rb +4 -2
- data/lib/rack/static.rb +15 -10
- data/lib/rack/tempfile_reaper.rb +2 -0
- data/lib/rack/urlmap.rb +11 -2
- data/lib/rack/utils.rb +58 -71
- data/lib/rack.rb +63 -60
- data/rack.gemspec +17 -7
- metadata +28 -170
- data/HISTORY.md +0 -520
- data/test/builder/an_underscore_app.rb +0 -5
- data/test/builder/anything.rb +0 -5
- data/test/builder/comment.ru +0 -4
- data/test/builder/end.ru +0 -5
- data/test/builder/line.ru +0 -1
- data/test/builder/options.ru +0 -2
- data/test/cgi/assets/folder/test.js +0 -1
- data/test/cgi/assets/fonts/font.eot +0 -1
- data/test/cgi/assets/images/image.png +0 -1
- data/test/cgi/assets/index.html +0 -1
- data/test/cgi/assets/javascripts/app.js +0 -1
- data/test/cgi/assets/stylesheets/app.css +0 -1
- data/test/cgi/lighttpd.conf +0 -26
- data/test/cgi/rackup_stub.rb +0 -6
- data/test/cgi/sample_rackup.ru +0 -5
- data/test/cgi/test +0 -9
- data/test/cgi/test+directory/test+file +0 -1
- data/test/cgi/test.fcgi +0 -9
- data/test/cgi/test.gz +0 -0
- data/test/cgi/test.ru +0 -5
- data/test/gemloader.rb +0 -10
- data/test/helper.rb +0 -34
- data/test/multipart/bad_robots +0 -259
- data/test/multipart/binary +0 -0
- data/test/multipart/content_type_and_no_filename +0 -6
- data/test/multipart/empty +0 -10
- data/test/multipart/fail_16384_nofile +0 -814
- data/test/multipart/file1.txt +0 -1
- data/test/multipart/filename_and_modification_param +0 -7
- data/test/multipart/filename_and_no_name +0 -6
- data/test/multipart/filename_with_encoded_words +0 -7
- data/test/multipart/filename_with_escaped_quotes +0 -6
- data/test/multipart/filename_with_escaped_quotes_and_modification_param +0 -7
- data/test/multipart/filename_with_null_byte +0 -7
- data/test/multipart/filename_with_percent_escaped_quotes +0 -6
- data/test/multipart/filename_with_single_quote +0 -7
- data/test/multipart/filename_with_unescaped_percentages +0 -6
- data/test/multipart/filename_with_unescaped_percentages2 +0 -6
- data/test/multipart/filename_with_unescaped_percentages3 +0 -6
- data/test/multipart/filename_with_unescaped_quotes +0 -6
- data/test/multipart/ie +0 -6
- data/test/multipart/invalid_character +0 -6
- data/test/multipart/mixed_files +0 -21
- data/test/multipart/nested +0 -10
- data/test/multipart/none +0 -9
- data/test/multipart/quoted +0 -15
- data/test/multipart/rack-logo.png +0 -0
- data/test/multipart/semicolon +0 -6
- data/test/multipart/text +0 -15
- data/test/multipart/three_files_three_fields +0 -31
- data/test/multipart/unity3d_wwwform +0 -11
- data/test/multipart/webkit +0 -32
- data/test/rackup/config.ru +0 -31
- data/test/registering_handler/rack/handler/registering_myself.rb +0 -8
- data/test/spec_auth_basic.rb +0 -89
- data/test/spec_auth_digest.rb +0 -260
- data/test/spec_body_proxy.rb +0 -85
- data/test/spec_builder.rb +0 -233
- data/test/spec_cascade.rb +0 -63
- data/test/spec_cgi.rb +0 -84
- data/test/spec_chunked.rb +0 -103
- data/test/spec_common_logger.rb +0 -107
- data/test/spec_conditional_get.rb +0 -103
- data/test/spec_config.rb +0 -23
- data/test/spec_content_length.rb +0 -86
- data/test/spec_content_type.rb +0 -46
- data/test/spec_deflater.rb +0 -375
- data/test/spec_directory.rb +0 -148
- data/test/spec_etag.rb +0 -108
- data/test/spec_events.rb +0 -133
- data/test/spec_fastcgi.rb +0 -85
- data/test/spec_file.rb +0 -264
- data/test/spec_handler.rb +0 -57
- data/test/spec_head.rb +0 -46
- data/test/spec_lint.rb +0 -520
- data/test/spec_lobster.rb +0 -59
- data/test/spec_lock.rb +0 -204
- data/test/spec_logger.rb +0 -24
- data/test/spec_media_type.rb +0 -42
- data/test/spec_method_override.rb +0 -110
- data/test/spec_mime.rb +0 -51
- data/test/spec_mock.rb +0 -359
- data/test/spec_multipart.rb +0 -721
- data/test/spec_null_logger.rb +0 -21
- data/test/spec_recursive.rb +0 -75
- data/test/spec_request.rb +0 -1423
- data/test/spec_response.rb +0 -528
- data/test/spec_rewindable_input.rb +0 -128
- data/test/spec_runtime.rb +0 -50
- data/test/spec_sendfile.rb +0 -125
- data/test/spec_server.rb +0 -193
- data/test/spec_session_abstract_id.rb +0 -31
- data/test/spec_session_abstract_session_hash.rb +0 -45
- data/test/spec_session_cookie.rb +0 -442
- data/test/spec_session_memcache.rb +0 -357
- data/test/spec_session_persisted_secure_secure_session_hash.rb +0 -73
- data/test/spec_session_pool.rb +0 -247
- data/test/spec_show_exceptions.rb +0 -93
- data/test/spec_show_status.rb +0 -104
- data/test/spec_static.rb +0 -184
- data/test/spec_tempfile_reaper.rb +0 -64
- data/test/spec_thin.rb +0 -96
- data/test/spec_urlmap.rb +0 -237
- data/test/spec_utils.rb +0 -742
- data/test/spec_version.rb +0 -11
- data/test/spec_webrick.rb +0 -206
- data/test/static/another/index.html +0 -1
- data/test/static/foo.html +0 -1
- data/test/static/index.html +0 -1
- data/test/testrequest.rb +0 -78
- data/test/unregistered_handler/rack/handler/unregistered.rb +0 -7
- data/test/unregistered_handler/rack/handler/unregistered_long_one.rb +0 -7
data/test/spec_mock.rb
DELETED
@@ -1,359 +0,0 @@
|
|
1
|
-
require 'minitest/autorun'
|
2
|
-
require 'yaml'
|
3
|
-
require 'rack/lint'
|
4
|
-
require 'rack/mock'
|
5
|
-
require 'stringio'
|
6
|
-
|
7
|
-
app = Rack::Lint.new(lambda { |env|
|
8
|
-
req = Rack::Request.new(env)
|
9
|
-
|
10
|
-
env["mock.postdata"] = env["rack.input"].read
|
11
|
-
if req.GET["error"]
|
12
|
-
env["rack.errors"].puts req.GET["error"]
|
13
|
-
env["rack.errors"].flush
|
14
|
-
end
|
15
|
-
|
16
|
-
body = req.head? ? "" : env.to_yaml
|
17
|
-
Rack::Response.new(body,
|
18
|
-
req.GET["status"] || 200,
|
19
|
-
"Content-Type" => "text/yaml").finish
|
20
|
-
})
|
21
|
-
|
22
|
-
describe Rack::MockRequest do
|
23
|
-
it "return a MockResponse" do
|
24
|
-
res = Rack::MockRequest.new(app).get("")
|
25
|
-
res.must_be_kind_of Rack::MockResponse
|
26
|
-
end
|
27
|
-
|
28
|
-
it "be able to only return the environment" do
|
29
|
-
env = Rack::MockRequest.env_for("")
|
30
|
-
env.must_be_kind_of Hash
|
31
|
-
env.must_include "rack.version"
|
32
|
-
end
|
33
|
-
|
34
|
-
it "return an environment with a path" do
|
35
|
-
env = Rack::MockRequest.env_for("http://www.example.com/parse?location[]=1&location[]=2&age_group[]=2")
|
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"
|
40
|
-
end
|
41
|
-
|
42
|
-
it "provide sensible defaults" do
|
43
|
-
res = Rack::MockRequest.new(app).request
|
44
|
-
|
45
|
-
env = YAML.load(res.body)
|
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?
|
54
|
-
end
|
55
|
-
|
56
|
-
it "allow GET/POST/PUT/DELETE/HEAD" do
|
57
|
-
res = Rack::MockRequest.new(app).get("", :input => "foo")
|
58
|
-
env = YAML.load(res.body)
|
59
|
-
env["REQUEST_METHOD"].must_equal "GET"
|
60
|
-
|
61
|
-
res = Rack::MockRequest.new(app).post("", :input => "foo")
|
62
|
-
env = YAML.load(res.body)
|
63
|
-
env["REQUEST_METHOD"].must_equal "POST"
|
64
|
-
|
65
|
-
res = Rack::MockRequest.new(app).put("", :input => "foo")
|
66
|
-
env = YAML.load(res.body)
|
67
|
-
env["REQUEST_METHOD"].must_equal "PUT"
|
68
|
-
|
69
|
-
res = Rack::MockRequest.new(app).patch("", :input => "foo")
|
70
|
-
env = YAML.load(res.body)
|
71
|
-
env["REQUEST_METHOD"].must_equal "PATCH"
|
72
|
-
|
73
|
-
res = Rack::MockRequest.new(app).delete("", :input => "foo")
|
74
|
-
env = YAML.load(res.body)
|
75
|
-
env["REQUEST_METHOD"].must_equal "DELETE"
|
76
|
-
|
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"
|
82
|
-
end
|
83
|
-
|
84
|
-
it "set content length" do
|
85
|
-
env = Rack::MockRequest.env_for("/", :input => "foo")
|
86
|
-
env["CONTENT_LENGTH"].must_equal "3"
|
87
|
-
end
|
88
|
-
|
89
|
-
it "allow posting" do
|
90
|
-
res = Rack::MockRequest.new(app).get("", :input => "foo")
|
91
|
-
env = YAML.load(res.body)
|
92
|
-
env["mock.postdata"].must_equal "foo"
|
93
|
-
|
94
|
-
res = Rack::MockRequest.new(app).post("", :input => StringIO.new("foo"))
|
95
|
-
env = YAML.load(res.body)
|
96
|
-
env["mock.postdata"].must_equal "foo"
|
97
|
-
end
|
98
|
-
|
99
|
-
it "use all parts of an URL" do
|
100
|
-
res = Rack::MockRequest.new(app).
|
101
|
-
get("https://bla.example.org:9292/meh/foo?bar")
|
102
|
-
res.must_be_kind_of Rack::MockResponse
|
103
|
-
|
104
|
-
env = YAML.load(res.body)
|
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"
|
111
|
-
end
|
112
|
-
|
113
|
-
it "set SSL port and HTTP flag on when using https" do
|
114
|
-
res = Rack::MockRequest.new(app).
|
115
|
-
get("https://example.org/foo")
|
116
|
-
res.must_be_kind_of Rack::MockResponse
|
117
|
-
|
118
|
-
env = YAML.load(res.body)
|
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"
|
126
|
-
end
|
127
|
-
|
128
|
-
it "prepend slash to uri path" do
|
129
|
-
res = Rack::MockRequest.new(app).
|
130
|
-
get("foo")
|
131
|
-
res.must_be_kind_of Rack::MockResponse
|
132
|
-
|
133
|
-
env = YAML.load(res.body)
|
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"
|
140
|
-
end
|
141
|
-
|
142
|
-
it "properly convert method name to an uppercase string" do
|
143
|
-
res = Rack::MockRequest.new(app).request(:get)
|
144
|
-
env = YAML.load(res.body)
|
145
|
-
env["REQUEST_METHOD"].must_equal "GET"
|
146
|
-
end
|
147
|
-
|
148
|
-
it "accept params and build query string for GET requests" do
|
149
|
-
res = Rack::MockRequest.new(app).get("/foo?baz=2", :params => {:foo => {:bar => "1"}})
|
150
|
-
env = YAML.load(res.body)
|
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 ""
|
156
|
-
end
|
157
|
-
|
158
|
-
it "accept raw input in params for GET requests" do
|
159
|
-
res = Rack::MockRequest.new(app).get("/foo?baz=2", :params => "foo[bar]=1")
|
160
|
-
env = YAML.load(res.body)
|
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 ""
|
166
|
-
end
|
167
|
-
|
168
|
-
it "accept params and build url encoded params for POST requests" do
|
169
|
-
res = Rack::MockRequest.new(app).post("/foo", :params => {:foo => {:bar => "1"}})
|
170
|
-
env = YAML.load(res.body)
|
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"
|
176
|
-
end
|
177
|
-
|
178
|
-
it "accept raw input in params for POST requests" do
|
179
|
-
res = Rack::MockRequest.new(app).post("/foo", :params => "foo[bar]=1")
|
180
|
-
env = YAML.load(res.body)
|
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"
|
186
|
-
end
|
187
|
-
|
188
|
-
it "accept params and build multipart encoded params for POST requests" do
|
189
|
-
files = Rack::Multipart::UploadedFile.new(File.join(File.dirname(__FILE__), "multipart", "file1.txt"))
|
190
|
-
res = Rack::MockRequest.new(app).post("/foo", :params => { "submit-name" => "Larry", "files" => files })
|
191
|
-
env = YAML.load(res.body)
|
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"
|
196
|
-
# The gsub accounts for differences in YAMLs affect on the data.
|
197
|
-
env["mock.postdata"].gsub("\r", "").length.must_equal 206
|
198
|
-
end
|
199
|
-
|
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
|
-
end
|
205
|
-
|
206
|
-
it "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.must_equal false
|
211
|
-
Rack::MockRequest.new(capp).get('/', :lint => true)
|
212
|
-
called.must_equal true
|
213
|
-
end
|
214
|
-
|
215
|
-
it "defaults encoding to ASCII 8BIT" do
|
216
|
-
req = Rack::MockRequest.env_for("/foo")
|
217
|
-
|
218
|
-
keys = [
|
219
|
-
Rack::REQUEST_METHOD,
|
220
|
-
Rack::SERVER_NAME,
|
221
|
-
Rack::SERVER_PORT,
|
222
|
-
Rack::QUERY_STRING,
|
223
|
-
Rack::PATH_INFO,
|
224
|
-
Rack::HTTPS,
|
225
|
-
Rack::RACK_URL_SCHEME
|
226
|
-
]
|
227
|
-
keys.each do |k|
|
228
|
-
assert_equal Encoding::ASCII_8BIT, req[k].encoding
|
229
|
-
end
|
230
|
-
end
|
231
|
-
end
|
232
|
-
|
233
|
-
describe Rack::MockResponse do
|
234
|
-
it "provide access to the HTTP status" do
|
235
|
-
res = Rack::MockRequest.new(app).get("")
|
236
|
-
res.must_be :successful?
|
237
|
-
res.must_be :ok?
|
238
|
-
|
239
|
-
res = Rack::MockRequest.new(app).get("/?status=404")
|
240
|
-
res.wont_be :successful?
|
241
|
-
res.must_be :client_error?
|
242
|
-
res.must_be :not_found?
|
243
|
-
|
244
|
-
res = Rack::MockRequest.new(app).get("/?status=501")
|
245
|
-
res.wont_be :successful?
|
246
|
-
res.must_be :server_error?
|
247
|
-
|
248
|
-
res = Rack::MockRequest.new(app).get("/?status=307")
|
249
|
-
res.must_be :redirect?
|
250
|
-
|
251
|
-
res = Rack::MockRequest.new(app).get("/?status=201", :lint => true)
|
252
|
-
res.must_be :empty?
|
253
|
-
end
|
254
|
-
|
255
|
-
it "provide access to the HTTP headers" do
|
256
|
-
res = Rack::MockRequest.new(app).get("")
|
257
|
-
res.must_include "Content-Type"
|
258
|
-
res.headers["Content-Type"].must_equal "text/yaml"
|
259
|
-
res.original_headers["Content-Type"].must_equal "text/yaml"
|
260
|
-
res["Content-Type"].must_equal "text/yaml"
|
261
|
-
res.content_type.must_equal "text/yaml"
|
262
|
-
res.content_length.wont_equal 0
|
263
|
-
res.location.must_be_nil
|
264
|
-
end
|
265
|
-
|
266
|
-
it "provide access to the HTTP body" do
|
267
|
-
res = Rack::MockRequest.new(app).get("")
|
268
|
-
res.body.must_match(/rack/)
|
269
|
-
assert_match(res, /rack/)
|
270
|
-
end
|
271
|
-
|
272
|
-
it "provide access to the Rack errors" do
|
273
|
-
res = Rack::MockRequest.new(app).get("/?error=foo", :lint => true)
|
274
|
-
res.must_be :ok?
|
275
|
-
res.errors.wont_be :empty?
|
276
|
-
res.errors.must_include "foo"
|
277
|
-
end
|
278
|
-
|
279
|
-
it "allow calling body.close afterwards" do
|
280
|
-
# this is exactly what rack-test does
|
281
|
-
body = StringIO.new("hi")
|
282
|
-
res = Rack::MockResponse.new(200, {}, body)
|
283
|
-
body.close if body.respond_to?(:close)
|
284
|
-
res.body.must_equal 'hi'
|
285
|
-
end
|
286
|
-
|
287
|
-
it "optionally make Rack errors fatal" do
|
288
|
-
lambda {
|
289
|
-
Rack::MockRequest.new(app).get("/?error=foo", :fatal => true)
|
290
|
-
}.must_raise Rack::MockRequest::FatalWarning
|
291
|
-
end
|
292
|
-
end
|
293
|
-
|
294
|
-
describe Rack::MockResponse, 'headers' do
|
295
|
-
before do
|
296
|
-
@res = Rack::MockRequest.new(app).get('')
|
297
|
-
@res.set_header 'FOO', '1'
|
298
|
-
end
|
299
|
-
|
300
|
-
it 'has_header?' do
|
301
|
-
lambda { @res.has_header? nil }.must_raise NoMethodError
|
302
|
-
|
303
|
-
@res.has_header?('FOO').must_equal true
|
304
|
-
@res.has_header?('Foo').must_equal true
|
305
|
-
end
|
306
|
-
|
307
|
-
it 'get_header' do
|
308
|
-
lambda { @res.get_header nil }.must_raise NoMethodError
|
309
|
-
|
310
|
-
@res.get_header('FOO').must_equal '1'
|
311
|
-
@res.get_header('Foo').must_equal '1'
|
312
|
-
end
|
313
|
-
|
314
|
-
it 'set_header' do
|
315
|
-
lambda { @res.set_header nil, '1' }.must_raise NoMethodError
|
316
|
-
|
317
|
-
@res.set_header('FOO', '2').must_equal '2'
|
318
|
-
@res.get_header('FOO').must_equal '2'
|
319
|
-
|
320
|
-
@res.set_header('Foo', '3').must_equal '3'
|
321
|
-
@res.get_header('Foo').must_equal '3'
|
322
|
-
@res.get_header('FOO').must_equal '3'
|
323
|
-
|
324
|
-
@res.set_header('FOO', nil).must_be_nil
|
325
|
-
@res.get_header('FOO').must_be_nil
|
326
|
-
@res.has_header?('FOO').must_equal true
|
327
|
-
end
|
328
|
-
|
329
|
-
it 'add_header' do
|
330
|
-
lambda { @res.add_header nil, '1' }.must_raise NoMethodError
|
331
|
-
|
332
|
-
# Sets header on first addition
|
333
|
-
@res.add_header('FOO', '1').must_equal '1,1'
|
334
|
-
@res.get_header('FOO').must_equal '1,1'
|
335
|
-
|
336
|
-
# Ignores nil additions
|
337
|
-
@res.add_header('FOO', nil).must_equal '1,1'
|
338
|
-
@res.get_header('FOO').must_equal '1,1'
|
339
|
-
|
340
|
-
# Converts additions to strings
|
341
|
-
@res.add_header('FOO', 2).must_equal '1,1,2'
|
342
|
-
@res.get_header('FOO').must_equal '1,1,2'
|
343
|
-
|
344
|
-
# Respects underlying case-sensitivity
|
345
|
-
@res.add_header('Foo', 'yep').must_equal '1,1,2,yep'
|
346
|
-
@res.get_header('Foo').must_equal '1,1,2,yep'
|
347
|
-
@res.get_header('FOO').must_equal '1,1,2,yep'
|
348
|
-
end
|
349
|
-
|
350
|
-
it 'delete_header' do
|
351
|
-
lambda { @res.delete_header nil }.must_raise NoMethodError
|
352
|
-
|
353
|
-
@res.delete_header('FOO').must_equal '1'
|
354
|
-
@res.has_header?('FOO').must_equal false
|
355
|
-
|
356
|
-
@res.has_header?('Foo').must_equal false
|
357
|
-
@res.delete_header('Foo').must_be_nil
|
358
|
-
end
|
359
|
-
end
|