rack-test 0.6.1 → 0.6.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +1 -1
- data/Gemfile.lock +16 -13
- data/History.txt +13 -0
- data/README.rdoc +32 -4
- data/lib/rack/test.rb +18 -7
- data/lib/rack/test/cookie_jar.rb +6 -0
- data/lib/rack/test/methods.rb +1 -0
- data/rack-test.gemspec +9 -12
- data/spec/fixtures/fake_app.rb +15 -0
- data/spec/rack/test/cookie_spec.rb +18 -0
- data/spec/rack/test/digest_auth_spec.rb +6 -0
- data/spec/rack/test_spec.rb +34 -0
- metadata +41 -56
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,21 +1,24 @@
|
|
1
1
|
GEM
|
2
2
|
remote: http://rubygems.org/
|
3
3
|
specs:
|
4
|
-
diff-lcs (1.1.
|
5
|
-
rack (1.
|
4
|
+
diff-lcs (1.1.3)
|
5
|
+
rack (1.4.0)
|
6
|
+
rack-protection (1.2.0)
|
7
|
+
rack
|
6
8
|
rake (0.9.2)
|
7
|
-
rspec (2.
|
8
|
-
rspec-core (~> 2.
|
9
|
-
rspec-expectations (~> 2.
|
10
|
-
rspec-mocks (~> 2.
|
11
|
-
rspec-core (2.
|
12
|
-
rspec-expectations (2.
|
9
|
+
rspec (2.8.0)
|
10
|
+
rspec-core (~> 2.8.0)
|
11
|
+
rspec-expectations (~> 2.8.0)
|
12
|
+
rspec-mocks (~> 2.8.0)
|
13
|
+
rspec-core (2.8.0)
|
14
|
+
rspec-expectations (2.8.0)
|
13
15
|
diff-lcs (~> 1.1.2)
|
14
|
-
rspec-mocks (2.
|
15
|
-
sinatra (1.2
|
16
|
-
rack (~> 1.1)
|
17
|
-
|
18
|
-
|
16
|
+
rspec-mocks (2.8.0)
|
17
|
+
sinatra (1.3.2)
|
18
|
+
rack (~> 1.3, >= 1.3.6)
|
19
|
+
rack-protection (~> 1.2)
|
20
|
+
tilt (~> 1.3, >= 1.3.3)
|
21
|
+
tilt (1.3.3)
|
19
22
|
|
20
23
|
PLATFORMS
|
21
24
|
java
|
data/History.txt
CHANGED
@@ -1,3 +1,16 @@
|
|
1
|
+
== 0.6.2 / 2012-09-27
|
2
|
+
|
3
|
+
* Minor enhancements
|
4
|
+
|
5
|
+
* Support HTTP PATCH method (Marjan Krekoten' #33)
|
6
|
+
* Preserve the exact query string when possible (Paul Grayson #63)
|
7
|
+
* Add a #delete method to CookieJar (Paul Grayson #63)
|
8
|
+
|
9
|
+
* Bug fixes
|
10
|
+
|
11
|
+
* Fix HTTP Digest authentication when the URI has query params
|
12
|
+
* Don't append default ports to HTTP_HOST (David Lee #57)
|
13
|
+
|
1
14
|
== 0.6.1 / 2011-07-27
|
2
15
|
|
3
16
|
* Bug fixes
|
data/README.rdoc
CHANGED
@@ -1,7 +1,6 @@
|
|
1
|
-
= Rack::Test
|
1
|
+
= Rack::Test {<img src="https://codeclimate.com/badge.png" />}[https://codeclimate.com/github/brynary/rack-test]
|
2
2
|
|
3
3
|
- Code: http://github.com/brynary/rack-test
|
4
|
-
- Build: http://runcoderun.com/brynary/rack-test
|
5
4
|
|
6
5
|
== Description
|
7
6
|
|
@@ -17,7 +16,7 @@ request helpers feature.
|
|
17
16
|
* Set request headers to be used by all subsequent requests
|
18
17
|
* Small footprint. Approximately 200 LOC
|
19
18
|
|
20
|
-
==
|
19
|
+
== Examples
|
21
20
|
|
22
21
|
require "rack/test"
|
23
22
|
|
@@ -39,19 +38,48 @@ request helpers feature.
|
|
39
38
|
|
40
39
|
end
|
41
40
|
|
41
|
+
|
42
|
+
If you want to test one app in isolation, you just return that app as shown above. But if you want to test the entire app stack, including middlewares, cascades etc. you need to parse the app defined in config.ru.
|
43
|
+
|
44
|
+
OUTER_APP = Rack::Builder.parse_file('config.ru').first
|
45
|
+
|
46
|
+
class TestApp < Test::Unit::TestCase
|
47
|
+
include Rack::Test::Methods
|
48
|
+
|
49
|
+
def app
|
50
|
+
OUTER_APP
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_root
|
54
|
+
get '/'
|
55
|
+
assert last_response.ok?
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
|
42
60
|
== Install
|
43
61
|
|
44
62
|
To install the latest release as a gem:
|
45
63
|
|
46
64
|
sudo gem install rack-test
|
47
65
|
|
66
|
+
Or via Bundler:
|
67
|
+
|
68
|
+
gem "rack-test", require: "rack/test"
|
69
|
+
|
48
70
|
== Authors
|
49
71
|
|
50
72
|
- Maintained by {Bryan Helmkamp}[mailto:bryan@brynary.com]
|
51
|
-
- Contributions from Simon Rozet
|
73
|
+
- Contributions from Simon Rozet, Pat Nakajima and others
|
52
74
|
- Much of the original code was extracted from Merb 1.0's request helper
|
53
75
|
|
54
76
|
== License
|
55
77
|
|
56
78
|
Copyright (c) 2008-2009 Bryan Helmkamp, Engine Yard Inc.
|
57
79
|
See MIT-LICENSE.txt in this directory.
|
80
|
+
|
81
|
+
== Releasing
|
82
|
+
|
83
|
+
* Ensure History.txt is up-to-date
|
84
|
+
* Bump VERSION in lib/rack/test.rb
|
85
|
+
* thor :release
|
data/lib/rack/test.rb
CHANGED
@@ -9,7 +9,7 @@ require "rack/test/uploaded_file"
|
|
9
9
|
|
10
10
|
module Rack
|
11
11
|
module Test
|
12
|
-
VERSION = "0.6.
|
12
|
+
VERSION = "0.6.2"
|
13
13
|
|
14
14
|
DEFAULT_HOST = "example.org"
|
15
15
|
MULTIPART_BOUNDARY = "----------XnJLe9ZIbbGUYtzPQJ16u1"
|
@@ -75,6 +75,15 @@ module Rack
|
|
75
75
|
process_request(uri, env, &block)
|
76
76
|
end
|
77
77
|
|
78
|
+
# Issue a PATCH request for the given URI. See #get
|
79
|
+
#
|
80
|
+
# Example:
|
81
|
+
# patch "/"
|
82
|
+
def patch(uri, params = {}, env = {}, &block)
|
83
|
+
env = env_for(uri, env.merge(:method => "PATCH", :params => params))
|
84
|
+
process_request(uri, env, &block)
|
85
|
+
end
|
86
|
+
|
78
87
|
# Issue a DELETE request for the given URI. See #get
|
79
88
|
#
|
80
89
|
# Example:
|
@@ -173,7 +182,7 @@ module Rack
|
|
173
182
|
|
174
183
|
env = default_env.merge(env)
|
175
184
|
|
176
|
-
env["HTTP_HOST"] ||= [uri.host, uri.port].compact.join(":")
|
185
|
+
env["HTTP_HOST"] ||= [uri.host, (uri.port if uri.port != uri.default_port)].compact.join(":")
|
177
186
|
|
178
187
|
env.update("HTTPS" => "on") if URI::HTTPS === uri
|
179
188
|
env["HTTP_X_REQUESTED_WITH"] = "XMLHttpRequest" if env[:xhr]
|
@@ -183,10 +192,12 @@ module Rack
|
|
183
192
|
env["REQUEST_METHOD"] ||= env[:method] ? env[:method].to_s.upcase : "GET"
|
184
193
|
|
185
194
|
if env["REQUEST_METHOD"] == "GET"
|
186
|
-
|
187
|
-
params =
|
188
|
-
|
189
|
-
|
195
|
+
# merge :params with the query string
|
196
|
+
if params = env[:params]
|
197
|
+
params = parse_nested_query(params) if params.is_a?(String)
|
198
|
+
params.update(parse_nested_query(uri.query))
|
199
|
+
uri.query = build_nested_query(params)
|
200
|
+
end
|
190
201
|
elsif !env.has_key?(:input)
|
191
202
|
env["CONTENT_TYPE"] ||= "application/x-www-form-urlencoded"
|
192
203
|
|
@@ -240,7 +251,7 @@ module Rack
|
|
240
251
|
"username" => @digest_username,
|
241
252
|
"nc" => "00000001",
|
242
253
|
"cnonce" => "nonsensenonce",
|
243
|
-
"uri" => last_request.
|
254
|
+
"uri" => last_request.fullpath,
|
244
255
|
"method" => last_request.env["REQUEST_METHOD"],
|
245
256
|
})
|
246
257
|
|
data/lib/rack/test/cookie_jar.rb
CHANGED
@@ -115,6 +115,12 @@ module Rack
|
|
115
115
|
merge("#{name}=#{Rack::Utils.escape(value)}")
|
116
116
|
end
|
117
117
|
|
118
|
+
def delete(name)
|
119
|
+
@cookies.reject! do |cookie|
|
120
|
+
cookie.name == name
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
118
124
|
def merge(raw_cookies, uri = nil)
|
119
125
|
return unless raw_cookies
|
120
126
|
|
data/lib/rack/test/methods.rb
CHANGED
data/rack-test.gemspec
CHANGED
@@ -1,17 +1,14 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
|
-
s.name =
|
5
|
-
s.version = "0.6.
|
4
|
+
s.name = "rack-test"
|
5
|
+
s.version = "0.6.2"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Bryan Helmkamp"]
|
9
|
-
s.date =
|
10
|
-
s.description =
|
11
|
-
|
12
|
-
to build on. Most of its initial functionality is an extraction of Merb 1.0's
|
13
|
-
request helpers feature.}
|
14
|
-
s.email = %q{bryan@brynary.com}
|
9
|
+
s.date = "2012-09-27"
|
10
|
+
s.description = "Rack::Test is a small, simple testing API for Rack apps. It can be used on its\nown or as a reusable starting point for Web frameworks and testing libraries\nto build on. Most of its initial functionality is an extraction of Merb 1.0's\nrequest helpers feature."
|
11
|
+
s.email = "bryan@brynary.com"
|
15
12
|
s.extra_rdoc_files = [
|
16
13
|
"README.rdoc",
|
17
14
|
"MIT-LICENSE.txt"
|
@@ -48,11 +45,11 @@ request helpers feature.}
|
|
48
45
|
"spec/support/matchers/body.rb",
|
49
46
|
"spec/support/matchers/challenge.rb"
|
50
47
|
]
|
51
|
-
s.homepage =
|
48
|
+
s.homepage = "http://github.com/brynary/rack-test"
|
52
49
|
s.require_paths = ["lib"]
|
53
|
-
s.rubyforge_project =
|
54
|
-
s.rubygems_version =
|
55
|
-
s.summary =
|
50
|
+
s.rubyforge_project = "rack-test"
|
51
|
+
s.rubygems_version = "1.8.23"
|
52
|
+
s.summary = "Simple testing API built on Rack"
|
56
53
|
s.test_files = [
|
57
54
|
"spec/fixtures/fake_app.rb",
|
58
55
|
"spec/rack/test/cookie_spec.rb",
|
data/spec/fixtures/fake_app.rb
CHANGED
@@ -55,6 +55,17 @@ module Rack
|
|
55
55
|
"Set"
|
56
56
|
end
|
57
57
|
|
58
|
+
post "/cookies/default-path" do
|
59
|
+
raise if params["value"].nil?
|
60
|
+
|
61
|
+
response.set_cookie "simple", params["value"]
|
62
|
+
"Set"
|
63
|
+
end
|
64
|
+
|
65
|
+
get "/cookies/default-path" do
|
66
|
+
response.cookies.inspect
|
67
|
+
end
|
68
|
+
|
58
69
|
get "/cookies/delete" do
|
59
70
|
response.delete_cookie "value"
|
60
71
|
end
|
@@ -119,6 +130,10 @@ module Rack
|
|
119
130
|
"Hello, PUT: #{params.inspect}"
|
120
131
|
end
|
121
132
|
|
133
|
+
patch "/" do
|
134
|
+
"Hello, PUT: #{params.inspect}"
|
135
|
+
end
|
136
|
+
|
122
137
|
delete "/" do
|
123
138
|
"Hello, DELETE: #{params.inspect}"
|
124
139
|
end
|
@@ -20,12 +20,30 @@ describe Rack::Test::Session do
|
|
20
20
|
last_request.cookies.should == {}
|
21
21
|
end
|
22
22
|
|
23
|
+
it "cookie path defaults to the uri of the document that was requested" do
|
24
|
+
pending "See issue rack-test github issue #50" do
|
25
|
+
post "/cookies/default-path", "value" => "cookie"
|
26
|
+
get "/cookies/default-path"
|
27
|
+
check last_request.cookies.should == { "simple"=>"cookie" }
|
28
|
+
get "/cookies/show"
|
29
|
+
check last_request.cookies.should == { }
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
23
33
|
it "escapes cookie values" do
|
24
34
|
jar = Rack::Test::CookieJar.new
|
25
35
|
jar["value"] = "foo;abc"
|
26
36
|
jar["value"].should == "foo;abc"
|
27
37
|
end
|
28
38
|
|
39
|
+
it "deletes cookies directly from the CookieJar" do
|
40
|
+
jar = Rack::Test::CookieJar.new
|
41
|
+
jar["abcd"] = "1234"
|
42
|
+
jar["abcd"].should == "1234"
|
43
|
+
jar.delete("abcd")
|
44
|
+
jar["abcd"].should == nil
|
45
|
+
end
|
46
|
+
|
29
47
|
it "doesn't send cookies with the wrong domain" do
|
30
48
|
get "http://www.example.com/cookies/set", "value" => "1"
|
31
49
|
get "http://www.other.example/cookies/show"
|
@@ -24,6 +24,12 @@ describe Rack::Test::Session do
|
|
24
24
|
response.should be_ok
|
25
25
|
end
|
26
26
|
|
27
|
+
it "correctly authenticates GETs with params" do
|
28
|
+
digest_authorize "alice", "correct-password"
|
29
|
+
response = get "/", "foo" => "bar"
|
30
|
+
response.should be_ok
|
31
|
+
end
|
32
|
+
|
27
33
|
it "correctly authenticates POSTs" do
|
28
34
|
digest_authorize "alice", "correct-password"
|
29
35
|
response = post "/"
|
data/spec/rack/test_spec.rb
CHANGED
@@ -34,6 +34,22 @@ describe Rack::Test::Session do
|
|
34
34
|
last_request.env['HTTP_HOST'].should == "www.example.ua"
|
35
35
|
end
|
36
36
|
|
37
|
+
it "sets HTTP_HOST with port for non-default ports" do
|
38
|
+
request "http://foo.com:8080"
|
39
|
+
last_request.env["HTTP_HOST"].should == "foo.com:8080"
|
40
|
+
request "https://foo.com:8443"
|
41
|
+
last_request.env["HTTP_HOST"].should == "foo.com:8443"
|
42
|
+
end
|
43
|
+
|
44
|
+
it "sets HTTP_HOST without port for default ports" do
|
45
|
+
request "http://foo.com"
|
46
|
+
last_request.env["HTTP_HOST"].should == "foo.com"
|
47
|
+
request "http://foo.com:80"
|
48
|
+
last_request.env["HTTP_HOST"].should == "foo.com"
|
49
|
+
request "https://foo.com:443"
|
50
|
+
last_request.env["HTTP_HOST"].should == "foo.com"
|
51
|
+
end
|
52
|
+
|
37
53
|
it "defaults to GET" do
|
38
54
|
request "/"
|
39
55
|
last_request.env["REQUEST_METHOD"].should == "GET"
|
@@ -106,6 +122,11 @@ describe Rack::Test::Session do
|
|
106
122
|
last_request.GET.should == { "baz" => "2", "foo" => { "bar" => "1" }}
|
107
123
|
end
|
108
124
|
|
125
|
+
it "does not rewrite a GET query string when :params is not supplied" do
|
126
|
+
request "/foo?a=1&b=2&c=3&e=4&d=5"
|
127
|
+
last_request.query_string.should == "a=1&b=2&c=3&e=4&d=5"
|
128
|
+
end
|
129
|
+
|
109
130
|
it "accepts params and builds url encoded params for POST requests" do
|
110
131
|
request "/foo", :method => :post, :params => {:foo => {:bar => "1"}}
|
111
132
|
last_request.env["rack.input"].read.should == "foo[bar]=1"
|
@@ -458,6 +479,19 @@ describe Rack::Test::Session do
|
|
458
479
|
end
|
459
480
|
end
|
460
481
|
|
482
|
+
describe "#patch" do
|
483
|
+
it_should_behave_like "any #verb methods"
|
484
|
+
|
485
|
+
def verb
|
486
|
+
"patch"
|
487
|
+
end
|
488
|
+
|
489
|
+
it "accepts a body" do
|
490
|
+
patch "/", "Lobsterlicious!"
|
491
|
+
last_request.body.read.should == "Lobsterlicious!"
|
492
|
+
end
|
493
|
+
end
|
494
|
+
|
461
495
|
describe "#delete" do
|
462
496
|
it_should_behave_like "any #verb methods"
|
463
497
|
|
metadata
CHANGED
@@ -1,52 +1,47 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-test
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.6.2
|
5
5
|
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 6
|
9
|
-
- 1
|
10
|
-
version: 0.6.1
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- Bryan Helmkamp
|
14
9
|
autorequire:
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
dependencies:
|
21
|
-
- !ruby/object:Gem::Dependency
|
12
|
+
date: 2012-09-27 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
22
15
|
name: rack
|
23
|
-
|
24
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
25
17
|
none: false
|
26
|
-
requirements:
|
27
|
-
- -
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
|
30
|
-
segments:
|
31
|
-
- 1
|
32
|
-
- 0
|
33
|
-
version: "1.0"
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '1.0'
|
34
22
|
type: :runtime
|
35
|
-
|
36
|
-
|
37
|
-
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.0'
|
30
|
+
description: ! 'Rack::Test is a small, simple testing API for Rack apps. It can be
|
31
|
+
used on its
|
32
|
+
|
38
33
|
own or as a reusable starting point for Web frameworks and testing libraries
|
39
|
-
|
40
|
-
|
34
|
+
|
35
|
+
to build on. Most of its initial functionality is an extraction of Merb 1.0''s
|
36
|
+
|
37
|
+
request helpers feature.'
|
41
38
|
email: bryan@brynary.com
|
42
39
|
executables: []
|
43
|
-
|
44
40
|
extensions: []
|
45
|
-
|
46
|
-
extra_rdoc_files:
|
41
|
+
extra_rdoc_files:
|
47
42
|
- README.rdoc
|
48
43
|
- MIT-LICENSE.txt
|
49
|
-
files:
|
44
|
+
files:
|
50
45
|
- .document
|
51
46
|
- .gitignore
|
52
47
|
- Gemfile
|
@@ -77,41 +72,31 @@ files:
|
|
77
72
|
- spec/spec_helper.rb
|
78
73
|
- spec/support/matchers/body.rb
|
79
74
|
- spec/support/matchers/challenge.rb
|
80
|
-
has_rdoc: true
|
81
75
|
homepage: http://github.com/brynary/rack-test
|
82
76
|
licenses: []
|
83
|
-
|
84
77
|
post_install_message:
|
85
78
|
rdoc_options: []
|
86
|
-
|
87
|
-
require_paths:
|
79
|
+
require_paths:
|
88
80
|
- lib
|
89
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
81
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
90
82
|
none: false
|
91
|
-
requirements:
|
92
|
-
- -
|
93
|
-
- !ruby/object:Gem::Version
|
94
|
-
|
95
|
-
|
96
|
-
- 0
|
97
|
-
version: "0"
|
98
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
83
|
+
requirements:
|
84
|
+
- - ! '>='
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '0'
|
87
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
99
88
|
none: false
|
100
|
-
requirements:
|
101
|
-
- -
|
102
|
-
- !ruby/object:Gem::Version
|
103
|
-
|
104
|
-
segments:
|
105
|
-
- 0
|
106
|
-
version: "0"
|
89
|
+
requirements:
|
90
|
+
- - ! '>='
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: '0'
|
107
93
|
requirements: []
|
108
|
-
|
109
94
|
rubyforge_project: rack-test
|
110
|
-
rubygems_version: 1.
|
95
|
+
rubygems_version: 1.8.23
|
111
96
|
signing_key:
|
112
97
|
specification_version: 3
|
113
98
|
summary: Simple testing API built on Rack
|
114
|
-
test_files:
|
99
|
+
test_files:
|
115
100
|
- spec/fixtures/fake_app.rb
|
116
101
|
- spec/rack/test/cookie_spec.rb
|
117
102
|
- spec/rack/test/digest_auth_spec.rb
|