rack-test 0.6.3 → 0.8.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/History.md +229 -0
- data/README.md +140 -0
- data/lib/rack/mock_session.rb +6 -9
- data/lib/rack/test/cookie_jar.rb +38 -28
- data/lib/rack/test/methods.rb +22 -22
- data/lib/rack/test/mock_digest_request.rb +1 -5
- data/lib/rack/test/uploaded_file.rb +50 -19
- data/lib/rack/test/utils.rb +37 -43
- data/lib/rack/test/version.rb +5 -0
- data/lib/rack/test.rb +86 -85
- metadata +139 -60
- data/.document +0 -4
- data/.gitignore +0 -6
- data/Gemfile +0 -8
- data/Gemfile.lock +0 -41
- data/History.txt +0 -179
- data/README.rdoc +0 -85
- data/Rakefile +0 -33
- data/Thorfile +0 -114
- data/rack-test.gemspec +0 -77
- data/spec/fixtures/bar.txt +0 -1
- data/spec/fixtures/config.ru +0 -3
- data/spec/fixtures/fake_app.rb +0 -143
- data/spec/fixtures/foo.txt +0 -1
- data/spec/rack/test/cookie_spec.rb +0 -219
- data/spec/rack/test/digest_auth_spec.rb +0 -46
- data/spec/rack/test/multipart_spec.rb +0 -145
- data/spec/rack/test/uploaded_file_spec.rb +0 -24
- data/spec/rack/test/utils_spec.rb +0 -193
- data/spec/rack/test_spec.rb +0 -550
- data/spec/spec_helper.rb +0 -69
- data/spec/support/matchers/body.rb +0 -9
- data/spec/support/matchers/challenge.rb +0 -11
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 98d93b9da867444521efc5c2d82d14b37c2b5743324865f96d2f6c0603ad8256
|
4
|
+
data.tar.gz: 3f78a90b58f6de6582088185f995195841995e9b2a0a9518a93ecee081eb8416
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3bd23e7ffcfa4ab19ad2966f36bcab31f49f3ea7f819fb81f15ce874437d8c6b96c6844f40499512042166b007d940b819b44e8d978ba4001f77fe515225f529
|
7
|
+
data.tar.gz: 9d0479de503ae1a74f2aa9263b39dfdabf1745c17bed3fc18e6aaf757bf0b7428510f26a08c0021090ec98f8125eca74fb19e9f7f19eef41a94dd9847a441472
|
data/History.md
ADDED
@@ -0,0 +1,229 @@
|
|
1
|
+
## 0.8.3 / 2018-02-27
|
2
|
+
|
3
|
+
* Bug fixes:
|
4
|
+
* Do not set Content-Type if params are explicitly set to nil
|
5
|
+
(Bartek Bułat #212). Fixes #200.
|
6
|
+
* Fix `UploadedFile#new` regression
|
7
|
+
(Per Lundberg #215)
|
8
|
+
|
9
|
+
* Minor enhancements
|
10
|
+
* [CI] Test against Ruby 2.5 (Nicolas Leger #217)
|
11
|
+
|
12
|
+
## 0.8.2 / 2017-11-21
|
13
|
+
|
14
|
+
* Bug fixes:
|
15
|
+
* Bugfix for `UploadedFile.new` unintended API breakage.
|
16
|
+
(Per Lundberg #210)
|
17
|
+
|
18
|
+
## 0.8.0 / 2017-11-20
|
19
|
+
|
20
|
+
* Known Issue
|
21
|
+
* In `UploadedFile.new`, when passing e.g. a `Pathname` object,
|
22
|
+
errors can be raised (eg. `ArgumentError: Missing original_filename
|
23
|
+
for IO`, or `NoMethodError: undefined method 'size'`) See #207, #209.
|
24
|
+
* Minor enhancements
|
25
|
+
* Add a required_ruby_version of >= 2.2.2, similar to rack 2.0.1.
|
26
|
+
(Samuel Giddins #194)
|
27
|
+
* Remove new line from basic auth. (Felix Kleinschmidt #185)
|
28
|
+
* Rubocop fixes (Per Lundberg #196)
|
29
|
+
* Add how to install rack-test from github to README. (Jun Aruga #189)
|
30
|
+
* Update CodeClimate badges (Toshimaru #195)
|
31
|
+
* Add the ability to create Test::UploadedFile instances without
|
32
|
+
the file system (Adam Milligan #149)
|
33
|
+
* Add custom_request, remove duplication (Johannes Barre #184)
|
34
|
+
* README.md: Added note about how to post JSON (Per Lundberg #198)
|
35
|
+
* README.md: Added version badge (Per Lundberg #199)
|
36
|
+
* Bug fixes
|
37
|
+
* Bugfix for Cookies with multiple paths (Kyle Welsby #197)
|
38
|
+
|
39
|
+
## 0.7.0 / 2017-07-10
|
40
|
+
|
41
|
+
* Major enhancements
|
42
|
+
* The project URL changed to https://github.com/rack-test/rack-test
|
43
|
+
(Per Lundberg, Dennis Sivia, Jun Aruga)
|
44
|
+
* Rack 2 compatible. (Trevor Wennblom #81, Vít Ondruch, Jun Aruga #151)
|
45
|
+
* Minor enhancements
|
46
|
+
* Port to RSpec 3. (Murahashi [Matt] Kenichi #70, Antonio Terceiro #134)
|
47
|
+
* Add Travis CI (Johannes Barre #108, Jun Aruga #161)
|
48
|
+
* Don't append an ampersand when params are empty (sbilharz, #157)
|
49
|
+
* Allow symbol access to cookies (Anorlondo448 #156)
|
50
|
+
* README: Added Travis badge (Olivier Lacan, Per Lundberg #146)
|
51
|
+
* `Rack::Test::Utils#build_multipart`: Allow passing a third parameter
|
52
|
+
to force multipart (Koen Punt #142)
|
53
|
+
* Allow better testing of cookies (Stephen Best #133)
|
54
|
+
* make `build_multipart` work without mixing in `Rack::Test::Utils`
|
55
|
+
(Aaron Patterson #131)
|
56
|
+
* Add license to gemspec (Jordi Massaguer Pla #72, Anatol Pomozov #89,
|
57
|
+
Anatol Pomozov #90, Johannes Barre #109, Mandaryn #115,
|
58
|
+
Chris Marshall #120, Robert Reiz #126, Nic Benders #127, Nic Benders #130)
|
59
|
+
* Feature/bulk pr for readme updates (Patrick Mulder #65,
|
60
|
+
Troels Knak-Nielsen #74, Jeff Casimir #76)
|
61
|
+
* Switch README format to Markdown (Dennis Sivia #176)
|
62
|
+
* Convert History.txt to Markdown (Dennis Sivia #179)
|
63
|
+
* Stop generating gemspec file. (Jun Aruga #181)
|
64
|
+
* Fix errors at rake docs and whitespace. (Jun Aruga #183)
|
65
|
+
* Ensure Rack::Test::UploadedFile closes its tempfile file descriptor
|
66
|
+
on GC (Michael de Silva #180)
|
67
|
+
* Change codeclimate URL correctly. (Jun Aruga #186)
|
68
|
+
* Bug fixes
|
69
|
+
* Initialize digest_username before using it. (Guo Xiang Tan #116,
|
70
|
+
John Drago #124, Mike Perham #154)
|
71
|
+
* Do not set Content-Type for DELETE requests (David Celis #132)
|
72
|
+
* Adds support for empty arrays in params. (Cedric Röck, Tim Masliuchenko
|
73
|
+
#125)
|
74
|
+
* Update README code example quotes to be consistent. (Dmitry Gritsay #112)
|
75
|
+
* Update README not to recommend installing gem with sudo. (T.J. Schuck #87)
|
76
|
+
* Set scheme when using ENV to enable SSL (Neil Ang #155)
|
77
|
+
* Reuse request method and parameters on HTTP 307 redirect. (Martin Mauch
|
78
|
+
#138)
|
79
|
+
|
80
|
+
## 0.6.3 / 2015-01-09
|
81
|
+
|
82
|
+
* Minor enhancements
|
83
|
+
* Expose an env helper for persistently configuring the env as needed
|
84
|
+
(Darío Javier Cravero #80)
|
85
|
+
* Expose the tempfile of UploadedFile (Sytse Sijbrandij #67)
|
86
|
+
* Bug fixes
|
87
|
+
* Improve support for arrays of hashes in multipart forms (Murray Steele #69)
|
88
|
+
* Improve test for query strings (Paul Grayson #66)
|
89
|
+
|
90
|
+
## 0.6.2 / 2012-09-27
|
91
|
+
|
92
|
+
* Minor enhancements
|
93
|
+
* Support HTTP PATCH method (Marjan Krekoten' #33)
|
94
|
+
* Preserve the exact query string when possible (Paul Grayson #63)
|
95
|
+
* Add a #delete method to CookieJar (Paul Grayson #63)
|
96
|
+
* Bug fixes
|
97
|
+
* Fix HTTP Digest authentication when the URI has query params
|
98
|
+
* Don't append default ports to HTTP_HOST (David Lee #57)
|
99
|
+
|
100
|
+
## 0.6.1 / 2011-07-27
|
101
|
+
|
102
|
+
* Bug fixes
|
103
|
+
* Fix support for params with arrays in multipart forms (Joel Chippindale)
|
104
|
+
* Add `respond_to?` to `Rack::Test::UploadedFile` to match `method_missing` (Josh Nichols)
|
105
|
+
* Set the Referer header on requests issued by follow_redirect! (Ryan Bigg)
|
106
|
+
|
107
|
+
## 0.6.0 / 2011-05-03
|
108
|
+
|
109
|
+
* Bug fixes
|
110
|
+
* Add support for HTTP OPTIONS verb (Paolo "Nusco" Perrotta)
|
111
|
+
* Call #finish on MockResponses if it's available (Aaron Patterson)
|
112
|
+
* Allow HTTP_HOST to be set via #header (Geoff Buesing)
|
113
|
+
|
114
|
+
## 0.5.7 / 2011-01-01
|
115
|
+
* Bug fixes
|
116
|
+
* If no URI is present, include all cookies (Pratik Naik)
|
117
|
+
|
118
|
+
## 0.5.6 / 2010-09-25
|
119
|
+
|
120
|
+
* Bug fixes
|
121
|
+
* Use parse_nested_query for parsing URI like Rack does (Eugene Bolshakov)
|
122
|
+
* Don't depend on ActiveSupport extension to String (Bryan Helmkamp)
|
123
|
+
* Do not overwrite HTTP_HOST if it is set (Krekoten' Marjan)
|
124
|
+
|
125
|
+
## 0.5.5 / 2010-09-22
|
126
|
+
|
127
|
+
* Bug fixes
|
128
|
+
* Fix encoding of file uploads on Ruby 1.9 (Alan Kennedy)
|
129
|
+
* Set env["HTTP_HOST"] when making requests (Istvan Hoka)
|
130
|
+
|
131
|
+
## 0.5.4 / 2010-05-26
|
132
|
+
|
133
|
+
* Bug fixes
|
134
|
+
* Don't stomp on Content-Type's supplied via #header (Bryan Helmkamp)
|
135
|
+
* Fixed build_multipart to allow for arrays of files (Louis Rose)
|
136
|
+
* Don't raise an error if raw cookies contain a blank line (John Reilly)
|
137
|
+
* Handle parameter names with brackets properly (Tanner Donovan)
|
138
|
+
|
139
|
+
## 0.5.3 / 2009-11-27
|
140
|
+
|
141
|
+
* Bug fixes
|
142
|
+
* Fix cookie matching for subdomains (Marcin Kulik)
|
143
|
+
|
144
|
+
## 0.5.2 / 2009-11-13
|
145
|
+
|
146
|
+
* Bug fixes
|
147
|
+
* Call close on response body after iteration, not before (Simon Rozet)
|
148
|
+
* Add missing require for time in cookie_jar.rb (Jerry West)
|
149
|
+
|
150
|
+
## 0.5.1 / 2009-10-27
|
151
|
+
|
152
|
+
* Bug fixes
|
153
|
+
* Escape cookie values (John Pignata)
|
154
|
+
* Close the response body after each request, as per the Rack spec (Elomar França)
|
155
|
+
|
156
|
+
## 0.5.0 / 2009-09-19
|
157
|
+
|
158
|
+
* Bug fixes
|
159
|
+
* Set HTTP_X_REQUESTED_WITH in the Rack env when a request is made with :xhr => true (Ben Sales)
|
160
|
+
* Set headers in the Rack env in HTTP_USER_AGENT form
|
161
|
+
* Rack::Test now generates no Ruby warnings
|
162
|
+
|
163
|
+
## 0.4.2 / 2009-09-01
|
164
|
+
|
165
|
+
* Minor enhancements
|
166
|
+
* Merge in rack/master's build_multipart method which covers additional cases
|
167
|
+
* Accept raw :params string input and merge it with the query string
|
168
|
+
* Stringify and upcase request method (e.g. :post => "POST") (Josh Peek)
|
169
|
+
* Bug fixes
|
170
|
+
* Properly convert hashes with nil values (e.g. :foo => nil becomes simply "foo", not "foo=")
|
171
|
+
* Prepend a slash to the URI path if it doesn't start with one (Josh Peek)
|
172
|
+
* Requiring Rack-Test never modifies the Ruby load path anymore (Josh Peek)
|
173
|
+
* Fixed using multiple cookies in a string on Ruby 1.8 (Tuomas Kareinen and Hermanni Hyytiälä)
|
174
|
+
|
175
|
+
## 0.4.1 / 2009-08-06
|
176
|
+
|
177
|
+
* Minor enhancements
|
178
|
+
* Support initializing a `Rack::Test::Session` with an app in addition to
|
179
|
+
a `Rack::MockSession`
|
180
|
+
* Allow CONTENT_TYPE to be specified in the env and not overwritten when
|
181
|
+
sending a POST or PUT
|
182
|
+
|
183
|
+
## 0.4.0 / 2009-06-25
|
184
|
+
|
185
|
+
* Minor enhancements
|
186
|
+
* Expose hook for building `Rack::MockSessions` for frameworks that need
|
187
|
+
to configure them before use
|
188
|
+
* Support passing in arrays of raw cookies in addition to a newline
|
189
|
+
separated string
|
190
|
+
* Support after_request callbacks in MockSession for things like running
|
191
|
+
background jobs
|
192
|
+
* Allow multiple named sessions using with_session
|
193
|
+
* Initialize `Rack::Test::Sessions` with `Rack::MockSessions` instead of apps.
|
194
|
+
This change should help integration with other Ruby web frameworks
|
195
|
+
(like Merb).
|
196
|
+
* Support sending bodies for PUT requests (Larry Diehl)
|
197
|
+
|
198
|
+
## 0.3.0 / 2009-05-17
|
199
|
+
|
200
|
+
* Major enhancements
|
201
|
+
* Ruby 1.9 compatible (Simon Rozet, Michael Fellinger)
|
202
|
+
* Minor enhancements
|
203
|
+
* Add `CookieJar#[]` and `CookieJar#[]=` methods
|
204
|
+
* Make the default host configurable
|
205
|
+
* Use `Rack::Lint` and fix errors (Simon Rozet)
|
206
|
+
* Extract `Rack::MockSession` from `Rack::Test::Session` to handle tracking
|
207
|
+
the last request and response and the cookie jar
|
208
|
+
* Add #set_cookie and #clear_cookies methods
|
209
|
+
* Rename #authorize to #basic_authorize (#authorize remains as an alias)
|
210
|
+
(Simon Rozet)
|
211
|
+
|
212
|
+
## 0.2.0 / 2009-04-26
|
213
|
+
|
214
|
+
Because `#last_response` is now a `MockResponse` instead of a `Rack::Response`, `#last_response.body`
|
215
|
+
now returns a string instead of an array.
|
216
|
+
|
217
|
+
* Major enhancements
|
218
|
+
* Support multipart requests via the UploadedFile class (thanks, Rails)
|
219
|
+
* Minor enhancements
|
220
|
+
* Updated for Rack 1.0
|
221
|
+
* Don't require rubygems (See http://gist.github.com/54177)
|
222
|
+
* Support HTTP Digest authentication with the `#digest_authorize` method
|
223
|
+
* `#last_response` returns a `MockResponse` instead of a Response
|
224
|
+
(Michael Fellinger)
|
225
|
+
|
226
|
+
## 0.1.0 / 2009-03-02
|
227
|
+
|
228
|
+
* 1 major enhancement
|
229
|
+
* Birthday!
|
data/README.md
ADDED
@@ -0,0 +1,140 @@
|
|
1
|
+
# Rack::Test
|
2
|
+
[![Gem Version](https://badge.fury.io/rb/rack-test.svg)](https://badge.fury.io/rb/rack-test)
|
3
|
+
[<img src="https://travis-ci.org/rack-test/rack-test.svg?branch=master" />](https://travis-ci.org/rack-test/rack-test)
|
4
|
+
[![Code Climate](https://codeclimate.com/github/codeclimate/codeclimate/badges/gpa.svg)](https://codeclimate.com/github/codeclimate/codeclimate)
|
5
|
+
[![Test Coverage](https://codeclimate.com/github/codeclimate/codeclimate/badges/coverage.svg)](https://codeclimate.com/github/codeclimate/codeclimate/coverage)
|
6
|
+
|
7
|
+
Code: https://github.com/rack-test/rack-test
|
8
|
+
|
9
|
+
## Description
|
10
|
+
|
11
|
+
Rack::Test is a small, simple testing API for Rack apps. It can be used on its
|
12
|
+
own or as a reusable starting point for Web frameworks and testing libraries
|
13
|
+
to build on.
|
14
|
+
|
15
|
+
## Features
|
16
|
+
|
17
|
+
* Maintains a cookie jar across requests
|
18
|
+
* Easily follow redirects when desired
|
19
|
+
* Set request headers to be used by all subsequent requests
|
20
|
+
* Small footprint. Approximately 200 LOC
|
21
|
+
|
22
|
+
## Supported platforms
|
23
|
+
|
24
|
+
* 2.2.2+
|
25
|
+
* 2.3
|
26
|
+
* 2.4
|
27
|
+
* JRuby 9.1.+
|
28
|
+
|
29
|
+
If you are using Ruby 1.8, 1.9 or JRuby 1.7, use rack-test 0.6.3.
|
30
|
+
|
31
|
+
## Examples
|
32
|
+
(The examples use `Test::Unit` but it's equally possible to use `rack-test` with other testing frameworks like `rspec`.)
|
33
|
+
|
34
|
+
```ruby
|
35
|
+
require "test/unit"
|
36
|
+
require "rack/test"
|
37
|
+
|
38
|
+
class HomepageTest < Test::Unit::TestCase
|
39
|
+
include Rack::Test::Methods
|
40
|
+
|
41
|
+
def app
|
42
|
+
app = lambda { |env| [200, {'Content-Type' => 'text/plain'}, ['All responses are OK']] }
|
43
|
+
builder = Rack::Builder.new
|
44
|
+
builder.run app
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_response_is_ok
|
48
|
+
get '/'
|
49
|
+
|
50
|
+
assert last_response.ok?
|
51
|
+
assert_equal last_response.body, 'All responses are OK'
|
52
|
+
end
|
53
|
+
|
54
|
+
def set_request_headers
|
55
|
+
header 'Accept-Charset', 'utf-8'
|
56
|
+
get '/'
|
57
|
+
|
58
|
+
assert last_response.ok?
|
59
|
+
assert_equal last_response.body, 'All responses are OK'
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_response_is_ok_for_other_paths
|
63
|
+
get '/other_paths'
|
64
|
+
|
65
|
+
assert last_response.ok?
|
66
|
+
assert_equal last_response.body, 'All responses are OK'
|
67
|
+
end
|
68
|
+
|
69
|
+
def post_with_json
|
70
|
+
# No assertion in this, we just demonstrate how you can post a JSON-encoded string.
|
71
|
+
# By default, Rack::Test will use HTTP form encoding if you pass in a Hash as the
|
72
|
+
# parameters, so make sure that `json` below is already a JSON-serialized string.
|
73
|
+
post(uri, json, { 'CONTENT_TYPE' => 'application/json' })
|
74
|
+
end
|
75
|
+
end
|
76
|
+
```
|
77
|
+
|
78
|
+
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.
|
79
|
+
|
80
|
+
```ruby
|
81
|
+
OUTER_APP = Rack::Builder.parse_file("config.ru").first
|
82
|
+
|
83
|
+
class TestApp < Test::Unit::TestCase
|
84
|
+
include Rack::Test::Methods
|
85
|
+
|
86
|
+
def app
|
87
|
+
OUTER_APP
|
88
|
+
end
|
89
|
+
|
90
|
+
def test_root
|
91
|
+
get "/"
|
92
|
+
assert last_response.ok?
|
93
|
+
end
|
94
|
+
end
|
95
|
+
```
|
96
|
+
|
97
|
+
|
98
|
+
## Install
|
99
|
+
|
100
|
+
To install the latest release as a gem:
|
101
|
+
|
102
|
+
```
|
103
|
+
gem install rack-test
|
104
|
+
```
|
105
|
+
|
106
|
+
Or via Bundler:
|
107
|
+
|
108
|
+
```
|
109
|
+
gem 'rack-test', require: 'rack/test'
|
110
|
+
```
|
111
|
+
|
112
|
+
Or to install unreleased version via Bundler:
|
113
|
+
|
114
|
+
```
|
115
|
+
gem 'rack-test', github: 'rack-test', branch: 'master'
|
116
|
+
```
|
117
|
+
|
118
|
+
## Authors
|
119
|
+
|
120
|
+
- Contributions from Bryan Helmkamp, Simon Rozet, Pat Nakajima and others
|
121
|
+
- Much of the original code was extracted from Merb 1.0's request helper
|
122
|
+
|
123
|
+
## License
|
124
|
+
`rack-test` is released under the [MIT License](MIT-LICENSE.txt).
|
125
|
+
|
126
|
+
## Contribution
|
127
|
+
|
128
|
+
Contributions are welcome. Please make sure to:
|
129
|
+
|
130
|
+
* Use a regular forking workflow
|
131
|
+
* Write tests for the new or changed behaviour
|
132
|
+
* Provide an explanation/motivation in your commit message / PR message
|
133
|
+
* Ensure History.txt is updated
|
134
|
+
|
135
|
+
## Releasing
|
136
|
+
|
137
|
+
* Ensure `History.md` is up-to-date
|
138
|
+
* Bump VERSION in lib/rack/test/version.rb
|
139
|
+
* bundle exec thor :release
|
140
|
+
* Updated the [GitHub releases page](https://github.com/rack-test/rack-test/releases)
|
data/lib/rack/mock_session.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
module Rack
|
2
|
-
|
3
2
|
class MockSession # :nodoc:
|
4
3
|
attr_writer :cookie_jar
|
5
4
|
attr_reader :default_host
|
@@ -25,16 +24,16 @@ module Rack
|
|
25
24
|
end
|
26
25
|
|
27
26
|
def request(uri, env)
|
28
|
-
env[
|
27
|
+
env['HTTP_COOKIE'] ||= cookie_jar.for(uri)
|
29
28
|
@last_request = Rack::Request.new(env)
|
30
29
|
status, headers, body = @app.call(@last_request.env)
|
31
30
|
|
32
|
-
@last_response = MockResponse.new(status, headers, body, env[
|
31
|
+
@last_response = MockResponse.new(status, headers, body, env['rack.errors'].flush)
|
33
32
|
body.close if body.respond_to?(:close)
|
34
33
|
|
35
|
-
cookie_jar.merge(last_response.headers[
|
34
|
+
cookie_jar.merge(last_response.headers['Set-Cookie'], uri)
|
36
35
|
|
37
|
-
@after_request.each
|
36
|
+
@after_request.each(&:call)
|
38
37
|
|
39
38
|
if @last_response.respond_to?(:finish)
|
40
39
|
@last_response.finish
|
@@ -46,21 +45,19 @@ module Rack
|
|
46
45
|
# Return the last request issued in the session. Raises an error if no
|
47
46
|
# requests have been sent yet.
|
48
47
|
def last_request
|
49
|
-
raise Rack::Test::Error
|
48
|
+
raise Rack::Test::Error, 'No request yet. Request a page first.' unless @last_request
|
50
49
|
@last_request
|
51
50
|
end
|
52
51
|
|
53
52
|
# Return the last response received in the session. Raises an error if
|
54
53
|
# no requests have been sent yet.
|
55
54
|
def last_response
|
56
|
-
raise Rack::Test::Error
|
55
|
+
raise Rack::Test::Error, 'No response yet. Request a page first.' unless @last_response
|
57
56
|
@last_response
|
58
57
|
end
|
59
58
|
|
60
59
|
def cookie_jar
|
61
60
|
@cookie_jar ||= Rack::Test::CookieJar.new([], @default_host)
|
62
61
|
end
|
63
|
-
|
64
62
|
end
|
65
|
-
|
66
63
|
end
|
data/lib/rack/test/cookie_jar.rb
CHANGED
@@ -1,9 +1,8 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require 'uri'
|
2
|
+
require 'time'
|
3
3
|
|
4
4
|
module Rack
|
5
5
|
module Test
|
6
|
-
|
7
6
|
class Cookie # :nodoc:
|
8
7
|
include Rack::Utils
|
9
8
|
|
@@ -21,8 +20,8 @@ module Rack
|
|
21
20
|
@name, @value = parse_query(@name_value_raw, ';').to_a.first
|
22
21
|
@options = parse_query(options, ';')
|
23
22
|
|
24
|
-
@options[
|
25
|
-
@options[
|
23
|
+
@options['domain'] ||= (uri.host || default_host)
|
24
|
+
@options['path'] ||= uri.path.sub(/\/[^\/]*\Z/, '')
|
26
25
|
end
|
27
26
|
|
28
27
|
def replaces?(other)
|
@@ -41,21 +40,25 @@ module Rack
|
|
41
40
|
|
42
41
|
# :api: private
|
43
42
|
def domain
|
44
|
-
@options[
|
43
|
+
@options['domain']
|
45
44
|
end
|
46
45
|
|
47
46
|
def secure?
|
48
|
-
@options.
|
47
|
+
@options.key?('secure')
|
48
|
+
end
|
49
|
+
|
50
|
+
def http_only?
|
51
|
+
@options.key?('HttpOnly')
|
49
52
|
end
|
50
53
|
|
51
54
|
# :api: private
|
52
55
|
def path
|
53
|
-
|
56
|
+
([*@options['path']].first.split(',').first || '/').strip
|
54
57
|
end
|
55
58
|
|
56
59
|
# :api: private
|
57
60
|
def expires
|
58
|
-
Time.parse(@options[
|
61
|
+
Time.parse(@options['expires']) if @options['expires']
|
59
62
|
end
|
60
63
|
|
61
64
|
# :api: private
|
@@ -67,19 +70,17 @@ module Rack
|
|
67
70
|
def valid?(uri)
|
68
71
|
uri ||= default_uri
|
69
72
|
|
70
|
-
if uri.host.nil?
|
71
|
-
uri.host = @default_host
|
72
|
-
end
|
73
|
+
uri.host = @default_host if uri.host.nil?
|
73
74
|
|
74
75
|
real_domain = domain =~ /^\./ ? domain[1..-1] : domain
|
75
|
-
(!secure? || (secure? && uri.scheme ==
|
76
|
-
|
77
|
-
|
76
|
+
(!secure? || (secure? && uri.scheme == 'https')) &&
|
77
|
+
uri.host =~ Regexp.new("#{Regexp.escape(real_domain)}$", Regexp::IGNORECASE) &&
|
78
|
+
uri.path =~ Regexp.new("^#{Regexp.escape(path)}")
|
78
79
|
end
|
79
80
|
|
80
81
|
# :api: private
|
81
82
|
def matches?(uri)
|
82
|
-
!
|
83
|
+
!expired? && valid?(uri)
|
83
84
|
end
|
84
85
|
|
85
86
|
# :api: private
|
@@ -88,16 +89,23 @@ module Rack
|
|
88
89
|
[name, path, domain.reverse] <=> [other.name, other.path, other.domain.reverse]
|
89
90
|
end
|
90
91
|
|
91
|
-
|
92
|
+
def to_h
|
93
|
+
@options.merge(
|
94
|
+
'value' => @value,
|
95
|
+
'HttpOnly' => http_only?,
|
96
|
+
'secure' => secure?
|
97
|
+
)
|
98
|
+
end
|
99
|
+
alias to_hash to_h
|
100
|
+
|
101
|
+
protected
|
92
102
|
|
93
103
|
def default_uri
|
94
|
-
URI.parse(
|
104
|
+
URI.parse('//' + @default_host + '/')
|
95
105
|
end
|
96
|
-
|
97
106
|
end
|
98
107
|
|
99
108
|
class CookieJar # :nodoc:
|
100
|
-
|
101
109
|
# :api: private
|
102
110
|
def initialize(cookies = [], default_host = DEFAULT_HOST)
|
103
111
|
@default_host = default_host
|
@@ -108,13 +116,17 @@ module Rack
|
|
108
116
|
def [](name)
|
109
117
|
cookies = hash_for(nil)
|
110
118
|
# TODO: Should be case insensitive
|
111
|
-
cookies[name] && cookies[name].value
|
119
|
+
cookies[name.to_s] && cookies[name.to_s].value
|
112
120
|
end
|
113
121
|
|
114
122
|
def []=(name, value)
|
115
123
|
merge("#{name}=#{Rack::Utils.escape(value)}")
|
116
124
|
end
|
117
125
|
|
126
|
+
def get_cookie(name)
|
127
|
+
hash_for(nil).fetch(name, nil)
|
128
|
+
end
|
129
|
+
|
118
130
|
def delete(name)
|
119
131
|
@cookies.reject! do |cookie|
|
120
132
|
cookie.name == name
|
@@ -126,7 +138,7 @@ module Rack
|
|
126
138
|
|
127
139
|
if raw_cookies.is_a? String
|
128
140
|
raw_cookies = raw_cookies.split("\n")
|
129
|
-
raw_cookies.reject!
|
141
|
+
raw_cookies.reject!(&:empty?)
|
130
142
|
end
|
131
143
|
|
132
144
|
raw_cookies.each do |raw_cookie|
|
@@ -146,7 +158,7 @@ module Rack
|
|
146
158
|
|
147
159
|
# :api: private
|
148
160
|
def for(uri)
|
149
|
-
hash_for(uri).values.map
|
161
|
+
hash_for(uri).values.map(&:raw).join(';')
|
150
162
|
end
|
151
163
|
|
152
164
|
def to_hash
|
@@ -156,10 +168,10 @@ module Rack
|
|
156
168
|
cookies[name] = cookie.value
|
157
169
|
end
|
158
170
|
|
159
|
-
|
171
|
+
cookies
|
160
172
|
end
|
161
173
|
|
162
|
-
|
174
|
+
protected
|
163
175
|
|
164
176
|
def hash_for(uri = nil)
|
165
177
|
cookies = {}
|
@@ -173,10 +185,8 @@ module Rack
|
|
173
185
|
cookies[cookie.name] = cookie if !uri || cookie.matches?(uri)
|
174
186
|
end
|
175
187
|
|
176
|
-
|
188
|
+
cookies
|
177
189
|
end
|
178
|
-
|
179
190
|
end
|
180
|
-
|
181
191
|
end
|
182
192
|
end
|
data/lib/rack/test/methods.rb
CHANGED
@@ -1,8 +1,7 @@
|
|
1
|
-
require
|
1
|
+
require 'forwardable'
|
2
2
|
|
3
3
|
module Rack
|
4
4
|
module Test
|
5
|
-
|
6
5
|
# This module serves as the primary integration point for using Rack::Test
|
7
6
|
# in a testing environment. It depends on an app method being defined in the
|
8
7
|
# same context, and provides the Rack::Test API methods (see Rack::Test::Session
|
@@ -56,26 +55,27 @@ module Rack
|
|
56
55
|
@_current_session_names ||= [:default]
|
57
56
|
end
|
58
57
|
|
59
|
-
METHODS = [
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
58
|
+
METHODS = %i[
|
59
|
+
request
|
60
|
+
get
|
61
|
+
post
|
62
|
+
put
|
63
|
+
patch
|
64
|
+
delete
|
65
|
+
options
|
66
|
+
head
|
67
|
+
custom_request
|
68
|
+
follow_redirect!
|
69
|
+
header
|
70
|
+
env
|
71
|
+
set_cookie
|
72
|
+
clear_cookies
|
73
|
+
authorize
|
74
|
+
basic_authorize
|
75
|
+
digest_authorize
|
76
|
+
last_response
|
77
|
+
last_request
|
78
|
+
].freeze
|
79
79
|
|
80
80
|
def_delegators :current_session, *METHODS
|
81
81
|
end
|
@@ -1,14 +1,12 @@
|
|
1
1
|
module Rack
|
2
2
|
module Test
|
3
|
-
|
4
3
|
class MockDigestRequest # :nodoc:
|
5
|
-
|
6
4
|
def initialize(params)
|
7
5
|
@params = params
|
8
6
|
end
|
9
7
|
|
10
8
|
def method_missing(sym)
|
11
|
-
if @params.
|
9
|
+
if @params.key? k = sym.to_s
|
12
10
|
return @params[k]
|
13
11
|
end
|
14
12
|
|
@@ -22,8 +20,6 @@ module Rack
|
|
22
20
|
def response(password)
|
23
21
|
Rack::Auth::Digest::MD5.new(nil).send :digest, self, password
|
24
22
|
end
|
25
|
-
|
26
23
|
end
|
27
|
-
|
28
24
|
end
|
29
25
|
end
|