webmock 2.1.0 → 2.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +13 -5
- data/.travis.yml +1 -0
- data/CHANGELOG.md +18 -2
- data/Gemfile +0 -1
- data/README.md +6 -1
- data/lib/webmock/api.rb +1 -0
- data/lib/webmock/http_lib_adapters/curb_adapter.rb +1 -16
- data/lib/webmock/http_lib_adapters/excon_adapter.rb +2 -1
- data/lib/webmock/http_lib_adapters/httpclient_adapter.rb +79 -78
- data/lib/webmock/http_lib_adapters/net_http.rb +16 -1
- data/lib/webmock/rack_response.rb +1 -1
- data/lib/webmock/version.rb +1 -1
- data/spec/acceptance/curb/curb_spec.rb +23 -0
- data/spec/acceptance/em_http_request/em_http_request_spec_helper.rb +2 -1
- data/spec/acceptance/excon/excon_spec.rb +1 -1
- data/spec/acceptance/excon/excon_spec_helper.rb +2 -1
- data/spec/acceptance/httpclient/httpclient_spec.rb +4 -0
- data/spec/acceptance/net_http/net_http_spec_helper.rb +7 -1
- data/spec/acceptance/patron/patron_spec.rb +6 -22
- data/spec/spec_helper.rb +0 -3
- data/spec/unit/api_spec.rb +2 -2
- data/spec/unit/rack_response_spec.rb +10 -0
- data/test/shared_test.rb +9 -2
- data/webmock.gemspec +11 -15
- metadata +84 -95
checksums.yaml
CHANGED
@@ -1,7 +1,15 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
NDA0NGYxYjJmZGI0OTNjMjhlNDhjMWRkNTMwZWZlNTQ4ZjhkZDljOQ==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
MjgyODBlOWY3ODE1MmM0OTk4NDE5NzU1NjhkYzRiN2QwN2Q5MzZiNA==
|
5
7
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
ZjZiYWFmOTJjMDc3Yzk3Y2M1M2UxNzMyYWVkOWNiNTYyMWQzZTJhZDNmMjA3
|
10
|
+
ZjcxMjI5N2QzNTBhNTVlYzI4OTFlNjMyYTZlNjNiNjNkNmUxYThlYjQ1MzNm
|
11
|
+
YjlhMWI5YTE5OTZmYThiYTJhNTllOGRjNTkzYWEwY2U1M2M5ZmE=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
NjI2YzNjODk0ZDBmNTM4N2NkMmU1NGZkNDVlOWFiZTUwYmQ3NGE0ZDJmYWRj
|
14
|
+
OTNjYmE3MWQxMTdmMzMwYTY5NmI1MWE5ODQ4YWY5MGQ2YWIzYTQ0NWVjMmJk
|
15
|
+
NGFiZjYzZTc4MzM4MWNlYWFjOGMzMTIwODY1M2NlZjFmYmRmNzU=
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,21 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## 2.2.0
|
4
|
+
|
5
|
+
* Added `refute_requested` as an alias for `assert_not_requested`
|
6
|
+
|
7
|
+
Thanks to [Michael Grosser](https://github.com/grosser)
|
8
|
+
|
9
|
+
* Raising `Net::OpenTimeout` instead of `Timeout::Error` if available when a request stub is declared `to_timeout`
|
10
|
+
|
11
|
+
Thanks to [Gabe Martin-Dempesy](https://github.com/gabetax)
|
12
|
+
|
13
|
+
## 2.1.1
|
14
|
+
|
15
|
+
* Added support for handling status messages in Excon responses.
|
16
|
+
|
17
|
+
Thanks to [Tero Marttila](https://github.com/SpComb) for reporting the issue.
|
18
|
+
|
3
19
|
## 2.1.0
|
4
20
|
|
5
21
|
* Added support for `on_debug` callback in Curb.
|
@@ -103,8 +119,8 @@
|
|
103
119
|
|
104
120
|
Thanks to [Alex Kestner](https://github.com/akestner)
|
105
121
|
|
106
|
-
* Added a clear message on an
|
107
|
-
WebMock
|
122
|
+
* Added a clear message on an attempt to match a multipart encoded request body.
|
123
|
+
WebMock doesn't support requests with multipart body... yet.
|
108
124
|
|
109
125
|
* `WebMock.disable_net_connect` `:allow` option, provided as regexp, matches https URIs correctly.
|
110
126
|
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -218,7 +218,7 @@ Net::HTTP.start('www.example.com') do |http|
|
|
218
218
|
end # ===> Success
|
219
219
|
```
|
220
220
|
|
221
|
-
##### Important! Since version 2.0.0, WebMock does not match credentials provided in Authorization header and credentials provided in the userinfo of a url. I.e. `stub_request(:get, "user:pass@www.example.com")` does not match a request with credentials provided in the
|
221
|
+
##### Important! Since version 2.0.0, WebMock does not match credentials provided in Authorization header and credentials provided in the userinfo of a url. I.e. `stub_request(:get, "user:pass@www.example.com")` does not match a request with credentials provided in the Authorization header.
|
222
222
|
|
223
223
|
### Request with basic authentication in the url
|
224
224
|
|
@@ -1021,6 +1021,11 @@ People who submitted patches and new features or suggested improvements. Many th
|
|
1021
1021
|
* Jose Luis Honorato
|
1022
1022
|
* Aaron Kromer
|
1023
1023
|
* Pavel Jurašek
|
1024
|
+
* Jake Worth
|
1025
|
+
* Gabe Martin-Dempesy
|
1026
|
+
* Michael Grosser
|
1027
|
+
* Aleksei Maridashvili
|
1028
|
+
* Ville Lautanala
|
1024
1029
|
|
1025
1030
|
For a full list of contributors you can visit the
|
1026
1031
|
[contributors](https://github.com/bblimke/webmock/contributors) page.
|
data/lib/webmock/api.rb
CHANGED
@@ -88,12 +88,10 @@ if defined?(Curl)
|
|
88
88
|
headers = headers_as_hash(self.headers).merge(basic_auth_headers)
|
89
89
|
|
90
90
|
request_body = case method
|
91
|
-
when :post
|
91
|
+
when :post, :patch
|
92
92
|
self.post_body || @post_body
|
93
93
|
when :put
|
94
94
|
@put_data
|
95
|
-
when :patch
|
96
|
-
@patch_data
|
97
95
|
else
|
98
96
|
nil
|
99
97
|
end
|
@@ -263,13 +261,6 @@ if defined?(Curl)
|
|
263
261
|
end
|
264
262
|
alias put http_put
|
265
263
|
|
266
|
-
def http_patch data = nil
|
267
|
-
@webmock_method = :patch
|
268
|
-
@patch_data = data if data
|
269
|
-
super
|
270
|
-
end
|
271
|
-
alias patch http_patch
|
272
|
-
|
273
264
|
def http_post *data
|
274
265
|
@webmock_method = :post
|
275
266
|
@post_body = data.join('&') if data && !data.empty?
|
@@ -288,12 +279,6 @@ if defined?(Curl)
|
|
288
279
|
super
|
289
280
|
end
|
290
281
|
|
291
|
-
def patch_data= data
|
292
|
-
@webmock_method = :patch
|
293
|
-
@patch_data = data
|
294
|
-
super
|
295
|
-
end
|
296
|
-
|
297
282
|
def post_body= data
|
298
283
|
@webmock_method = :post
|
299
284
|
super
|
@@ -130,13 +130,14 @@ if defined?(Excon)
|
|
130
130
|
{
|
131
131
|
body: mock.body,
|
132
132
|
status: mock.status[0].to_i,
|
133
|
+
reason_phrase: mock.status[1],
|
133
134
|
headers: mock.headers || {}
|
134
135
|
}
|
135
136
|
end
|
136
137
|
|
137
138
|
def self.mock_response(real)
|
138
139
|
mock = WebMock::Response.new
|
139
|
-
mock.status = real.status
|
140
|
+
mock.status = [real.status, real.reason_phrase]
|
140
141
|
mock.headers = real.headers
|
141
142
|
mock.body = real.body.dup
|
142
143
|
mock
|
@@ -121,110 +121,111 @@ if defined?(::HTTPClient)
|
|
121
121
|
|
122
122
|
response
|
123
123
|
end
|
124
|
-
end
|
125
124
|
|
126
|
-
|
127
|
-
|
128
|
-
|
125
|
+
def build_webmock_response(httpclient_response, body = nil)
|
126
|
+
webmock_response = WebMock::Response.new
|
127
|
+
webmock_response.status = [httpclient_response.status, httpclient_response.reason]
|
129
128
|
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
129
|
+
webmock_response.headers = {}.tap do |hash|
|
130
|
+
httpclient_response.header.all.each do |(key, value)|
|
131
|
+
if hash.has_key?(key)
|
132
|
+
hash[key] = Array(hash[key]) + [value]
|
133
|
+
else
|
134
|
+
hash[key] = value
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
137
138
|
|
138
|
-
|
139
|
+
if body
|
140
|
+
webmock_response.body = body
|
141
|
+
elsif httpclient_response.content.respond_to?(:read)
|
142
|
+
webmock_response.body = httpclient_response.content.read
|
143
|
+
body = HTTP::Message::Body.new
|
144
|
+
body.init_response(StringIO.new(webmock_response.body))
|
145
|
+
httpclient_response.body = body
|
146
|
+
else
|
147
|
+
webmock_response.body = httpclient_response.content
|
148
|
+
end
|
149
|
+
webmock_response
|
139
150
|
end
|
140
|
-
end
|
141
151
|
|
142
|
-
|
143
|
-
|
144
|
-
|
152
|
+
def build_request_signature(req, reuse_existing = false)
|
153
|
+
uri = WebMock::Util::URI.heuristic_parse(req.header.request_uri.to_s)
|
154
|
+
uri.query = WebMock::Util::QueryMapper.values_to_query(req.header.request_query, notation: WebMock::Config.instance.query_values_notation) if req.header.request_query
|
155
|
+
uri.port = req.header.request_uri.port
|
145
156
|
|
146
|
-
|
147
|
-
|
148
|
-
if hash.has_key?(key)
|
149
|
-
hash[key] = Array(hash[key]) + [value]
|
150
|
-
else
|
151
|
-
hash[key] = value
|
152
|
-
end
|
157
|
+
@request_filter.each do |filter|
|
158
|
+
filter.filter_request(req)
|
153
159
|
end
|
154
|
-
end
|
155
160
|
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
161
|
+
headers = req.header.all.inject({}) do |hdrs, header|
|
162
|
+
hdrs[header[0]] ||= []
|
163
|
+
hdrs[header[0]] << header[1]
|
164
|
+
hdrs
|
165
|
+
end
|
166
|
+
headers = headers_from_session(uri).merge(headers)
|
167
|
+
|
168
|
+
signature = WebMock::RequestSignature.new(
|
169
|
+
req.header.request_method.downcase.to_sym,
|
170
|
+
uri.to_s,
|
171
|
+
body: req.http_body.dump,
|
172
|
+
headers: headers
|
173
|
+
)
|
174
|
+
|
175
|
+
# reuse a previous identical signature object if we stored one for later use
|
176
|
+
if reuse_existing && previous_signature = previous_signature_for(signature)
|
177
|
+
return previous_signature
|
178
|
+
end
|
168
179
|
|
169
|
-
|
170
|
-
|
171
|
-
uri.query = WebMock::Util::QueryMapper.values_to_query(req.header.request_query, notation: WebMock::Config.instance.query_values_notation) if req.header.request_query
|
172
|
-
uri.port = req.header.request_uri.port
|
180
|
+
signature
|
181
|
+
end
|
173
182
|
|
174
|
-
|
175
|
-
|
183
|
+
def webmock_responses
|
184
|
+
@webmock_responses ||= Hash.new do |hash, request_signature|
|
185
|
+
hash[request_signature] = WebMock::StubRegistry.instance.response_for_request(request_signature)
|
186
|
+
end
|
176
187
|
end
|
177
188
|
|
178
|
-
|
179
|
-
|
180
|
-
hdrs[header[0]] << header[1]
|
181
|
-
hdrs
|
189
|
+
def webmock_request_signatures
|
190
|
+
@webmock_request_signatures ||= []
|
182
191
|
end
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
uri.to_s,
|
188
|
-
body: req.http_body.dump,
|
189
|
-
headers: headers
|
190
|
-
)
|
191
|
-
|
192
|
-
# reuse a previous identical signature object if we stored one for later use
|
193
|
-
if reuse_existing && previous_signature = previous_signature_for(signature)
|
194
|
-
return previous_signature
|
192
|
+
|
193
|
+
def previous_signature_for(signature)
|
194
|
+
return nil unless index = webmock_request_signatures.index(signature)
|
195
|
+
webmock_request_signatures.delete_at(index)
|
195
196
|
end
|
196
197
|
|
197
|
-
|
198
|
-
end
|
198
|
+
private
|
199
199
|
|
200
|
-
|
201
|
-
|
202
|
-
|
200
|
+
# some of the headers sent by HTTPClient are derived from
|
201
|
+
# the client session
|
202
|
+
def headers_from_session(uri)
|
203
|
+
session_headers = HTTP::Message::Headers.new
|
204
|
+
@session_manager.send(:open, uri).send(:set_header, MessageMock.new(session_headers))
|
205
|
+
session_headers.all.inject({}) do |hdrs, header|
|
206
|
+
hdrs[header[0]] = header[1]
|
207
|
+
hdrs
|
208
|
+
end
|
203
209
|
end
|
204
210
|
end
|
205
211
|
|
206
|
-
|
207
|
-
|
208
|
-
|
212
|
+
class WebMockHTTPClient < HTTPClient
|
213
|
+
alias_method :do_get_block_without_webmock, :do_get_block
|
214
|
+
alias_method :do_get_stream_without_webmock, :do_get_stream
|
209
215
|
|
210
|
-
|
211
|
-
return nil unless index = webmock_request_signatures.index(signature)
|
212
|
-
webmock_request_signatures.delete_at(index)
|
216
|
+
include WebMockHTTPClients
|
213
217
|
end
|
214
218
|
|
215
|
-
|
219
|
+
if defined? ::JSONClient
|
220
|
+
class WebMockJSONClient < JSONClient
|
221
|
+
alias_method :do_get_block_without_webmock, :do_get_block
|
222
|
+
alias_method :do_get_stream_without_webmock, :do_get_stream
|
216
223
|
|
217
|
-
|
218
|
-
# the client session
|
219
|
-
def headers_from_session(uri)
|
220
|
-
session_headers = HTTP::Message::Headers.new
|
221
|
-
@session_manager.send(:open, uri).send(:set_header, MessageMock.new(session_headers))
|
222
|
-
session_headers.all.inject({}) do |hdrs, header|
|
223
|
-
hdrs[header[0]] = header[1]
|
224
|
-
hdrs
|
224
|
+
include WebMockHTTPClients
|
225
225
|
end
|
226
226
|
end
|
227
227
|
|
228
|
+
|
228
229
|
# Mocks a HTTPClient HTTP::Message
|
229
230
|
class MessageMock
|
230
231
|
attr_reader :header
|
@@ -168,7 +168,9 @@ module WebMock
|
|
168
168
|
|
169
169
|
response.extend Net::WebMockHTTPResponse
|
170
170
|
|
171
|
-
|
171
|
+
if webmock_response.should_timeout
|
172
|
+
raise timeout_exception, "execution expired"
|
173
|
+
end
|
172
174
|
|
173
175
|
webmock_response.raise_error_if_any
|
174
176
|
|
@@ -177,6 +179,19 @@ module WebMock
|
|
177
179
|
response
|
178
180
|
end
|
179
181
|
|
182
|
+
def timeout_exception
|
183
|
+
if defined?(Net::OpenTimeout)
|
184
|
+
# Ruby 2.x
|
185
|
+
Net::OpenTimeout
|
186
|
+
elsif defined?(Net::HTTP::OpenTimeout)
|
187
|
+
# Ruby 1.9
|
188
|
+
Net::HTTP::OpenTimeout
|
189
|
+
else
|
190
|
+
# Fallback, if things change
|
191
|
+
Timeout::Error
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
180
195
|
def build_webmock_response(net_http_response)
|
181
196
|
webmock_response = WebMock::Response.new
|
182
197
|
webmock_response.status = [
|
data/lib/webmock/version.rb
CHANGED
@@ -382,6 +382,29 @@ unless RUBY_PLATFORM =~ /java/
|
|
382
382
|
c.http(:GET)
|
383
383
|
expect(c.body).to eq("abc")
|
384
384
|
end
|
385
|
+
|
386
|
+
describe 'match request body' do
|
387
|
+
it 'for post' do
|
388
|
+
stub_request(:post, "www.example.com").with(body: 'foo=nhe').to_return(body: "abc")
|
389
|
+
|
390
|
+
response = Curl.post("http://www.example.com", {foo: :nhe})
|
391
|
+
expect(response.body_str).to eq("abc")
|
392
|
+
end
|
393
|
+
|
394
|
+
it 'for patch' do
|
395
|
+
stub_request(:patch, "www.example.com").with(body: 'foo=nhe').to_return(body: "abc")
|
396
|
+
|
397
|
+
response = Curl.patch("http://www.example.com", {foo: :nhe})
|
398
|
+
expect(response.body_str).to eq("abc")
|
399
|
+
end
|
400
|
+
|
401
|
+
it 'for put' do
|
402
|
+
stub_request(:put, "www.example.com").with(body: 'foo=nhe').to_return(body: "abc")
|
403
|
+
|
404
|
+
response = Curl.put("http://www.example.com", {foo: :nhe})
|
405
|
+
expect(response.body_str).to eq("abc")
|
406
|
+
end
|
407
|
+
end
|
385
408
|
end
|
386
409
|
|
387
410
|
describe "using #http_* methods for requests" do
|
@@ -4,7 +4,7 @@ require 'acceptance/excon/excon_spec_helper'
|
|
4
4
|
|
5
5
|
describe "Excon" do
|
6
6
|
include ExconSpecHelper
|
7
|
-
include_context "with WebMock", :
|
7
|
+
include_context "with WebMock", :no_url_auth
|
8
8
|
|
9
9
|
it 'should allow Excon requests to use query hash paramters' do
|
10
10
|
stub_request(:get, "http://example.com/resource/?a=1&b=2").to_return(body: "abc")
|
@@ -4,6 +4,7 @@ module ExconSpecHelper
|
|
4
4
|
|
5
5
|
def http_request(method, uri, options = {}, &block)
|
6
6
|
Excon.defaults[:ssl_verify_peer] = false
|
7
|
+
Excon.defaults[:ciphers] = 'DEFAULT'
|
7
8
|
uri = Addressable::URI.heuristic_parse(uri)
|
8
9
|
uri = uri.to_s.gsub(' ', '%20')
|
9
10
|
|
@@ -31,7 +32,7 @@ module ExconSpecHelper
|
|
31
32
|
body: response.body,
|
32
33
|
headers: headers,
|
33
34
|
status: response.status.to_s,
|
34
|
-
message:
|
35
|
+
message: response.reason_phrase
|
35
36
|
end
|
36
37
|
|
37
38
|
def client_timeout_exception_class
|
@@ -125,6 +125,10 @@ describe "HTTPClient" do
|
|
125
125
|
before { WebMock.allow_net_connect! }
|
126
126
|
|
127
127
|
it 'invokes the global_stub_request hook for each request' do
|
128
|
+
# Mock time to ensure that date headers match
|
129
|
+
now = Time.now
|
130
|
+
allow(Time).to receive(:now).and_return(now)
|
131
|
+
|
128
132
|
request_signatures = []
|
129
133
|
WebMock.globally_stub_request do |request_sig|
|
130
134
|
request_signatures << request_sig
|
@@ -45,7 +45,13 @@ module NetHTTPSpecHelper
|
|
45
45
|
end
|
46
46
|
|
47
47
|
def client_timeout_exception_class
|
48
|
-
|
48
|
+
if defined?(Net::OpenTimeout)
|
49
|
+
Net::OpenTimeout
|
50
|
+
elsif defined?(Net::HTTP::OpenTimeout)
|
51
|
+
Net::HTTP::OpenTimeout
|
52
|
+
else
|
53
|
+
Timeout::Error
|
54
|
+
end
|
49
55
|
end
|
50
56
|
|
51
57
|
def connection_refused_exception_class
|
@@ -95,38 +95,22 @@ unless RUBY_PLATFORM =~ /java/
|
|
95
95
|
Encoding.default_internal = @encoding
|
96
96
|
end
|
97
97
|
|
98
|
-
it "should encode body with default encoding" do
|
98
|
+
it "should not encode body with default encoding" do
|
99
99
|
stub_request(:get, "www.example.com").
|
100
100
|
to_return(body: "Øl")
|
101
101
|
|
102
|
-
expect(@sess.get("").body.encoding).to eq(Encoding::
|
102
|
+
expect(@sess.get("").body.encoding).to eq(Encoding::ASCII_8BIT)
|
103
|
+
expect(@sess.get("").inspectable_body.encoding).to eq(Encoding::UTF_8)
|
103
104
|
end
|
104
105
|
|
105
|
-
it "should encode body to default internal" do
|
106
|
+
it "should not encode body to default internal" do
|
106
107
|
stub_request(:get, "www.example.com").
|
107
108
|
to_return(headers: {'Content-Type' => 'text/html; charset=iso-8859-1'},
|
108
109
|
body: "Øl".encode("iso-8859-1"))
|
109
110
|
|
110
|
-
expect(@sess.get("").body.encoding).to eq(Encoding
|
111
|
+
expect(@sess.get("").body.encoding).to eq(Encoding::ASCII_8BIT)
|
112
|
+
expect(@sess.get("").decoded_body.encoding).to eq(Encoding.default_internal)
|
111
113
|
end
|
112
|
-
|
113
|
-
it "should encode body based on encoding-attribute in body" do
|
114
|
-
stub_request(:get, "www.example.com").
|
115
|
-
to_return(body: "<?xml encoding=\"iso-8859-1\">Øl</xml>".encode("iso-8859-1"))
|
116
|
-
|
117
|
-
expect(@sess.get("").body.encoding).to eq(Encoding::ISO_8859_1)
|
118
|
-
end
|
119
|
-
|
120
|
-
|
121
|
-
it "should encode body based on Session#default_response_charset" do
|
122
|
-
stub_request(:get, "www.example.com").
|
123
|
-
to_return(body: "Øl".encode("iso-8859-1"))
|
124
|
-
|
125
|
-
@sess.default_response_charset = "iso-8859-1"
|
126
|
-
|
127
|
-
expect(@sess.get("").body.encoding).to eq(Encoding::ISO_8859_1)
|
128
|
-
end
|
129
|
-
|
130
114
|
end
|
131
115
|
end
|
132
116
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -21,9 +21,6 @@ require 'support/webmock_server'
|
|
21
21
|
require 'support/my_rack_app'
|
22
22
|
require 'support/failures'
|
23
23
|
|
24
|
-
require 'simplecov'
|
25
|
-
SimpleCov.start
|
26
|
-
|
27
24
|
CURL_EXAMPLE_OUTPUT_PATH = File.expand_path('../support/example_curl_output.txt', __FILE__)
|
28
25
|
|
29
26
|
RSpec.configure do |config|
|
data/spec/unit/api_spec.rb
CHANGED
@@ -43,7 +43,7 @@ describe WebMock::API do
|
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
46
|
-
context "when args are an
|
46
|
+
context "when args are an empty hash" do
|
47
47
|
subject {klass.new.hash_including({})}
|
48
48
|
|
49
49
|
it "creates 'HashIncludingMatcher' with an empty hash" do
|
@@ -72,4 +72,4 @@ describe WebMock::API do
|
|
72
72
|
end
|
73
73
|
|
74
74
|
end
|
75
|
-
end
|
75
|
+
end
|
@@ -14,6 +14,16 @@ describe WebMock::RackResponse do
|
|
14
14
|
expect(response.body).to include('This is my root!')
|
15
15
|
end
|
16
16
|
|
17
|
+
it "should set the reason phrase based on the status code" do
|
18
|
+
request = WebMock::RequestSignature.new(:get, 'www.example.com')
|
19
|
+
response = @rack_response.evaluate(request)
|
20
|
+
expect(response.status).to eq([200, "OK"])
|
21
|
+
|
22
|
+
request = WebMock::RequestSignature.new(:get, 'www.example.com/error')
|
23
|
+
response = @rack_response.evaluate(request)
|
24
|
+
expect(response.status).to eq([500, "Internal Server Error"])
|
25
|
+
end
|
26
|
+
|
17
27
|
it "should behave correctly when the rack response is not a simple array of strings" do
|
18
28
|
request = WebMock::RequestSignature.new(:get, 'www.example.com/non_array_response')
|
19
29
|
response = @rack_response.evaluate(request)
|
data/test/shared_test.rb
CHANGED
@@ -22,7 +22,6 @@ module SharedTest
|
|
22
22
|
end
|
23
23
|
|
24
24
|
def test_error_on_non_stubbed_request
|
25
|
-
default_ruby_headers = (RUBY_VERSION >= "1.9.1") ? "{'Accept'=>'*/*', 'User-Agent'=>'Ruby'}" : "{'Accept'=>'*/*'}"
|
26
25
|
assert_raise_with_message(WebMock::NetConnectNotAllowedError, %r{Real HTTP connections are disabled. Unregistered request: GET http://www.example.net/ with headers}) do
|
27
26
|
http_request(:get, "http://www.example.net/")
|
28
27
|
end
|
@@ -48,7 +47,7 @@ module SharedTest
|
|
48
47
|
end
|
49
48
|
end
|
50
49
|
|
51
|
-
def
|
50
|
+
def test_verification_that_expected_stub_didnt_occur
|
52
51
|
expected_message = "The request ANY http://www.example.com/ was expected to execute 1 time but it executed 0 times"
|
53
52
|
expected_message << "\n\nThe following requests were made:\n\nNo requests were made.\n============================================================"
|
54
53
|
assert_fail(expected_message) do
|
@@ -78,6 +77,14 @@ module SharedTest
|
|
78
77
|
end
|
79
78
|
end
|
80
79
|
|
80
|
+
def test_refute_requested_alias
|
81
|
+
expected_message = %r(The request GET http://www.example.com/ was not expected to execute but it executed 1 time\n\nThe following requests were made:\n\nGET http://www.example.com/ with headers .+ was made 1 time\n\n============================================================)
|
82
|
+
assert_fail(expected_message) do
|
83
|
+
http_request(:get, "http://www.example.com/")
|
84
|
+
refute_requested(:get, "http://www.example.com")
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
81
88
|
def test_verification_that_non_expected_stub_didnt_occur
|
82
89
|
expected_message = %r(The request ANY http://www.example.com/ was not expected to execute but it executed 1 time\n\nThe following requests were made:\n\nGET http://www.example.com/ with headers .+ was made 1 time\n\n============================================================)
|
83
90
|
assert_fail(expected_message) do
|
data/webmock.gemspec
CHANGED
@@ -17,34 +17,30 @@ Gem::Specification.new do |s|
|
|
17
17
|
|
18
18
|
s.required_ruby_version = '>= 1.9.3'
|
19
19
|
|
20
|
-
s.add_dependency 'addressable', '>= 2.3.6'
|
21
|
-
s.add_dependency 'crack', '>=0.3.2'
|
20
|
+
s.add_dependency 'addressable', '>= 2.3.6', ('<= 2.4.0' if RUBY_VERSION <= '1.9.3')
|
21
|
+
s.add_dependency 'crack', '>= 0.3.2'
|
22
22
|
s.add_dependency 'hashdiff'
|
23
23
|
|
24
|
+
unless RUBY_PLATFORM =~ /java/
|
25
|
+
s.add_development_dependency 'patron', '>= 0.4.18'
|
26
|
+
s.add_development_dependency 'curb', '>= 0.7.16'
|
27
|
+
s.add_development_dependency 'typhoeus', '>= 0.5.0'
|
28
|
+
end
|
29
|
+
|
30
|
+
s.add_development_dependency 'http', ((RUBY_VERSION <= '1.9.3') ? '0.7.3' : '>= 0.8.0')
|
31
|
+
s.add_development_dependency 'manticore', '>= 0.5.1' if RUBY_PLATFORM =~ /java/
|
32
|
+
s.add_development_dependency 'rack', ((RUBY_VERSION < '2.2.2') ? '1.6.0' : '> 1.6')
|
24
33
|
s.add_development_dependency 'rspec', '>= 3.1.0'
|
25
34
|
s.add_development_dependency 'httpclient', '>= 2.2.4'
|
26
|
-
s.add_development_dependency 'patron', '>= 0.4.18' unless RUBY_PLATFORM =~ /java/
|
27
35
|
s.add_development_dependency 'em-http-request', '>= 1.0.2'
|
28
|
-
s.add_development_dependency 'http', ((RUBY_VERSION <= '1.9.3') ? '0.7.3' : '>= 0.8.0')
|
29
36
|
s.add_development_dependency 'em-synchrony', '>= 1.0.0'
|
30
|
-
s.add_development_dependency 'curb', '>= 0.7.16' unless RUBY_PLATFORM =~ /java/
|
31
|
-
s.add_development_dependency 'typhoeus', '>= 0.5.0' unless RUBY_PLATFORM =~ /java/
|
32
|
-
s.add_development_dependency 'manticore', '>= 0.5.1' if RUBY_PLATFORM =~ /java/
|
33
37
|
s.add_development_dependency 'excon', '>= 0.27.5'
|
34
38
|
s.add_development_dependency 'minitest', '>= 5.0.0'
|
35
39
|
s.add_development_dependency 'test-unit', '>= 3.0.0'
|
36
40
|
s.add_development_dependency 'rdoc', '> 3.5.0'
|
37
|
-
s.add_development_dependency 'rack'
|
38
|
-
s.add_development_dependency 'simplecov'
|
39
41
|
|
40
42
|
s.files = `git ls-files`.split("\n")
|
41
43
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
42
44
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
43
45
|
s.require_paths = ['lib']
|
44
|
-
|
45
|
-
s.post_install_message = <<-EOM
|
46
|
-
|
47
|
-
WebMock 2.0 has some breaking changes. Please check the CHANGELOG: https://goo.gl/piDGLu
|
48
|
-
|
49
|
-
EOM
|
50
46
|
end
|
metadata
CHANGED
@@ -1,253 +1,245 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: webmock
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bartosz Blimke
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-12-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: addressable
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ! '>='
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: 2.3.6
|
20
|
+
- - <=
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 2.4.0
|
20
23
|
type: :runtime
|
21
24
|
prerelease: false
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
23
26
|
requirements:
|
24
|
-
- -
|
27
|
+
- - ! '>='
|
25
28
|
- !ruby/object:Gem::Version
|
26
29
|
version: 2.3.6
|
30
|
+
- - <=
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 2.4.0
|
27
33
|
- !ruby/object:Gem::Dependency
|
28
34
|
name: crack
|
29
35
|
requirement: !ruby/object:Gem::Requirement
|
30
36
|
requirements:
|
31
|
-
- -
|
37
|
+
- - ! '>='
|
32
38
|
- !ruby/object:Gem::Version
|
33
39
|
version: 0.3.2
|
34
40
|
type: :runtime
|
35
41
|
prerelease: false
|
36
42
|
version_requirements: !ruby/object:Gem::Requirement
|
37
43
|
requirements:
|
38
|
-
- -
|
44
|
+
- - ! '>='
|
39
45
|
- !ruby/object:Gem::Version
|
40
46
|
version: 0.3.2
|
41
47
|
- !ruby/object:Gem::Dependency
|
42
48
|
name: hashdiff
|
43
49
|
requirement: !ruby/object:Gem::Requirement
|
44
50
|
requirements:
|
45
|
-
- -
|
51
|
+
- - ! '>='
|
46
52
|
- !ruby/object:Gem::Version
|
47
53
|
version: '0'
|
48
54
|
type: :runtime
|
49
55
|
prerelease: false
|
50
56
|
version_requirements: !ruby/object:Gem::Requirement
|
51
57
|
requirements:
|
52
|
-
- -
|
58
|
+
- - ! '>='
|
53
59
|
- !ruby/object:Gem::Version
|
54
60
|
version: '0'
|
55
61
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
62
|
+
name: patron
|
57
63
|
requirement: !ruby/object:Gem::Requirement
|
58
64
|
requirements:
|
59
|
-
- -
|
65
|
+
- - ! '>='
|
60
66
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
67
|
+
version: 0.4.18
|
62
68
|
type: :development
|
63
69
|
prerelease: false
|
64
70
|
version_requirements: !ruby/object:Gem::Requirement
|
65
71
|
requirements:
|
66
|
-
- -
|
72
|
+
- - ! '>='
|
67
73
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
74
|
+
version: 0.4.18
|
69
75
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
76
|
+
name: curb
|
71
77
|
requirement: !ruby/object:Gem::Requirement
|
72
78
|
requirements:
|
73
|
-
- -
|
79
|
+
- - ! '>='
|
74
80
|
- !ruby/object:Gem::Version
|
75
|
-
version:
|
81
|
+
version: 0.7.16
|
76
82
|
type: :development
|
77
83
|
prerelease: false
|
78
84
|
version_requirements: !ruby/object:Gem::Requirement
|
79
85
|
requirements:
|
80
|
-
- -
|
86
|
+
- - ! '>='
|
81
87
|
- !ruby/object:Gem::Version
|
82
|
-
version:
|
88
|
+
version: 0.7.16
|
83
89
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
90
|
+
name: typhoeus
|
85
91
|
requirement: !ruby/object:Gem::Requirement
|
86
92
|
requirements:
|
87
|
-
- -
|
93
|
+
- - ! '>='
|
88
94
|
- !ruby/object:Gem::Version
|
89
|
-
version: 0.
|
95
|
+
version: 0.5.0
|
90
96
|
type: :development
|
91
97
|
prerelease: false
|
92
98
|
version_requirements: !ruby/object:Gem::Requirement
|
93
99
|
requirements:
|
94
|
-
- -
|
100
|
+
- - ! '>='
|
95
101
|
- !ruby/object:Gem::Version
|
96
|
-
version: 0.
|
102
|
+
version: 0.5.0
|
97
103
|
- !ruby/object:Gem::Dependency
|
98
|
-
name:
|
104
|
+
name: http
|
99
105
|
requirement: !ruby/object:Gem::Requirement
|
100
106
|
requirements:
|
101
|
-
- -
|
107
|
+
- - '='
|
102
108
|
- !ruby/object:Gem::Version
|
103
|
-
version:
|
109
|
+
version: 0.7.3
|
104
110
|
type: :development
|
105
111
|
prerelease: false
|
106
112
|
version_requirements: !ruby/object:Gem::Requirement
|
107
113
|
requirements:
|
108
|
-
- -
|
114
|
+
- - '='
|
109
115
|
- !ruby/object:Gem::Version
|
110
|
-
version:
|
116
|
+
version: 0.7.3
|
111
117
|
- !ruby/object:Gem::Dependency
|
112
|
-
name:
|
118
|
+
name: rack
|
113
119
|
requirement: !ruby/object:Gem::Requirement
|
114
120
|
requirements:
|
115
|
-
- -
|
121
|
+
- - '='
|
116
122
|
- !ruby/object:Gem::Version
|
117
|
-
version:
|
123
|
+
version: 1.6.0
|
118
124
|
type: :development
|
119
125
|
prerelease: false
|
120
126
|
version_requirements: !ruby/object:Gem::Requirement
|
121
127
|
requirements:
|
122
|
-
- -
|
128
|
+
- - '='
|
123
129
|
- !ruby/object:Gem::Version
|
124
|
-
version:
|
130
|
+
version: 1.6.0
|
125
131
|
- !ruby/object:Gem::Dependency
|
126
|
-
name:
|
132
|
+
name: rspec
|
127
133
|
requirement: !ruby/object:Gem::Requirement
|
128
134
|
requirements:
|
129
|
-
- -
|
135
|
+
- - ! '>='
|
130
136
|
- !ruby/object:Gem::Version
|
131
|
-
version: 1.0
|
137
|
+
version: 3.1.0
|
132
138
|
type: :development
|
133
139
|
prerelease: false
|
134
140
|
version_requirements: !ruby/object:Gem::Requirement
|
135
141
|
requirements:
|
136
|
-
- -
|
142
|
+
- - ! '>='
|
137
143
|
- !ruby/object:Gem::Version
|
138
|
-
version: 1.0
|
144
|
+
version: 3.1.0
|
139
145
|
- !ruby/object:Gem::Dependency
|
140
|
-
name:
|
146
|
+
name: httpclient
|
141
147
|
requirement: !ruby/object:Gem::Requirement
|
142
148
|
requirements:
|
143
|
-
- -
|
149
|
+
- - ! '>='
|
144
150
|
- !ruby/object:Gem::Version
|
145
|
-
version:
|
151
|
+
version: 2.2.4
|
146
152
|
type: :development
|
147
153
|
prerelease: false
|
148
154
|
version_requirements: !ruby/object:Gem::Requirement
|
149
155
|
requirements:
|
150
|
-
- -
|
156
|
+
- - ! '>='
|
151
157
|
- !ruby/object:Gem::Version
|
152
|
-
version:
|
158
|
+
version: 2.2.4
|
153
159
|
- !ruby/object:Gem::Dependency
|
154
|
-
name:
|
160
|
+
name: em-http-request
|
155
161
|
requirement: !ruby/object:Gem::Requirement
|
156
162
|
requirements:
|
157
|
-
- -
|
163
|
+
- - ! '>='
|
158
164
|
- !ruby/object:Gem::Version
|
159
|
-
version: 0.
|
165
|
+
version: 1.0.2
|
160
166
|
type: :development
|
161
167
|
prerelease: false
|
162
168
|
version_requirements: !ruby/object:Gem::Requirement
|
163
169
|
requirements:
|
164
|
-
- -
|
170
|
+
- - ! '>='
|
165
171
|
- !ruby/object:Gem::Version
|
166
|
-
version: 0.
|
172
|
+
version: 1.0.2
|
173
|
+
- !ruby/object:Gem::Dependency
|
174
|
+
name: em-synchrony
|
175
|
+
requirement: !ruby/object:Gem::Requirement
|
176
|
+
requirements:
|
177
|
+
- - ! '>='
|
178
|
+
- !ruby/object:Gem::Version
|
179
|
+
version: 1.0.0
|
180
|
+
type: :development
|
181
|
+
prerelease: false
|
182
|
+
version_requirements: !ruby/object:Gem::Requirement
|
183
|
+
requirements:
|
184
|
+
- - ! '>='
|
185
|
+
- !ruby/object:Gem::Version
|
186
|
+
version: 1.0.0
|
167
187
|
- !ruby/object:Gem::Dependency
|
168
188
|
name: excon
|
169
189
|
requirement: !ruby/object:Gem::Requirement
|
170
190
|
requirements:
|
171
|
-
- -
|
191
|
+
- - ! '>='
|
172
192
|
- !ruby/object:Gem::Version
|
173
193
|
version: 0.27.5
|
174
194
|
type: :development
|
175
195
|
prerelease: false
|
176
196
|
version_requirements: !ruby/object:Gem::Requirement
|
177
197
|
requirements:
|
178
|
-
- -
|
198
|
+
- - ! '>='
|
179
199
|
- !ruby/object:Gem::Version
|
180
200
|
version: 0.27.5
|
181
201
|
- !ruby/object:Gem::Dependency
|
182
202
|
name: minitest
|
183
203
|
requirement: !ruby/object:Gem::Requirement
|
184
204
|
requirements:
|
185
|
-
- -
|
205
|
+
- - ! '>='
|
186
206
|
- !ruby/object:Gem::Version
|
187
207
|
version: 5.0.0
|
188
208
|
type: :development
|
189
209
|
prerelease: false
|
190
210
|
version_requirements: !ruby/object:Gem::Requirement
|
191
211
|
requirements:
|
192
|
-
- -
|
212
|
+
- - ! '>='
|
193
213
|
- !ruby/object:Gem::Version
|
194
214
|
version: 5.0.0
|
195
215
|
- !ruby/object:Gem::Dependency
|
196
216
|
name: test-unit
|
197
217
|
requirement: !ruby/object:Gem::Requirement
|
198
218
|
requirements:
|
199
|
-
- -
|
219
|
+
- - ! '>='
|
200
220
|
- !ruby/object:Gem::Version
|
201
221
|
version: 3.0.0
|
202
222
|
type: :development
|
203
223
|
prerelease: false
|
204
224
|
version_requirements: !ruby/object:Gem::Requirement
|
205
225
|
requirements:
|
206
|
-
- -
|
226
|
+
- - ! '>='
|
207
227
|
- !ruby/object:Gem::Version
|
208
228
|
version: 3.0.0
|
209
229
|
- !ruby/object:Gem::Dependency
|
210
230
|
name: rdoc
|
211
231
|
requirement: !ruby/object:Gem::Requirement
|
212
232
|
requirements:
|
213
|
-
- -
|
233
|
+
- - ! '>'
|
214
234
|
- !ruby/object:Gem::Version
|
215
235
|
version: 3.5.0
|
216
236
|
type: :development
|
217
237
|
prerelease: false
|
218
238
|
version_requirements: !ruby/object:Gem::Requirement
|
219
239
|
requirements:
|
220
|
-
- -
|
240
|
+
- - ! '>'
|
221
241
|
- !ruby/object:Gem::Version
|
222
242
|
version: 3.5.0
|
223
|
-
- !ruby/object:Gem::Dependency
|
224
|
-
name: rack
|
225
|
-
requirement: !ruby/object:Gem::Requirement
|
226
|
-
requirements:
|
227
|
-
- - ">="
|
228
|
-
- !ruby/object:Gem::Version
|
229
|
-
version: '0'
|
230
|
-
type: :development
|
231
|
-
prerelease: false
|
232
|
-
version_requirements: !ruby/object:Gem::Requirement
|
233
|
-
requirements:
|
234
|
-
- - ">="
|
235
|
-
- !ruby/object:Gem::Version
|
236
|
-
version: '0'
|
237
|
-
- !ruby/object:Gem::Dependency
|
238
|
-
name: simplecov
|
239
|
-
requirement: !ruby/object:Gem::Requirement
|
240
|
-
requirements:
|
241
|
-
- - ">="
|
242
|
-
- !ruby/object:Gem::Version
|
243
|
-
version: '0'
|
244
|
-
type: :development
|
245
|
-
prerelease: false
|
246
|
-
version_requirements: !ruby/object:Gem::Requirement
|
247
|
-
requirements:
|
248
|
-
- - ">="
|
249
|
-
- !ruby/object:Gem::Version
|
250
|
-
version: '0'
|
251
243
|
description: WebMock allows stubbing HTTP requests and setting expectations on HTTP
|
252
244
|
requests.
|
253
245
|
email:
|
@@ -256,10 +248,10 @@ executables: []
|
|
256
248
|
extensions: []
|
257
249
|
extra_rdoc_files: []
|
258
250
|
files:
|
259
|
-
-
|
260
|
-
-
|
261
|
-
-
|
262
|
-
-
|
251
|
+
- .gemtest
|
252
|
+
- .gitignore
|
253
|
+
- .rspec-tm
|
254
|
+
- .travis.yml
|
263
255
|
- CHANGELOG.md
|
264
256
|
- Gemfile
|
265
257
|
- LICENSE
|
@@ -392,26 +384,23 @@ homepage: http://github.com/bblimke/webmock
|
|
392
384
|
licenses:
|
393
385
|
- MIT
|
394
386
|
metadata: {}
|
395
|
-
post_install_message:
|
396
|
-
|
397
|
-
WebMock 2.0 has some breaking changes. Please check the CHANGELOG: https://goo.gl/piDGLu
|
398
|
-
|
387
|
+
post_install_message:
|
399
388
|
rdoc_options: []
|
400
389
|
require_paths:
|
401
390
|
- lib
|
402
391
|
required_ruby_version: !ruby/object:Gem::Requirement
|
403
392
|
requirements:
|
404
|
-
- -
|
393
|
+
- - ! '>='
|
405
394
|
- !ruby/object:Gem::Version
|
406
395
|
version: 1.9.3
|
407
396
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
408
397
|
requirements:
|
409
|
-
- -
|
398
|
+
- - ! '>='
|
410
399
|
- !ruby/object:Gem::Version
|
411
400
|
version: '0'
|
412
401
|
requirements: []
|
413
402
|
rubyforge_project: webmock
|
414
|
-
rubygems_version: 2.
|
403
|
+
rubygems_version: 2.6.8
|
415
404
|
signing_key:
|
416
405
|
specification_version: 4
|
417
406
|
summary: Library for stubbing HTTP requests in Ruby.
|