rack-test 0.6.3 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1a276395f953e48d223d387a9ca830fec7bc17f4
4
+ data.tar.gz: 75368392e7c13919d3073d9b69fb5c0e3c271b10
5
+ SHA512:
6
+ metadata.gz: 874eb9d53b22b2842d9659144acdc4bf222cb18474f4d8b496292e3209bf53d2564a2fcef5d9541dc81a825780766d48da46a1a7643ac8f04807fc41094bba11
7
+ data.tar.gz: 17b51e137c7bc2e2b59276bdaf90781dc6a701f082cd17b8faccbc179668c05914e34025474134ab87bd4e5a1c42821a07e0193665444062cfd77a6b24492e7a
@@ -1,179 +1,191 @@
1
- == 0.6.3 / 2015-01-09
1
+ ## 0.7.0 / 2017-07-10
2
2
 
3
+ * Major enhancements
4
+ * The project URL changed to https://github.com/rack-test/rack-test
5
+ (Per Lundberg, Dennis Sivia, Jun Aruga)
6
+ * Rack 2 compatible. (Trevor Wennblom #81, Vít Ondruch, Jun Aruga #151)
3
7
  * Minor enhancements
8
+ * Port to RSpec 3. (Murahashi [Matt] Kenichi #70, Antonio Terceiro #134)
9
+ * Add Travis CI (Johannes Barre #108, Jun Aruga #161)
10
+ * Don't append an ampersand when params are empty (sbilharz, #157)
11
+ * Allow symbol access to cookies (Anorlondo448 #156)
12
+ * README: Added Travis badge (Olivier Lacan, Per Lundberg #146)
13
+ * `Rack::Test::Utils#build_multipart`: Allow passing a third parameter
14
+ to force multipart (Koen Punt #142)
15
+ * Allow better testing of cookies (Stephen Best #133)
16
+ * make `build_multipart` work without mixing in `Rack::Test::Utils`
17
+ (Aaron Patterson #131)
18
+ * Add license to gemspec (Jordi Massaguer Pla #72, Anatol Pomozov #89,
19
+ Anatol Pomozov #90, Johannes Barre #109, Mandaryn #115,
20
+ Chris Marshall #120, Robert Reiz #126, Nic Benders #127, Nic Benders #130)
21
+ * Feature/bulk pr for readme updates (Patrick Mulder #65,
22
+ Troels Knak-Nielsen #74, Jeff Casimir #76)
23
+ * Switch README format to Markdown (Dennis Sivia #176)
24
+ * Convert History.txt to Markdown (Dennis Sivia #179)
25
+ * Stop generating gemspec file. (Jun Aruga #181)
26
+ * Fix errors at rake docs and whitespace. (Jun Aruga #183)
27
+ * Ensure Rack::Test::UploadedFile closes its tempfile file descriptor
28
+ on GC (Michael de Silva #180)
29
+ * Change codeclimate URL correctly. (Jun Aruga #186)
30
+ * Bug fixes
31
+ * Initialize digest_username before using it. (Guo Xiang Tan #116,
32
+ John Drago #124, Mike Perham #154)
33
+ * Do not set Content-Type for DELETE requests (David Celis #132)
34
+ * Adds support for empty arrays in params. (Cedric Röck, Tim Masliuchenko
35
+ #125)
36
+ * Update README code example quotes to be consistent. (Dmitry Gritsay #112)
37
+ * Update README not to recommend installing gem with sudo. (T.J. Schuck #87)
38
+ * Set scheme when using ENV to enable SSL (Neil Ang #155)
39
+ * Reuse request method and parameters on HTTP 307 redirect. (Martin Mauch
40
+ #138)
41
+
42
+ ## 0.6.3 / 2015-01-09
4
43
 
44
+ * Minor enhancements
5
45
  * Expose an env helper for persistently configuring the env as needed
6
46
  (Darío Javier Cravero #80)
7
47
  * Expose the tempfile of UploadedFile (Sytse Sijbrandij #67)
8
-
9
48
  * Bug fixes
10
-
11
49
  * Improve support for arrays of hashes in multipart forms (Murray Steele #69)
12
50
  * Improve test for query strings (Paul Grayson #66)
13
51
 
14
- == 0.6.2 / 2012-09-27
52
+ ## 0.6.2 / 2012-09-27
15
53
 
16
54
  * Minor enhancements
17
-
18
55
  * Support HTTP PATCH method (Marjan Krekoten' #33)
19
56
  * Preserve the exact query string when possible (Paul Grayson #63)
20
57
  * Add a #delete method to CookieJar (Paul Grayson #63)
21
-
22
58
  * Bug fixes
23
-
24
59
  * Fix HTTP Digest authentication when the URI has query params
25
60
  * Don't append default ports to HTTP_HOST (David Lee #57)
26
61
 
27
- == 0.6.1 / 2011-07-27
62
+ ## 0.6.1 / 2011-07-27
28
63
 
29
64
  * Bug fixes
30
-
31
65
  * Fix support for params with arrays in multipart forms (Joel Chippindale)
32
- * Add respond_to? to Rack::Test::UploadedFile to match method_missing (Josh Nichols)
66
+ * Add `respond_to?` to `Rack::Test::UploadedFile` to match `method_missing` (Josh Nichols)
33
67
  * Set the Referer header on requests issued by follow_redirect! (Ryan Bigg)
34
68
 
35
- == 0.6.0 / 2011-05-03
69
+ ## 0.6.0 / 2011-05-03
36
70
 
37
71
  * Bug fixes
38
-
39
72
  * Add support for HTTP OPTIONS verb (Paolo "Nusco" Perrotta)
40
73
  * Call #finish on MockResponses if it's available (Aaron Patterson)
41
74
  * Allow HTTP_HOST to be set via #header (Geoff Buesing)
42
75
 
43
- == 0.5.7 / 2011-01-01
44
-
76
+ ## 0.5.7 / 2011-01-01
45
77
  * Bug fixes
46
-
47
78
  * If no URI is present, include all cookies (Pratik Naik)
48
79
 
49
- == 0.5.6 / 2010-09-25
80
+ ## 0.5.6 / 2010-09-25
50
81
 
51
82
  * Bug fixes
52
-
53
83
  * Use parse_nested_query for parsing URI like Rack does (Eugene Bolshakov)
54
84
  * Don't depend on ActiveSupport extension to String (Bryan Helmkamp)
55
85
  * Do not overwrite HTTP_HOST if it is set (Krekoten' Marjan)
56
86
 
57
- == 0.5.5 / 2010-09-22
87
+ ## 0.5.5 / 2010-09-22
58
88
 
59
89
  * Bug fixes
60
-
61
90
  * Fix encoding of file uploads on Ruby 1.9 (Alan Kennedy)
62
91
  * Set env["HTTP_HOST"] when making requests (Istvan Hoka)
63
92
 
64
- == 0.5.4 / 2010-05-26
93
+ ## 0.5.4 / 2010-05-26
65
94
 
66
95
  * Bug fixes
67
-
68
96
  * Don't stomp on Content-Type's supplied via #header (Bryan Helmkamp)
69
97
  * Fixed build_multipart to allow for arrays of files (Louis Rose)
70
98
  * Don't raise an error if raw cookies contain a blank line (John Reilly)
71
99
  * Handle parameter names with brackets properly (Tanner Donovan)
72
100
 
73
- == 0.5.3 / 2009-11-27
101
+ ## 0.5.3 / 2009-11-27
74
102
 
75
103
  * Bug fixes
76
-
77
104
  * Fix cookie matching for subdomains (Marcin Kulik)
78
105
 
79
- == 0.5.2 / 2009-11-13
106
+ ## 0.5.2 / 2009-11-13
80
107
 
81
108
  * Bug fixes
82
-
83
109
  * Call close on response body after iteration, not before (Simon Rozet)
84
110
  * Add missing require for time in cookie_jar.rb (Jerry West)
85
111
 
86
- == 0.5.1 / 2009-10-27
112
+ ## 0.5.1 / 2009-10-27
87
113
 
88
114
  * Bug fixes
89
-
90
115
  * Escape cookie values (John Pignata)
91
116
  * Close the response body after each request, as per the Rack spec (Elomar França)
92
117
 
93
- == 0.5.0 / 2009-09-19
118
+ ## 0.5.0 / 2009-09-19
94
119
 
95
120
  * Bug fixes
96
-
97
121
  * Set HTTP_X_REQUESTED_WITH in the Rack env when a request is made with :xhr => true (Ben Sales)
98
122
  * Set headers in the Rack env in HTTP_USER_AGENT form
99
123
  * Rack::Test now generates no Ruby warnings
100
124
 
101
- == 0.4.2 / 2009-09-01
125
+ ## 0.4.2 / 2009-09-01
102
126
 
103
127
  * Minor enhancements
104
-
105
128
  * Merge in rack/master's build_multipart method which covers additional cases
106
129
  * Accept raw :params string input and merge it with the query string
107
130
  * Stringify and upcase request method (e.g. :post => "POST") (Josh Peek)
108
-
109
131
  * Bug fixes
110
-
111
132
  * Properly convert hashes with nil values (e.g. :foo => nil becomes simply "foo", not "foo=")
112
133
  * Prepend a slash to the URI path if it doesn't start with one (Josh Peek)
113
134
  * Requiring Rack-Test never modifies the Ruby load path anymore (Josh Peek)
114
135
  * Fixed using multiple cookies in a string on Ruby 1.8 (Tuomas Kareinen and Hermanni Hyytiälä)
115
136
 
116
- == 0.4.1 / 2009-08-06
137
+ ## 0.4.1 / 2009-08-06
117
138
 
118
139
  * Minor enhancements
119
-
120
- * Support initializing a Rack::Test::Session with an app in addition to
121
- a Rack::MockSession
140
+ * Support initializing a `Rack::Test::Session` with an app in addition to
141
+ a `Rack::MockSession`
122
142
  * Allow CONTENT_TYPE to be specified in the env and not overwritten when
123
143
  sending a POST or PUT
124
144
 
125
- == 0.4.0 / 2009-06-25
145
+ ## 0.4.0 / 2009-06-25
126
146
 
127
147
  * Minor enhancements
128
-
129
- * Expose hook for building Rack::MockSessions for frameworks that need
148
+ * Expose hook for building `Rack::MockSessions` for frameworks that need
130
149
  to configure them before use
131
150
  * Support passing in arrays of raw cookies in addition to a newline
132
151
  separated string
133
152
  * Support after_request callbacks in MockSession for things like running
134
153
  background jobs
135
154
  * Allow multiple named sessions using with_session
136
- * Initialize Rack::Test::Sessions with Rack::MockSessions instead of apps.
155
+ * Initialize `Rack::Test::Sessions` with `Rack::MockSessions` instead of apps.
137
156
  This change should help integration with other Ruby web frameworks
138
157
  (like Merb).
139
158
  * Support sending bodies for PUT requests (Larry Diehl)
140
159
 
141
- == 0.3.0 / 2009-05-17
160
+ ## 0.3.0 / 2009-05-17
142
161
 
143
162
  * Major enhancements
144
-
145
163
  * Ruby 1.9 compatible (Simon Rozet, Michael Fellinger)
146
-
147
164
  * Minor enhancements
148
-
149
- * Add CookieJar#[] and CookieJar#[]= methods
165
+ * Add `CookieJar#[]` and `CookieJar#[]=` methods
150
166
  * Make the default host configurable
151
- * Use Rack::Lint and fix errors (Simon Rozet)
152
- * Extract Rack::MockSession from Rack::Test::Session to handle tracking
167
+ * Use `Rack::Lint` and fix errors (Simon Rozet)
168
+ * Extract `Rack::MockSession` from `Rack::Test::Session` to handle tracking
153
169
  the last request and response and the cookie jar
154
170
  * Add #set_cookie and #clear_cookies methods
155
171
  * Rename #authorize to #basic_authorize (#authorize remains as an alias)
156
172
  (Simon Rozet)
157
173
 
158
- == 0.2.0 / 2009-04-26
174
+ ## 0.2.0 / 2009-04-26
159
175
 
160
- Because #last_response is now a MockResponse instead of a Rack::Response,
161
- #last_response.body now returns a string instead of an array.
176
+ Because `#last_response` is now a `MockResponse` instead of a `Rack::Response`, `#last_response.body`
177
+ now returns a string instead of an array.
162
178
 
163
179
  * Major enhancements
164
-
165
180
  * Support multipart requests via the UploadedFile class (thanks, Rails)
166
-
167
181
  * Minor enhancements
168
-
169
182
  * Updated for Rack 1.0
170
183
  * Don't require rubygems (See http://gist.github.com/54177)
171
- * Support HTTP Digest authentication with the #digest_authorize method
172
- * #last_response returns a MockResponse instead of a Response
184
+ * Support HTTP Digest authentication with the `#digest_authorize` method
185
+ * `#last_response` returns a `MockResponse` instead of a Response
173
186
  (Michael Fellinger)
174
187
 
175
- == 0.1.0 / 2009-03-02
188
+ ## 0.1.0 / 2009-03-02
176
189
 
177
190
  * 1 major enhancement
178
-
179
191
  * Birthday!
@@ -0,0 +1,110 @@
1
+ # Rack::Test
2
+ [<img src="https://travis-ci.org/rack-test/rack-test.svg?branch=master" />](https://travis-ci.org/rack-test/rack-test)
3
+ [<img src="https://codeclimate.com/github/rack-test/rack-test.png" />](https://codeclimate.com/github/rack-test/rack-test)
4
+ [<img src="https://codeclimate.com/github/rack-test/rack-test/coverage.png" />](https://codeclimate.com/github/rack-test/rack-test)
5
+
6
+ Code: https://github.com/rack-test/rack-test
7
+
8
+ ## Description
9
+
10
+ Rack::Test is a small, simple testing API for Rack apps. It can be used on its
11
+ own or as a reusable starting point for Web frameworks and testing libraries
12
+ to build on.
13
+
14
+ ## Features
15
+
16
+ * Maintains a cookie jar across requests
17
+ * Easily follow redirects when desired
18
+ * Set request headers to be used by all subsequent requests
19
+ * Small footprint. Approximately 200 LOC
20
+
21
+ ## Examples
22
+ ```ruby
23
+ require "test/unit"
24
+ require "rack/test"
25
+
26
+ class HomepageTest < Test::Unit::TestCase
27
+ include Rack::Test::Methods
28
+
29
+ def app
30
+ app = lambda { |env| [200, {'Content-Type' => 'text/plain'}, ['All responses are OK']] }
31
+ builder = Rack::Builder.new
32
+ builder.run app
33
+ end
34
+
35
+ def test_response_is_ok
36
+ get "/"
37
+
38
+ assert last_response.ok?
39
+ assert_equal last_response.body, "All responses are OK"
40
+ end
41
+
42
+ def set_request_headers
43
+ headers 'Accept-Charset', 'utf-8'
44
+ get "/"
45
+
46
+ assert last_response.ok?
47
+ assert_equal last_response.body, "All responses are OK"
48
+ end
49
+
50
+ def test_response_is_ok_for_other_paths
51
+ get "/other_paths"
52
+
53
+ assert last_response.ok?
54
+ assert_equal last_response.body, "All responses are OK"
55
+ end
56
+ end
57
+ ```
58
+
59
+ 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.
60
+
61
+ ```ruby
62
+ OUTER_APP = Rack::Builder.parse_file("config.ru").first
63
+
64
+ class TestApp < Test::Unit::TestCase
65
+ include Rack::Test::Methods
66
+
67
+ def app
68
+ OUTER_APP
69
+ end
70
+
71
+ def test_root
72
+ get "/"
73
+ assert last_response.ok?
74
+ end
75
+ end
76
+ ```
77
+
78
+
79
+ ## Install
80
+
81
+ To install the latest release as a gem:
82
+
83
+ `gem install rack-test`
84
+
85
+ Or via Bundler:
86
+
87
+ `gem "rack-test", require: "rack/test"`
88
+
89
+ ## Authors
90
+
91
+ - Contributions from Bryan Helmkamp, Simon Rozet, Pat Nakajima and others
92
+ - Much of the original code was extracted from Merb 1.0's request helper
93
+
94
+ ## License
95
+ `rack-test` is released under the [MIT License](MIT-LICENSE.txt).
96
+
97
+ ## Contribution
98
+
99
+ Contributions are welcome. Please make sure to:
100
+
101
+ * Use a regular forking workflow
102
+ * Write tests for the new or changed behaviour
103
+ * Provide an explanation/motivation in your commit message / PR message
104
+ * Ensure History.txt is updated
105
+
106
+ ## Releasing
107
+
108
+ * Ensure History.txt is up-to-date
109
+ * Bump VERSION in lib/rack/test/version.rb
110
+ * bundle exec thor :release
@@ -6,11 +6,10 @@ require "rack/test/mock_digest_request"
6
6
  require "rack/test/utils"
7
7
  require "rack/test/methods"
8
8
  require "rack/test/uploaded_file"
9
+ require "rack/test/version"
9
10
 
10
11
  module Rack
11
12
  module Test
12
- VERSION = "0.6.3"
13
-
14
13
  DEFAULT_HOST = "example.org"
15
14
  MULTIPART_BOUNDARY = "----------XnJLe9ZIbbGUYtzPQJ16u1"
16
15
 
@@ -36,6 +35,8 @@ module Rack
36
35
  def initialize(mock_session)
37
36
  @headers = {}
38
37
  @env = {}
38
+ @digest_username = nil
39
+ @digest_password = nil
39
40
 
40
41
  if mock_session.is_a?(MockSession)
41
42
  @rack_mock_session = mock_session
@@ -183,8 +184,11 @@ module Rack
183
184
  unless last_response.redirect?
184
185
  raise Error.new("Last response was not a redirect. Cannot follow_redirect!")
185
186
  end
186
-
187
- get(last_response["Location"], {}, { "HTTP_REFERER" => last_request.url })
187
+ if last_response.status == 307
188
+ send(last_request.request_method.downcase.to_sym, last_response["Location"], last_request.params, { "HTTP_REFERER" => last_request.url })
189
+ else
190
+ get(last_response["Location"], {}, { "HTTP_REFERER" => last_request.url })
191
+ end
188
192
  end
189
193
 
190
194
  private
@@ -205,12 +209,12 @@ module Rack
205
209
  # Stringifying and upcasing methods has be commit upstream
206
210
  env["REQUEST_METHOD"] ||= env[:method] ? env[:method].to_s.upcase : "GET"
207
211
 
208
- if env["REQUEST_METHOD"] == "GET"
212
+ if ["GET", "DELETE"].include?(env["REQUEST_METHOD"])
209
213
  # merge :params with the query string
210
214
  if params = env[:params]
211
215
  params = parse_nested_query(params) if params.is_a?(String)
212
- params.update(parse_nested_query(uri.query))
213
- uri.query = build_nested_query(params)
216
+
217
+ uri.query = [uri.query, build_nested_query(params)].compact.reject { |v| v == '' }.join("&")
214
218
  end
215
219
  elsif !env.has_key?(:input)
216
220
  env["CONTENT_TYPE"] ||= "application/x-www-form-urlencoded"
@@ -240,6 +244,7 @@ module Rack
240
244
  def process_request(uri, env)
241
245
  uri = URI.parse(uri)
242
246
  uri.host ||= @default_host
247
+ uri.scheme ||= "https" if env["HTTPS"] == "on"
243
248
 
244
249
  @rack_mock_session.request(uri, env)
245
250
 
@@ -48,6 +48,10 @@ module Rack
48
48
  @options.has_key?("secure")
49
49
  end
50
50
 
51
+ def http_only?
52
+ @options.has_key?('HttpOnly')
53
+ end
54
+
51
55
  # :api: private
52
56
  def path
53
57
  @options["path"].strip || "/"
@@ -87,6 +91,14 @@ module Rack
87
91
  # Orders the cookies from least specific to most
88
92
  [name, path, domain.reverse] <=> [other.name, other.path, other.domain.reverse]
89
93
  end
94
+ def to_h
95
+ @options.merge(
96
+ 'value' => @value,
97
+ 'HttpOnly' => http_only?,
98
+ 'secure' => secure?,
99
+ )
100
+ end
101
+ alias_method :to_hash, :to_h
90
102
 
91
103
  protected
92
104
 
@@ -108,13 +120,17 @@ module Rack
108
120
  def [](name)
109
121
  cookies = hash_for(nil)
110
122
  # TODO: Should be case insensitive
111
- cookies[name] && cookies[name].value
123
+ cookies[name.to_s] && cookies[name.to_s].value
112
124
  end
113
125
 
114
126
  def []=(name, value)
115
127
  merge("#{name}=#{Rack::Utils.escape(value)}")
116
128
  end
117
129
 
130
+ def get_cookie(name)
131
+ hash_for(nil).fetch(name,nil)
132
+ end
133
+
118
134
  def delete(name)
119
135
  @cookies.reject! do |cookie|
120
136
  cookie.name == name