rack-test 0.6.3 → 1.0.0

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