rack 1.1.0 → 1.2.0
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.
- data/README +23 -26
- data/SPEC +3 -3
- data/lib/rack/auth/digest/params.rb +1 -1
- data/lib/rack/content_length.rb +1 -1
- data/lib/rack/etag.rb +15 -6
- data/lib/rack/file.rb +3 -1
- data/lib/rack/handler/cgi.rb +8 -7
- data/lib/rack/handler/fastcgi.rb +1 -1
- data/lib/rack/handler/lsws.rb +1 -1
- data/lib/rack/handler/mongrel.rb +1 -1
- data/lib/rack/handler/scgi.rb +1 -4
- data/lib/rack/handler/webrick.rb +10 -6
- data/lib/rack/lint.rb +29 -37
- data/lib/rack/mime.rb +2 -0
- data/lib/rack/mock.rb +2 -1
- data/lib/rack/recursive.rb +4 -0
- data/lib/rack/request.rb +8 -6
- data/lib/rack/response.rb +1 -0
- data/lib/rack/rewindable_input.rb +13 -10
- data/lib/rack/sendfile.rb +8 -6
- data/lib/rack/server.rb +66 -7
- data/lib/rack/session/memcache.rb +1 -1
- data/lib/rack/urlmap.rb +6 -7
- data/lib/rack/utils.rb +64 -22
- data/lib/rack.rb +1 -12
- data/rack.gemspec +6 -6
- data/spec/cgi/lighttpd.conf +25 -0
- data/spec/cgi/rackup_stub.rb +6 -0
- data/spec/cgi/sample_rackup.ru +5 -0
- data/spec/cgi/test +9 -0
- data/spec/cgi/test.fcgi +8 -0
- data/spec/cgi/test.ru +5 -0
- data/spec/multipart/bad_robots +259 -0
- data/spec/multipart/binary +0 -0
- data/spec/multipart/empty +10 -0
- data/spec/multipart/fail_16384_nofile +814 -0
- data/spec/multipart/file1.txt +1 -0
- data/spec/multipart/filename_and_modification_param +7 -0
- data/spec/multipart/filename_with_escaped_quotes +6 -0
- data/spec/multipart/filename_with_escaped_quotes_and_modification_param +7 -0
- data/spec/multipart/filename_with_percent_escaped_quotes +6 -0
- data/spec/multipart/filename_with_unescaped_quotes +6 -0
- data/spec/multipart/ie +6 -0
- data/spec/multipart/nested +10 -0
- data/spec/multipart/none +9 -0
- data/spec/multipart/semicolon +6 -0
- data/spec/multipart/text +10 -0
- data/spec/rackup/config.ru +31 -0
- data/{test/spec_rack_auth_basic.rb → spec/spec_auth_basic.rb} +11 -14
- data/{test/spec_rack_auth_digest.rb → spec/spec_auth_digest.rb} +18 -21
- data/{test/spec_rack_builder.rb → spec/spec_builder.rb} +49 -10
- data/{test/spec_rack_cascade.rb → spec/spec_cascade.rb} +7 -10
- data/{test/spec_rack_cgi.rb → spec/spec_cgi.rb} +34 -32
- data/{test/spec_rack_chunked.rb → spec/spec_chunked.rb} +8 -10
- data/{test/spec_rack_commonlogger.rb → spec/spec_commonlogger.rb} +10 -15
- data/{test/spec_rack_conditionalget.rb → spec/spec_conditionalget.rb} +5 -7
- data/{test/spec_rack_config.rb → spec/spec_config.rb} +6 -7
- data/{test/spec_rack_content_length.rb → spec/spec_content_length.rb} +7 -8
- data/{test/spec_rack_content_type.rb → spec/spec_content_type.rb} +5 -6
- data/{test/spec_rack_deflater.rb → spec/spec_deflater.rb} +11 -13
- data/{test/spec_rack_directory.rb → spec/spec_directory.rb} +6 -10
- data/{test/spec_rack_etag.rb → spec/spec_etag.rb} +3 -5
- data/{test/spec_rack_fastcgi.rb → spec/spec_fastcgi.rb} +36 -29
- data/{test/spec_rack_file.rb → spec/spec_file.rb} +9 -13
- data/{test/spec_rack_handler.rb → spec/spec_handler.rb} +10 -12
- data/{test/spec_rack_head.rb → spec/spec_head.rb} +3 -3
- data/{test/spec_rack_lint.rb → spec/spec_lint.rb} +19 -32
- data/{test/spec_rack_lobster.rb → spec/spec_lobster.rb} +9 -11
- data/{test/spec_rack_lock.rb → spec/spec_lock.rb} +15 -17
- data/{test/spec_rack_logger.rb → spec/spec_logger.rb} +6 -7
- data/{test/spec_rack_methodoverride.rb → spec/spec_methodoverride.rb} +15 -17
- data/{test/spec_rack_mock.rb → spec/spec_mock.rb} +30 -32
- data/{test/spec_rack_mongrel.rb → spec/spec_mongrel.rb} +40 -46
- data/{test/spec_rack_nulllogger.rb → spec/spec_nulllogger.rb} +4 -5
- data/{test/spec_rack_recursive.rb → spec/spec_recursive.rb} +28 -36
- data/{test/spec_rack_request.rb → spec/spec_request.rb} +84 -49
- data/{test/spec_rack_response.rb → spec/spec_response.rb} +48 -29
- data/spec/spec_rewindable_input.rb +118 -0
- data/{test/spec_rack_runtime.rb → spec/spec_runtime.rb} +15 -11
- data/{test/spec_rack_sendfile.rb → spec/spec_sendfile.rb} +11 -14
- data/{test/spec_rack_session_cookie.rb → spec/spec_session_cookie.rb} +15 -18
- data/{test/spec_rack_session_memcache.rb → spec/spec_session_memcache.rb} +32 -26
- data/{test/spec_rack_session_pool.rb → spec/spec_session_pool.rb} +36 -31
- data/spec/spec_showexceptions.rb +23 -0
- data/spec/spec_showstatus.rb +79 -0
- data/{test/spec_rack_static.rb → spec/spec_static.rb} +5 -9
- data/{test/spec_rack_thin.rb → spec/spec_thin.rb} +30 -35
- data/{test/spec_rack_urlmap.rb → spec/spec_urlmap.rb} +6 -8
- data/{test/spec_rack_utils.rb → spec/spec_utils.rb} +136 -71
- data/{test/spec_rack_webrick.rb → spec/spec_webrick.rb} +28 -36
- data/spec/testrequest.rb +77 -0
- data/spec/unregistered_handler/rack/handler/unregistered.rb +7 -0
- data/spec/unregistered_handler/rack/handler/unregistered_long_one.rb +7 -0
- metadata +206 -124
- data/RDOX +0 -0
- data/lib/rack/adapter/camping.rb +0 -22
- data/test/spec_rack_camping.rb +0 -51
- data/test/spec_rack_rewindable_input.rb +0 -118
- data/test/spec_rack_showexceptions.rb +0 -21
- data/test/spec_rack_showstatus.rb +0 -72
- data/test/spec_rackup.rb +0 -154
|
@@ -1,15 +1,13 @@
|
|
|
1
|
-
require 'test/spec'
|
|
2
1
|
require 'stringio'
|
|
3
|
-
|
|
4
2
|
require 'rack/lint'
|
|
5
3
|
require 'rack/mock'
|
|
6
4
|
|
|
7
|
-
|
|
5
|
+
describe Rack::Lint do
|
|
8
6
|
def env(*args)
|
|
9
7
|
Rack::MockRequest.env_for("/", *args)
|
|
10
8
|
end
|
|
11
9
|
|
|
12
|
-
|
|
10
|
+
should "pass valid request" do
|
|
13
11
|
lambda {
|
|
14
12
|
Rack::Lint.new(lambda { |env|
|
|
15
13
|
[200, {"Content-type" => "test/plain", "Content-length" => "3"}, ["foo"]]
|
|
@@ -17,12 +15,12 @@ context "Rack::Lint" do
|
|
|
17
15
|
}.should.not.raise
|
|
18
16
|
end
|
|
19
17
|
|
|
20
|
-
|
|
18
|
+
should "notice fatal errors" do
|
|
21
19
|
lambda { Rack::Lint.new(nil).call }.should.raise(Rack::Lint::LintError).
|
|
22
20
|
message.should.match(/No env given/)
|
|
23
21
|
end
|
|
24
22
|
|
|
25
|
-
|
|
23
|
+
should "notice environment errors" do
|
|
26
24
|
lambda { Rack::Lint.new(nil).call 5 }.should.raise(Rack::Lint::LintError).
|
|
27
25
|
message.should.match(/not a Hash/)
|
|
28
26
|
|
|
@@ -110,7 +108,7 @@ context "Rack::Lint" do
|
|
|
110
108
|
message.should.match(/cannot be .* make it ''/)
|
|
111
109
|
end
|
|
112
110
|
|
|
113
|
-
|
|
111
|
+
should "notice input errors" do
|
|
114
112
|
lambda {
|
|
115
113
|
Rack::Lint.new(nil).call(env("rack.input" => ""))
|
|
116
114
|
}.should.raise(Rack::Lint::LintError).
|
|
@@ -139,14 +137,14 @@ context "Rack::Lint" do
|
|
|
139
137
|
message.should.match(/does not have ASCII-8BIT as its external encoding/)
|
|
140
138
|
end
|
|
141
139
|
|
|
142
|
-
|
|
140
|
+
should "notice error errors" do
|
|
143
141
|
lambda {
|
|
144
142
|
Rack::Lint.new(nil).call(env("rack.errors" => ""))
|
|
145
143
|
}.should.raise(Rack::Lint::LintError).
|
|
146
144
|
message.should.match(/does not respond to #puts/)
|
|
147
145
|
end
|
|
148
146
|
|
|
149
|
-
|
|
147
|
+
should "notice status errors" do
|
|
150
148
|
lambda {
|
|
151
149
|
Rack::Lint.new(lambda { |env|
|
|
152
150
|
["cc", {}, ""]
|
|
@@ -162,7 +160,7 @@ context "Rack::Lint" do
|
|
|
162
160
|
message.should.match(/must be >=100 seen as integer/)
|
|
163
161
|
end
|
|
164
162
|
|
|
165
|
-
|
|
163
|
+
should "notice header errors" do
|
|
166
164
|
lambda {
|
|
167
165
|
Rack::Lint.new(lambda { |env|
|
|
168
166
|
[200, Object.new, []]
|
|
@@ -235,7 +233,7 @@ context "Rack::Lint" do
|
|
|
235
233
|
}.should.not.raise(Rack::Lint::LintError)
|
|
236
234
|
end
|
|
237
235
|
|
|
238
|
-
|
|
236
|
+
should "notice content-type errors" do
|
|
239
237
|
lambda {
|
|
240
238
|
Rack::Lint.new(lambda { |env|
|
|
241
239
|
[200, {"Content-length" => "0"}, []]
|
|
@@ -253,7 +251,7 @@ context "Rack::Lint" do
|
|
|
253
251
|
end
|
|
254
252
|
end
|
|
255
253
|
|
|
256
|
-
|
|
254
|
+
should "notice content-length errors" do
|
|
257
255
|
[100, 101, 204, 304].each do |status|
|
|
258
256
|
lambda {
|
|
259
257
|
Rack::Lint.new(lambda { |env|
|
|
@@ -266,12 +264,12 @@ context "Rack::Lint" do
|
|
|
266
264
|
lambda {
|
|
267
265
|
Rack::Lint.new(lambda { |env|
|
|
268
266
|
[200, {"Content-type" => "text/plain", "Content-Length" => "1"}, []]
|
|
269
|
-
}).call(env({}))
|
|
267
|
+
}).call(env({}))[2].each { }
|
|
270
268
|
}.should.raise(Rack::Lint::LintError).
|
|
271
269
|
message.should.match(/Content-Length header was 1, but should be 0/)
|
|
272
270
|
end
|
|
273
271
|
|
|
274
|
-
|
|
272
|
+
should "notice body errors" do
|
|
275
273
|
lambda {
|
|
276
274
|
status, header, body = Rack::Lint.new(lambda { |env|
|
|
277
275
|
[200, {"Content-type" => "text/plain","Content-length" => "3"}, [1,2,3]]
|
|
@@ -281,7 +279,7 @@ context "Rack::Lint" do
|
|
|
281
279
|
message.should.match(/yielded non-string/)
|
|
282
280
|
end
|
|
283
281
|
|
|
284
|
-
|
|
282
|
+
should "notice input handling errors" do
|
|
285
283
|
lambda {
|
|
286
284
|
Rack::Lint.new(lambda { |env|
|
|
287
285
|
env["rack.input"].gets("\r\n")
|
|
@@ -425,7 +423,7 @@ context "Rack::Lint" do
|
|
|
425
423
|
message.should.match(/close must not be called/)
|
|
426
424
|
end
|
|
427
425
|
|
|
428
|
-
|
|
426
|
+
should "notice error handling errors" do
|
|
429
427
|
lambda {
|
|
430
428
|
Rack::Lint.new(lambda { |env|
|
|
431
429
|
env["rack.errors"].write(42)
|
|
@@ -443,7 +441,7 @@ context "Rack::Lint" do
|
|
|
443
441
|
message.should.match(/close must not be called/)
|
|
444
442
|
end
|
|
445
443
|
|
|
446
|
-
|
|
444
|
+
should "notice HEAD errors" do
|
|
447
445
|
lambda {
|
|
448
446
|
Rack::Lint.new(lambda { |env|
|
|
449
447
|
[200, {"Content-type" => "test/plain", "Content-length" => "3"}, []]
|
|
@@ -453,12 +451,12 @@ context "Rack::Lint" do
|
|
|
453
451
|
lambda {
|
|
454
452
|
Rack::Lint.new(lambda { |env|
|
|
455
453
|
[200, {"Content-type" => "test/plain", "Content-length" => "3"}, ["foo"]]
|
|
456
|
-
}).call(env({"REQUEST_METHOD" => "HEAD"}))
|
|
454
|
+
}).call(env({"REQUEST_METHOD" => "HEAD"}))[2].each { }
|
|
457
455
|
}.should.raise(Rack::Lint::LintError).
|
|
458
456
|
message.should.match(/body was given for HEAD/)
|
|
459
457
|
end
|
|
460
458
|
|
|
461
|
-
|
|
459
|
+
should "pass valid read calls" do
|
|
462
460
|
hello_str = "hello world"
|
|
463
461
|
hello_str.force_encoding("ASCII-8BIT") if hello_str.respond_to? :force_encoding
|
|
464
462
|
lambda {
|
|
@@ -505,19 +503,8 @@ context "Rack::Lint" do
|
|
|
505
503
|
end
|
|
506
504
|
end
|
|
507
505
|
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
class IOMock
|
|
511
|
-
def size
|
|
512
|
-
101
|
|
513
|
-
end
|
|
514
|
-
end
|
|
515
|
-
|
|
516
|
-
wrapper = Rack::Lint::InputWrapper.new(IOMock.new)
|
|
517
|
-
wrapper.size.should == 101
|
|
518
|
-
end
|
|
519
|
-
|
|
520
|
-
specify "delegates :rewind to underlying IO object" do
|
|
506
|
+
describe "Rack::Lint::InputWrapper" do
|
|
507
|
+
should "delegate :rewind to underlying IO object" do
|
|
521
508
|
io = StringIO.new("123")
|
|
522
509
|
wrapper = Rack::Lint::InputWrapper.new(io)
|
|
523
510
|
wrapper.read.should.equal "123"
|
|
@@ -1,29 +1,27 @@
|
|
|
1
|
-
require 'test/spec'
|
|
2
|
-
|
|
3
1
|
require 'rack/lobster'
|
|
4
2
|
require 'rack/mock'
|
|
5
3
|
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
describe Rack::Lobster::LambdaLobster do
|
|
5
|
+
should "be a single lambda" do
|
|
8
6
|
Rack::Lobster::LambdaLobster.should.be.kind_of Proc
|
|
9
7
|
end
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
|
|
9
|
+
should "look like a lobster" do
|
|
12
10
|
res = Rack::MockRequest.new(Rack::Lobster::LambdaLobster).get("/")
|
|
13
11
|
res.should.be.ok
|
|
14
12
|
res.body.should.include "(,(,,(,,,("
|
|
15
13
|
res.body.should.include "?flip"
|
|
16
14
|
end
|
|
17
15
|
|
|
18
|
-
|
|
16
|
+
should "be flippable" do
|
|
19
17
|
res = Rack::MockRequest.new(Rack::Lobster::LambdaLobster).get("/?flip")
|
|
20
18
|
res.should.be.ok
|
|
21
19
|
res.body.should.include "(,,,(,,(,("
|
|
22
20
|
end
|
|
23
21
|
end
|
|
24
22
|
|
|
25
|
-
|
|
26
|
-
|
|
23
|
+
describe Rack::Lobster do
|
|
24
|
+
should "look like a lobster" do
|
|
27
25
|
res = Rack::MockRequest.new(Rack::Lobster.new).get("/")
|
|
28
26
|
res.should.be.ok
|
|
29
27
|
res.body.should.include "(,(,,(,,,("
|
|
@@ -31,13 +29,13 @@ context "Rack::Lobster" do
|
|
|
31
29
|
res.body.should.include "crash"
|
|
32
30
|
end
|
|
33
31
|
|
|
34
|
-
|
|
32
|
+
should "be flippable" do
|
|
35
33
|
res = Rack::MockRequest.new(Rack::Lobster.new).get("/?flip=left")
|
|
36
34
|
res.should.be.ok
|
|
37
35
|
res.body.should.include "(,,,(,,(,("
|
|
38
36
|
end
|
|
39
37
|
|
|
40
|
-
|
|
38
|
+
should "provide crashing for testing purposes" do
|
|
41
39
|
lambda {
|
|
42
40
|
Rack::MockRequest.new(Rack::Lobster.new).get("/?flip=crash")
|
|
43
41
|
}.should.raise
|
|
@@ -1,37 +1,35 @@
|
|
|
1
|
-
require 'test/spec'
|
|
2
|
-
|
|
3
|
-
require 'rack/mock'
|
|
4
1
|
require 'rack/lock'
|
|
2
|
+
require 'rack/mock'
|
|
5
3
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
attr_reader :synchronized
|
|
4
|
+
class Lock
|
|
5
|
+
attr_reader :synchronized
|
|
9
6
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
7
|
+
def initialize
|
|
8
|
+
@synchronized = false
|
|
9
|
+
end
|
|
13
10
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
end
|
|
11
|
+
def synchronize
|
|
12
|
+
@synchronized = true
|
|
13
|
+
yield
|
|
18
14
|
end
|
|
15
|
+
end
|
|
19
16
|
|
|
20
|
-
|
|
17
|
+
describe Rack::Lock do
|
|
18
|
+
should "call synchronize on lock" do
|
|
21
19
|
lock = Lock.new
|
|
22
20
|
env = Rack::MockRequest.env_for("/")
|
|
23
|
-
app = Rack::Lock.new(lambda { |
|
|
21
|
+
app = Rack::Lock.new(lambda { |inner_env| }, lock)
|
|
24
22
|
lock.synchronized.should.equal false
|
|
25
23
|
app.call(env)
|
|
26
24
|
lock.synchronized.should.equal true
|
|
27
25
|
end
|
|
28
26
|
|
|
29
|
-
|
|
27
|
+
should "set multithread flag to false" do
|
|
30
28
|
app = Rack::Lock.new(lambda { |env| env['rack.multithread'] })
|
|
31
29
|
app.call(Rack::MockRequest.env_for("/")).should.equal false
|
|
32
30
|
end
|
|
33
31
|
|
|
34
|
-
|
|
32
|
+
should "reset original multithread flag when exiting lock" do
|
|
35
33
|
app = Rack::Lock.new(lambda { |env| env })
|
|
36
34
|
app.call(Rack::MockRequest.env_for("/"))['rack.multithread'].should.equal true
|
|
37
35
|
end
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
require 'rack/logger'
|
|
2
|
-
require 'rack/lint'
|
|
3
1
|
require 'stringio'
|
|
2
|
+
require 'rack/logger'
|
|
4
3
|
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
describe Rack::Logger do
|
|
5
|
+
should "log to rack.errors" do
|
|
7
6
|
app = lambda { |env|
|
|
8
7
|
log = env['rack.logger']
|
|
9
8
|
log.debug("Created logger")
|
|
@@ -14,8 +13,8 @@ context "Rack::Logger" do
|
|
|
14
13
|
}
|
|
15
14
|
|
|
16
15
|
errors = StringIO.new
|
|
17
|
-
Rack::Logger.new(app).call(
|
|
18
|
-
errors.string.should.match
|
|
19
|
-
errors.string.should.match
|
|
16
|
+
Rack::Logger.new(app).call('rack.errors' => errors)
|
|
17
|
+
errors.string.should.match(/INFO -- : Program started/)
|
|
18
|
+
errors.string.should.match(/WARN -- : Nothing to do/)
|
|
20
19
|
end
|
|
21
20
|
end
|
|
@@ -1,58 +1,56 @@
|
|
|
1
|
-
require 'test/spec'
|
|
2
|
-
|
|
3
|
-
require 'rack/mock'
|
|
4
|
-
require 'rack/methodoverride'
|
|
5
1
|
require 'stringio'
|
|
2
|
+
require 'rack/methodoverride'
|
|
3
|
+
require 'rack/mock'
|
|
6
4
|
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
describe Rack::MethodOverride do
|
|
6
|
+
should "not affect GET requests" do
|
|
9
7
|
env = Rack::MockRequest.env_for("/?_method=delete", :method => "GET")
|
|
10
|
-
app = Rack::MethodOverride.new(lambda
|
|
8
|
+
app = Rack::MethodOverride.new(lambda{|envx| Rack::Request.new(envx) })
|
|
11
9
|
req = app.call(env)
|
|
12
10
|
|
|
13
11
|
req.env["REQUEST_METHOD"].should.equal "GET"
|
|
14
12
|
end
|
|
15
13
|
|
|
16
|
-
|
|
14
|
+
should "modify REQUEST_METHOD for POST requests when _method parameter is set" do
|
|
17
15
|
env = Rack::MockRequest.env_for("/", :method => "POST", :input => "_method=put")
|
|
18
|
-
app = Rack::MethodOverride.new(lambda
|
|
16
|
+
app = Rack::MethodOverride.new(lambda{|envx| Rack::Request.new(envx) })
|
|
19
17
|
req = app.call(env)
|
|
20
18
|
|
|
21
19
|
req.env["REQUEST_METHOD"].should.equal "PUT"
|
|
22
20
|
end
|
|
23
21
|
|
|
24
|
-
|
|
22
|
+
should "modify REQUEST_METHOD for POST requests when X-HTTP-Method-Override is set" do
|
|
25
23
|
env = Rack::MockRequest.env_for("/",
|
|
26
24
|
:method => "POST",
|
|
27
25
|
"HTTP_X_HTTP_METHOD_OVERRIDE" => "PUT"
|
|
28
26
|
)
|
|
29
|
-
app = Rack::MethodOverride.new(lambda
|
|
27
|
+
app = Rack::MethodOverride.new(lambda{|envx| Rack::Request.new(envx) })
|
|
30
28
|
req = app.call(env)
|
|
31
29
|
|
|
32
30
|
req.env["REQUEST_METHOD"].should.equal "PUT"
|
|
33
31
|
end
|
|
34
32
|
|
|
35
|
-
|
|
33
|
+
should "not modify REQUEST_METHOD if the method is unknown" do
|
|
36
34
|
env = Rack::MockRequest.env_for("/", :method => "POST", :input => "_method=foo")
|
|
37
|
-
app = Rack::MethodOverride.new(lambda
|
|
35
|
+
app = Rack::MethodOverride.new(lambda{|envx| Rack::Request.new(envx) })
|
|
38
36
|
req = app.call(env)
|
|
39
37
|
|
|
40
38
|
req.env["REQUEST_METHOD"].should.equal "POST"
|
|
41
39
|
end
|
|
42
40
|
|
|
43
|
-
|
|
41
|
+
should "not modify REQUEST_METHOD when _method is nil" do
|
|
44
42
|
env = Rack::MockRequest.env_for("/", :method => "POST", :input => "foo=bar")
|
|
45
|
-
app = Rack::MethodOverride.new(lambda
|
|
43
|
+
app = Rack::MethodOverride.new(lambda{|envx| Rack::Request.new(envx) })
|
|
46
44
|
req = app.call(env)
|
|
47
45
|
|
|
48
46
|
req.env["REQUEST_METHOD"].should.equal "POST"
|
|
49
47
|
end
|
|
50
48
|
|
|
51
|
-
|
|
49
|
+
should "store the original REQUEST_METHOD prior to overriding" do
|
|
52
50
|
env = Rack::MockRequest.env_for("/",
|
|
53
51
|
:method => "POST",
|
|
54
52
|
:input => "_method=options")
|
|
55
|
-
app = Rack::MethodOverride.new(lambda
|
|
53
|
+
app = Rack::MethodOverride.new(lambda{|envx| Rack::Request.new(envx) })
|
|
56
54
|
req = app.call(env)
|
|
57
55
|
|
|
58
56
|
req.env["rack.methodoverride.original_method"].should.equal "POST"
|
|
@@ -1,35 +1,33 @@
|
|
|
1
1
|
require 'yaml'
|
|
2
2
|
require 'rack/mock'
|
|
3
|
-
require 'rack/request'
|
|
4
|
-
require 'rack/response'
|
|
5
3
|
|
|
6
4
|
app = lambda { |env|
|
|
7
5
|
req = Rack::Request.new(env)
|
|
8
|
-
|
|
6
|
+
|
|
9
7
|
env["mock.postdata"] = env["rack.input"].read
|
|
10
8
|
if req.GET["error"]
|
|
11
9
|
env["rack.errors"].puts req.GET["error"]
|
|
12
10
|
env["rack.errors"].flush
|
|
13
11
|
end
|
|
14
|
-
|
|
12
|
+
|
|
15
13
|
Rack::Response.new(env.to_yaml,
|
|
16
14
|
req.GET["status"] || 200,
|
|
17
15
|
"Content-Type" => "text/yaml").finish
|
|
18
16
|
}
|
|
19
17
|
|
|
20
|
-
|
|
21
|
-
|
|
18
|
+
describe Rack::MockRequest do
|
|
19
|
+
should "return a MockResponse" do
|
|
22
20
|
res = Rack::MockRequest.new(app).get("")
|
|
23
21
|
res.should.be.kind_of Rack::MockResponse
|
|
24
22
|
end
|
|
25
23
|
|
|
26
|
-
|
|
24
|
+
should "be able to only return the environment" do
|
|
27
25
|
env = Rack::MockRequest.env_for("")
|
|
28
26
|
env.should.be.kind_of Hash
|
|
29
27
|
env.should.include "rack.version"
|
|
30
28
|
end
|
|
31
29
|
|
|
32
|
-
|
|
30
|
+
should "provide sensible defaults" do
|
|
33
31
|
res = Rack::MockRequest.new(app).request
|
|
34
32
|
|
|
35
33
|
env = YAML.load(res.body)
|
|
@@ -43,7 +41,7 @@ context "Rack::MockRequest" do
|
|
|
43
41
|
env["mock.postdata"].should.be.empty
|
|
44
42
|
end
|
|
45
43
|
|
|
46
|
-
|
|
44
|
+
should "allow GET/POST/PUT/DELETE" do
|
|
47
45
|
res = Rack::MockRequest.new(app).get("", :input => "foo")
|
|
48
46
|
env = YAML.load(res.body)
|
|
49
47
|
env["REQUEST_METHOD"].should.equal "GET"
|
|
@@ -64,12 +62,12 @@ context "Rack::MockRequest" do
|
|
|
64
62
|
should.equal "OPTIONS"
|
|
65
63
|
end
|
|
66
64
|
|
|
67
|
-
|
|
65
|
+
should "set content length" do
|
|
68
66
|
env = Rack::MockRequest.env_for("/", :input => "foo")
|
|
69
67
|
env["CONTENT_LENGTH"].should.equal "3"
|
|
70
68
|
end
|
|
71
69
|
|
|
72
|
-
|
|
70
|
+
should "allow posting" do
|
|
73
71
|
res = Rack::MockRequest.new(app).get("", :input => "foo")
|
|
74
72
|
env = YAML.load(res.body)
|
|
75
73
|
env["mock.postdata"].should.equal "foo"
|
|
@@ -79,7 +77,7 @@ context "Rack::MockRequest" do
|
|
|
79
77
|
env["mock.postdata"].should.equal "foo"
|
|
80
78
|
end
|
|
81
79
|
|
|
82
|
-
|
|
80
|
+
should "use all parts of an URL" do
|
|
83
81
|
res = Rack::MockRequest.new(app).
|
|
84
82
|
get("https://bla.example.org:9292/meh/foo?bar")
|
|
85
83
|
res.should.be.kind_of Rack::MockResponse
|
|
@@ -93,7 +91,7 @@ context "Rack::MockRequest" do
|
|
|
93
91
|
env["rack.url_scheme"].should.equal "https"
|
|
94
92
|
end
|
|
95
93
|
|
|
96
|
-
|
|
94
|
+
should "set SSL port and HTTP flag on when using https" do
|
|
97
95
|
res = Rack::MockRequest.new(app).
|
|
98
96
|
get("https://example.org/foo")
|
|
99
97
|
res.should.be.kind_of Rack::MockResponse
|
|
@@ -108,7 +106,7 @@ context "Rack::MockRequest" do
|
|
|
108
106
|
env["HTTPS"].should.equal "on"
|
|
109
107
|
end
|
|
110
108
|
|
|
111
|
-
|
|
109
|
+
should "prepend slash to uri path" do
|
|
112
110
|
res = Rack::MockRequest.new(app).
|
|
113
111
|
get("foo")
|
|
114
112
|
res.should.be.kind_of Rack::MockResponse
|
|
@@ -122,33 +120,33 @@ context "Rack::MockRequest" do
|
|
|
122
120
|
env["rack.url_scheme"].should.equal "http"
|
|
123
121
|
end
|
|
124
122
|
|
|
125
|
-
|
|
123
|
+
should "properly convert method name to an uppercase string" do
|
|
126
124
|
res = Rack::MockRequest.new(app).request(:get)
|
|
127
125
|
env = YAML.load(res.body)
|
|
128
126
|
env["REQUEST_METHOD"].should.equal "GET"
|
|
129
127
|
end
|
|
130
128
|
|
|
131
|
-
|
|
129
|
+
should "accept params and build query string for GET requests" do
|
|
132
130
|
res = Rack::MockRequest.new(app).get("/foo?baz=2", :params => {:foo => {:bar => "1"}})
|
|
133
131
|
env = YAML.load(res.body)
|
|
134
132
|
env["REQUEST_METHOD"].should.equal "GET"
|
|
135
|
-
env["QUERY_STRING"].should.
|
|
136
|
-
env["QUERY_STRING"].should.
|
|
133
|
+
env["QUERY_STRING"].should.include "baz=2"
|
|
134
|
+
env["QUERY_STRING"].should.include "foo[bar]=1"
|
|
137
135
|
env["PATH_INFO"].should.equal "/foo"
|
|
138
136
|
env["mock.postdata"].should.equal ""
|
|
139
137
|
end
|
|
140
138
|
|
|
141
|
-
|
|
139
|
+
should "accept raw input in params for GET requests" do
|
|
142
140
|
res = Rack::MockRequest.new(app).get("/foo?baz=2", :params => "foo[bar]=1")
|
|
143
141
|
env = YAML.load(res.body)
|
|
144
142
|
env["REQUEST_METHOD"].should.equal "GET"
|
|
145
|
-
env["QUERY_STRING"].should.
|
|
146
|
-
env["QUERY_STRING"].should.
|
|
143
|
+
env["QUERY_STRING"].should.include "baz=2"
|
|
144
|
+
env["QUERY_STRING"].should.include "foo[bar]=1"
|
|
147
145
|
env["PATH_INFO"].should.equal "/foo"
|
|
148
146
|
env["mock.postdata"].should.equal ""
|
|
149
147
|
end
|
|
150
148
|
|
|
151
|
-
|
|
149
|
+
should "accept params and build url encoded params for POST requests" do
|
|
152
150
|
res = Rack::MockRequest.new(app).post("/foo", :params => {:foo => {:bar => "1"}})
|
|
153
151
|
env = YAML.load(res.body)
|
|
154
152
|
env["REQUEST_METHOD"].should.equal "POST"
|
|
@@ -158,7 +156,7 @@ context "Rack::MockRequest" do
|
|
|
158
156
|
env["mock.postdata"].should.equal "foo[bar]=1"
|
|
159
157
|
end
|
|
160
158
|
|
|
161
|
-
|
|
159
|
+
should "accept raw input in params for POST requests" do
|
|
162
160
|
res = Rack::MockRequest.new(app).post("/foo", :params => "foo[bar]=1")
|
|
163
161
|
env = YAML.load(res.body)
|
|
164
162
|
env["REQUEST_METHOD"].should.equal "POST"
|
|
@@ -168,7 +166,7 @@ context "Rack::MockRequest" do
|
|
|
168
166
|
env["mock.postdata"].should.equal "foo[bar]=1"
|
|
169
167
|
end
|
|
170
168
|
|
|
171
|
-
|
|
169
|
+
should "accept params and build multipart encoded params for POST requests" do
|
|
172
170
|
files = Rack::Utils::Multipart::UploadedFile.new(File.join(File.dirname(__FILE__), "multipart", "file1.txt"))
|
|
173
171
|
res = Rack::MockRequest.new(app).post("/foo", :params => { "submit-name" => "Larry", "files" => files })
|
|
174
172
|
env = YAML.load(res.body)
|
|
@@ -179,7 +177,7 @@ context "Rack::MockRequest" do
|
|
|
179
177
|
env["mock.postdata"].length.should.equal 206
|
|
180
178
|
end
|
|
181
179
|
|
|
182
|
-
|
|
180
|
+
should "behave valid according to the Rack spec" do
|
|
183
181
|
lambda {
|
|
184
182
|
res = Rack::MockRequest.new(app).
|
|
185
183
|
get("https://bla.example.org:9292/meh/foo?bar", :lint => true)
|
|
@@ -187,8 +185,8 @@ context "Rack::MockRequest" do
|
|
|
187
185
|
end
|
|
188
186
|
end
|
|
189
187
|
|
|
190
|
-
|
|
191
|
-
|
|
188
|
+
describe Rack::MockResponse do
|
|
189
|
+
should "provide access to the HTTP status" do
|
|
192
190
|
res = Rack::MockRequest.new(app).get("")
|
|
193
191
|
res.should.be.successful
|
|
194
192
|
res.should.be.ok
|
|
@@ -209,18 +207,18 @@ context "Rack::MockResponse" do
|
|
|
209
207
|
res.should.be.empty
|
|
210
208
|
end
|
|
211
209
|
|
|
212
|
-
|
|
210
|
+
should "provide access to the HTTP headers" do
|
|
213
211
|
res = Rack::MockRequest.new(app).get("")
|
|
214
212
|
res.should.include "Content-Type"
|
|
215
213
|
res.headers["Content-Type"].should.equal "text/yaml"
|
|
216
214
|
res.original_headers["Content-Type"].should.equal "text/yaml"
|
|
217
215
|
res["Content-Type"].should.equal "text/yaml"
|
|
218
216
|
res.content_type.should.equal "text/yaml"
|
|
219
|
-
res.content_length.should.be
|
|
217
|
+
res.content_length.should.be > 0
|
|
220
218
|
res.location.should.be.nil
|
|
221
219
|
end
|
|
222
220
|
|
|
223
|
-
|
|
221
|
+
should "provide access to the HTTP body" do
|
|
224
222
|
res = Rack::MockRequest.new(app).get("")
|
|
225
223
|
res.body.should =~ /rack/
|
|
226
224
|
res.should =~ /rack/
|
|
@@ -228,14 +226,14 @@ context "Rack::MockResponse" do
|
|
|
228
226
|
res.should.satisfy { |r| r.match(/rack/) }
|
|
229
227
|
end
|
|
230
228
|
|
|
231
|
-
|
|
229
|
+
should "provide access to the Rack errors" do
|
|
232
230
|
res = Rack::MockRequest.new(app).get("/?error=foo", :lint => true)
|
|
233
231
|
res.should.be.ok
|
|
234
232
|
res.errors.should.not.be.empty
|
|
235
233
|
res.errors.should.include "foo"
|
|
236
234
|
end
|
|
237
235
|
|
|
238
|
-
|
|
236
|
+
should "optionally make Rack errors fatal" do
|
|
239
237
|
lambda {
|
|
240
238
|
Rack::MockRequest.new(app).get("/?error=foo", :fatal => true)
|
|
241
239
|
}.should.raise(Rack::MockRequest::FatalWarning)
|