webmock 3.9.0 → 3.9.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +33 -3
- data/README.md +37 -23
- data/lib/webmock/http_lib_adapters/httpclient_adapter.rb +23 -6
- data/lib/webmock/request_pattern.rb +6 -4
- data/lib/webmock/response.rb +11 -5
- data/lib/webmock/stub_registry.rb +12 -2
- data/lib/webmock/test_unit.rb +1 -3
- data/lib/webmock/version.rb +1 -1
- data/spec/unit/request_pattern_spec.rb +44 -3
- data/spec/unit/response_spec.rb +22 -18
- data/test/test_webmock.rb +6 -0
- metadata +8 -8
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e86a9ca126d1410e47a219ea054f8591fe421e303deb27366b0705c88d37484f
|
|
4
|
+
data.tar.gz: 8e35153a6620d376d86cf37c3ab85060f38265cc9c110ce6f5adbc3120af0fdf
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 3af5f5d03fe560dbbdf8cb974ed913568bfb8964372c44d705ae6b8956a66f9095723e9a6c8845b7fb9ce6894047cb5662c6d01f5ae832e62a17cd6bf681e6c9
|
|
7
|
+
data.tar.gz: bae8f2a18cf86174308dc4ab14305aca3586853e67a9b27a4fbdefbb5abee31c54ec734ff42f22a1fa974e233d69516eea96a669a511cbb342bda2e2f062e3fa
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,35 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
# 3.9.5
|
|
4
|
+
|
|
5
|
+
* Prevent overwriting `teardown` method in Test::Unit
|
|
6
|
+
|
|
7
|
+
Thanks to [Jesse Bowes](https://github.com/jessebs)
|
|
8
|
+
|
|
9
|
+
# 3.9.4
|
|
10
|
+
|
|
11
|
+
* More intuitive error message when stubbed response body was provided as Hash
|
|
12
|
+
|
|
13
|
+
Thanks to [Ben Koshy](https://github.com/BKSpurgeon)
|
|
14
|
+
|
|
15
|
+
# 3.9.3
|
|
16
|
+
|
|
17
|
+
* Make httpclient_adapter thread-safe
|
|
18
|
+
|
|
19
|
+
Thanks to [Adam Harwood](https://github.com/adam-harwood)
|
|
20
|
+
|
|
21
|
+
# 3.9.2
|
|
22
|
+
|
|
23
|
+
* Made global stubs thread-safe
|
|
24
|
+
|
|
25
|
+
Thanks to [Adam Harwood](https://github.com/adam-harwood)
|
|
26
|
+
|
|
27
|
+
# 3.9.1
|
|
28
|
+
|
|
29
|
+
* Fixed support for passing `URI` objects as second argument of `stub_request`
|
|
30
|
+
|
|
31
|
+
Thanks to [Ryan Kerr](https://github.com/leboshi)
|
|
32
|
+
|
|
3
33
|
## 3.9.0
|
|
4
34
|
|
|
5
35
|
* Allow using a "callable" (like a proc) as URI pattern
|
|
@@ -22,11 +52,11 @@
|
|
|
22
52
|
|
|
23
53
|
* Fixed async-http adapter which caused Async::HTTP::Client or Async::HTTP::Internet to hang and never return a response.
|
|
24
54
|
|
|
25
|
-
Thanks to
|
|
55
|
+
Thanks to [Bruno Sutic](https://github.com/bruno-) and [Samuel Williams](https://github.com/ioquatix)
|
|
26
56
|
|
|
27
57
|
* Fixed warning when using async-http adapter
|
|
28
58
|
|
|
29
|
-
Thanks to
|
|
59
|
+
Thanks to [Bruno Sutic](https://github.com/bruno-)
|
|
30
60
|
|
|
31
61
|
* Dropped support for Ruby 2.3 - EOL date: 2019-03-31
|
|
32
62
|
|
|
@@ -34,7 +64,7 @@
|
|
|
34
64
|
|
|
35
65
|
* Handling matching of Addressable::Template patterns that have an ip address without port and patterns that have ip address and don’t have schema and path.
|
|
36
66
|
|
|
37
|
-
Thanks to
|
|
67
|
+
Thanks to [Rafael França](https://github.com/rafaelfranca) and [guppy0356](https://github.com/guppy0356)
|
|
38
68
|
|
|
39
69
|
## 3.8.3
|
|
40
70
|
|
data/README.md
CHANGED
|
@@ -24,16 +24,19 @@ Features
|
|
|
24
24
|
Supported HTTP libraries
|
|
25
25
|
------------------------
|
|
26
26
|
|
|
27
|
-
*
|
|
28
|
-
* HTTPClient
|
|
29
|
-
* Patron
|
|
30
|
-
* EM-HTTP-Request
|
|
27
|
+
* Async::HTTP::Client
|
|
31
28
|
* Curb (currently only Curb::Easy)
|
|
32
|
-
*
|
|
29
|
+
* EM-HTTP-Request
|
|
33
30
|
* Excon
|
|
34
|
-
*
|
|
31
|
+
* HTTPClient
|
|
32
|
+
* [HTTP Gem (also known as http.rb)](https://github.com/httprb/http)
|
|
35
33
|
* Manticore
|
|
36
|
-
*
|
|
34
|
+
* Net::HTTP and other libraries based on Net::HTTP, e.g.:
|
|
35
|
+
* HTTParty
|
|
36
|
+
* REST Client
|
|
37
|
+
* RightHttpConnection
|
|
38
|
+
* Patron
|
|
39
|
+
* Typhoeus (currently only Typhoeus::Hydra)
|
|
37
40
|
|
|
38
41
|
Supported Ruby Interpreters
|
|
39
42
|
---------------------------
|
|
@@ -46,7 +49,17 @@ Supported Ruby Interpreters
|
|
|
46
49
|
|
|
47
50
|
## Installation
|
|
48
51
|
|
|
52
|
+
```bash
|
|
49
53
|
gem install webmock
|
|
54
|
+
```
|
|
55
|
+
or alternatively:
|
|
56
|
+
|
|
57
|
+
```ruby
|
|
58
|
+
# add to your Gemfile
|
|
59
|
+
group :test do
|
|
60
|
+
gem "webmock"
|
|
61
|
+
end
|
|
62
|
+
```
|
|
50
63
|
|
|
51
64
|
### or to install the latest development version from github master
|
|
52
65
|
|
|
@@ -58,36 +71,36 @@ Supported Ruby Interpreters
|
|
|
58
71
|
|
|
59
72
|
WebMock 2.x has changed somewhat since version 1.x. Changes are listed in [CHANGELOG.md](CHANGELOG.md)
|
|
60
73
|
|
|
61
|
-
###
|
|
74
|
+
### Cucumber
|
|
62
75
|
|
|
63
|
-
|
|
76
|
+
Create a file `features/support/webmock.rb` with the following contents:
|
|
64
77
|
|
|
65
78
|
```ruby
|
|
66
|
-
require 'webmock/
|
|
79
|
+
require 'webmock/cucumber'
|
|
67
80
|
```
|
|
68
81
|
|
|
69
|
-
###
|
|
82
|
+
### MiniTest
|
|
70
83
|
|
|
71
|
-
Add the following code to `
|
|
84
|
+
Add the following code to `test/test_helper`:
|
|
72
85
|
|
|
73
86
|
```ruby
|
|
74
|
-
require 'webmock/
|
|
87
|
+
require 'webmock/minitest'
|
|
75
88
|
```
|
|
76
89
|
|
|
77
|
-
###
|
|
90
|
+
### RSpec
|
|
78
91
|
|
|
79
|
-
Add the following code to `
|
|
92
|
+
Add the following code to `spec/spec_helper`:
|
|
80
93
|
|
|
81
94
|
```ruby
|
|
82
|
-
require 'webmock/
|
|
95
|
+
require 'webmock/rspec'
|
|
83
96
|
```
|
|
84
97
|
|
|
85
|
-
###
|
|
98
|
+
### Test::Unit
|
|
86
99
|
|
|
87
|
-
|
|
100
|
+
Add the following code to `test/test_helper.rb`
|
|
88
101
|
|
|
89
102
|
```ruby
|
|
90
|
-
require 'webmock/
|
|
103
|
+
require 'webmock/test_unit'
|
|
91
104
|
```
|
|
92
105
|
|
|
93
106
|
### Outside a test framework
|
|
@@ -101,13 +114,10 @@ include WebMock::API
|
|
|
101
114
|
WebMock.enable!
|
|
102
115
|
```
|
|
103
116
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
117
|
+
# Examples
|
|
107
118
|
|
|
108
119
|
## Stubbing
|
|
109
120
|
|
|
110
|
-
|
|
111
121
|
### Stubbed request based on uri only and with the default response
|
|
112
122
|
|
|
113
123
|
```ruby
|
|
@@ -1136,6 +1146,10 @@ People who submitted patches and new features or suggested improvements. Many th
|
|
|
1136
1146
|
* Andrew Stuntz
|
|
1137
1147
|
* Lucas Uyezu
|
|
1138
1148
|
* Bruno Sutic
|
|
1149
|
+
* Ryan Kerr
|
|
1150
|
+
* Adam Harwood
|
|
1151
|
+
* Ben Koshy
|
|
1152
|
+
* Jesse Bowes
|
|
1139
1153
|
|
|
1140
1154
|
For a full list of contributors you can visit the
|
|
1141
1155
|
[contributors](https://github.com/bblimke/webmock/contributors) page.
|
|
@@ -43,6 +43,9 @@ if defined?(::HTTPClient)
|
|
|
43
43
|
end
|
|
44
44
|
|
|
45
45
|
module WebMockHTTPClients
|
|
46
|
+
|
|
47
|
+
REQUEST_RESPONSE_LOCK = Mutex.new
|
|
48
|
+
|
|
46
49
|
def do_get_block(req, proxy, conn, &block)
|
|
47
50
|
do_get(req, proxy, conn, false, &block)
|
|
48
51
|
end
|
|
@@ -57,7 +60,7 @@ if defined?(::HTTPClient)
|
|
|
57
60
|
WebMock::RequestRegistry.instance.requested_signatures.put(request_signature)
|
|
58
61
|
|
|
59
62
|
if webmock_responses[request_signature]
|
|
60
|
-
webmock_response = webmock_responses.delete(request_signature)
|
|
63
|
+
webmock_response = synchronize_request_response { webmock_responses.delete(request_signature) }
|
|
61
64
|
response = build_httpclient_response(webmock_response, stream, req.header, &block)
|
|
62
65
|
@request_filter.each do |filter|
|
|
63
66
|
filter.filter_response(req, response)
|
|
@@ -68,7 +71,7 @@ if defined?(::HTTPClient)
|
|
|
68
71
|
res
|
|
69
72
|
elsif WebMock.net_connect_allowed?(request_signature.uri)
|
|
70
73
|
# in case there is a nil entry in the hash...
|
|
71
|
-
webmock_responses.delete(request_signature)
|
|
74
|
+
synchronize_request_response { webmock_responses.delete(request_signature) }
|
|
72
75
|
|
|
73
76
|
res = if stream
|
|
74
77
|
do_get_stream_without_webmock(req, proxy, conn, &block)
|
|
@@ -100,7 +103,7 @@ if defined?(::HTTPClient)
|
|
|
100
103
|
def do_request_async(method, uri, query, body, extheader)
|
|
101
104
|
req = create_request(method, uri, query, body, extheader)
|
|
102
105
|
request_signature = build_request_signature(req)
|
|
103
|
-
webmock_request_signatures << request_signature
|
|
106
|
+
synchronize_request_response { webmock_request_signatures << request_signature }
|
|
104
107
|
|
|
105
108
|
if webmock_responses[request_signature] || WebMock.net_connect_allowed?(request_signature.uri)
|
|
106
109
|
super
|
|
@@ -184,7 +187,9 @@ if defined?(::HTTPClient)
|
|
|
184
187
|
|
|
185
188
|
def webmock_responses
|
|
186
189
|
@webmock_responses ||= Hash.new do |hash, request_signature|
|
|
187
|
-
|
|
190
|
+
synchronize_request_response do
|
|
191
|
+
hash[request_signature] = WebMock::StubRegistry.instance.response_for_request(request_signature)
|
|
192
|
+
end
|
|
188
193
|
end
|
|
189
194
|
end
|
|
190
195
|
|
|
@@ -193,8 +198,10 @@ if defined?(::HTTPClient)
|
|
|
193
198
|
end
|
|
194
199
|
|
|
195
200
|
def previous_signature_for(signature)
|
|
196
|
-
|
|
197
|
-
|
|
201
|
+
synchronize_request_response do
|
|
202
|
+
return nil unless index = webmock_request_signatures.index(signature)
|
|
203
|
+
webmock_request_signatures.delete_at(index)
|
|
204
|
+
end
|
|
198
205
|
end
|
|
199
206
|
|
|
200
207
|
private
|
|
@@ -209,6 +216,16 @@ if defined?(::HTTPClient)
|
|
|
209
216
|
hdrs
|
|
210
217
|
end
|
|
211
218
|
end
|
|
219
|
+
|
|
220
|
+
def synchronize_request_response
|
|
221
|
+
if REQUEST_RESPONSE_LOCK.owned?
|
|
222
|
+
yield
|
|
223
|
+
else
|
|
224
|
+
REQUEST_RESPONSE_LOCK.synchronize do
|
|
225
|
+
yield
|
|
226
|
+
end
|
|
227
|
+
end
|
|
228
|
+
end
|
|
212
229
|
end
|
|
213
230
|
|
|
214
231
|
class WebMockHTTPClient < HTTPClient
|
|
@@ -109,11 +109,13 @@ module WebMock
|
|
|
109
109
|
include RSpecMatcherDetector
|
|
110
110
|
|
|
111
111
|
def initialize(pattern)
|
|
112
|
-
@pattern =
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
112
|
+
@pattern = if pattern.is_a?(Addressable::URI) \
|
|
113
|
+
|| pattern.is_a?(Addressable::Template)
|
|
114
|
+
pattern
|
|
115
|
+
elsif pattern.respond_to?(:call)
|
|
116
116
|
pattern
|
|
117
|
+
else
|
|
118
|
+
WebMock::Util::URI.normalize_uri(pattern)
|
|
117
119
|
end
|
|
118
120
|
@query_params = nil
|
|
119
121
|
end
|
data/lib/webmock/response.rb
CHANGED
|
@@ -91,10 +91,10 @@ module WebMock
|
|
|
91
91
|
|
|
92
92
|
def ==(other)
|
|
93
93
|
self.body == other.body &&
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
94
|
+
self.headers === other.headers &&
|
|
95
|
+
self.status == other.status &&
|
|
96
|
+
self.exception == other.exception &&
|
|
97
|
+
self.should_timeout == other.should_timeout
|
|
98
98
|
end
|
|
99
99
|
|
|
100
100
|
private
|
|
@@ -111,7 +111,13 @@ module WebMock
|
|
|
111
111
|
valid_types = [Proc, IO, Pathname, String, Array]
|
|
112
112
|
return if @body.nil?
|
|
113
113
|
return if valid_types.any? { |c| @body.is_a?(c) }
|
|
114
|
-
|
|
114
|
+
|
|
115
|
+
if @body.class.is_a?(Hash)
|
|
116
|
+
raise InvalidBody, "must be one of: #{valid_types}, but you've used a #{@body.class}' instead." \
|
|
117
|
+
"\n What shall we encode it to? try calling .to_json .to_xml instead on the hash instead, or otherwise convert it to a string."
|
|
118
|
+
else
|
|
119
|
+
raise InvalidBody, "must be one of: #{valid_types}. '#{@body.class}' given"
|
|
120
|
+
end
|
|
115
121
|
end
|
|
116
122
|
|
|
117
123
|
def read_raw_response(raw_response)
|
|
@@ -23,10 +23,20 @@ module WebMock
|
|
|
23
23
|
# That way, there's no race condition in case #to_return
|
|
24
24
|
# doesn't run immediately after stub.with.
|
|
25
25
|
responses = {}
|
|
26
|
+
response_lock = Mutex.new
|
|
26
27
|
|
|
27
28
|
stub = ::WebMock::RequestStub.new(:any, ->(uri) { true }).with { |request|
|
|
28
|
-
responses[request.object_id] = yield(request)
|
|
29
|
-
|
|
29
|
+
update_response = -> { responses[request.object_id] = yield(request) }
|
|
30
|
+
|
|
31
|
+
# The block can recurse, so only lock if we don't already own it
|
|
32
|
+
if response_lock.owned?
|
|
33
|
+
update_response.call
|
|
34
|
+
else
|
|
35
|
+
response_lock.synchronize(&update_response)
|
|
36
|
+
end
|
|
37
|
+
}.to_return(lambda { |request|
|
|
38
|
+
response_lock.synchronize { responses.delete(request.object_id) }
|
|
39
|
+
})
|
|
30
40
|
|
|
31
41
|
global_stubs.push stub
|
|
32
42
|
end
|
data/lib/webmock/test_unit.rb
CHANGED
|
@@ -8,12 +8,10 @@ module Test
|
|
|
8
8
|
class TestCase
|
|
9
9
|
include WebMock::API
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
teardown
|
|
12
12
|
def teardown_with_webmock
|
|
13
|
-
teardown_without_webmock
|
|
14
13
|
WebMock.reset!
|
|
15
14
|
end
|
|
16
|
-
alias_method :teardown, :teardown_with_webmock
|
|
17
15
|
|
|
18
16
|
end
|
|
19
17
|
end
|
data/lib/webmock/version.rb
CHANGED
|
@@ -111,6 +111,11 @@ describe WebMock::RequestPattern do
|
|
|
111
111
|
to match(WebMock::RequestSignature.new(:get, "www.example.com"))
|
|
112
112
|
end
|
|
113
113
|
|
|
114
|
+
it "should match if uri matches requesst uri as URI object" do
|
|
115
|
+
expect(WebMock::RequestPattern.new(:get, URI.parse("www.example.com"))).
|
|
116
|
+
to match(WebMock::RequestSignature.new(:get, "www.example.com"))
|
|
117
|
+
end
|
|
118
|
+
|
|
114
119
|
it "should match if uri proc pattern returning true" do
|
|
115
120
|
expect(WebMock::RequestPattern.new(:get, ->(uri) { true })).
|
|
116
121
|
to match(WebMock::RequestSignature.new(:get, "www.example.com"))
|
|
@@ -233,7 +238,7 @@ describe WebMock::RequestPattern do
|
|
|
233
238
|
to match(WebMock::RequestSignature.new(:get, "www.example.com?a[]=b&a[]=c"))
|
|
234
239
|
end
|
|
235
240
|
|
|
236
|
-
it "should match request query params if params don't match" do
|
|
241
|
+
it "should not match request query params if params don't match" do
|
|
237
242
|
expect(WebMock::RequestPattern.new(:get, /.*example.*/, query: {"x" => ["b", "c"]})).
|
|
238
243
|
not_to match(WebMock::RequestSignature.new(:get, "www.example.com?a[]=b&a[]=c"))
|
|
239
244
|
end
|
|
@@ -263,13 +268,49 @@ describe WebMock::RequestPattern do
|
|
|
263
268
|
end
|
|
264
269
|
end
|
|
265
270
|
|
|
271
|
+
describe "when uri is described as URI" do
|
|
272
|
+
it "should match request query params" do
|
|
273
|
+
expect(WebMock::RequestPattern.new(:get, URI.parse("www.example.com"), query: {"a" => ["b", "c"]})).
|
|
274
|
+
to match(WebMock::RequestSignature.new(:get, "www.example.com?a[]=b&a[]=c"))
|
|
275
|
+
end
|
|
276
|
+
|
|
277
|
+
it "should not match request query params if params don't match" do
|
|
278
|
+
expect(WebMock::RequestPattern.new(:get, URI.parse("www.example.com"), query: {"x" => ["b", "c"]})).
|
|
279
|
+
not_to match(WebMock::RequestSignature.new(:get, "www.example.com?a[]=b&a[]=c"))
|
|
280
|
+
end
|
|
281
|
+
|
|
282
|
+
it "should match when query params are declared as HashIncluding matcher matching params" do
|
|
283
|
+
expect(WebMock::RequestPattern.new(:get, URI.parse("www.example.com"),
|
|
284
|
+
query: WebMock::Matchers::HashIncludingMatcher.new({"a" => ["b", "c"]}))).
|
|
285
|
+
to match(WebMock::RequestSignature.new(:get, "www.example.com?a[]=b&a[]=c&b=1"))
|
|
286
|
+
end
|
|
287
|
+
|
|
288
|
+
it "should not match when query params are declared as HashIncluding matcher not matching params" do
|
|
289
|
+
expect(WebMock::RequestPattern.new(:get, URI.parse("www.example.com"),
|
|
290
|
+
query: WebMock::Matchers::HashIncludingMatcher.new({"x" => ["b", "c"]}))).
|
|
291
|
+
not_to match(WebMock::RequestSignature.new(:get, "www.example.com?a[]=b&a[]=c&b=1"))
|
|
292
|
+
end
|
|
293
|
+
|
|
294
|
+
it "should match when query params are declared as RSpec HashIncluding matcher matching params" do
|
|
295
|
+
expect(WebMock::RequestPattern.new(:get, URI.parse("www.example.com"),
|
|
296
|
+
query: RSpec::Mocks::ArgumentMatchers::HashIncludingMatcher.new({"a" => ["b", "c"]}))).
|
|
297
|
+
to match(WebMock::RequestSignature.new(:get, "www.example.com?a[]=b&a[]=c&b=1"))
|
|
298
|
+
end
|
|
299
|
+
|
|
300
|
+
it "should not match when query params are declared as RSpec HashIncluding matcher not matching params" do
|
|
301
|
+
expect(WebMock::RequestPattern.new(:get, URI.parse("www.example.com"),
|
|
302
|
+
query: RSpec::Mocks::ArgumentMatchers::HashIncludingMatcher.new({"a" => ["b", "d"]}))).
|
|
303
|
+
not_to match(WebMock::RequestSignature.new(:get, "www.example.com?a[]=b&a[]=c&b=1"))
|
|
304
|
+
end
|
|
305
|
+
end
|
|
306
|
+
|
|
266
307
|
describe "when uri is described as a proc" do
|
|
267
308
|
it "should match request query params" do
|
|
268
309
|
expect(WebMock::RequestPattern.new(:get, ->(uri) { true }, query: {"a" => ["b", "c"]})).
|
|
269
310
|
to match(WebMock::RequestSignature.new(:get, "www.example.com?a[]=b&a[]=c"))
|
|
270
311
|
end
|
|
271
312
|
|
|
272
|
-
it "should match request query params if params don't match" do
|
|
313
|
+
it "should not match request query params if params don't match" do
|
|
273
314
|
expect(WebMock::RequestPattern.new(:get, ->(uri) { true }, query: {"x" => ["b", "c"]})).
|
|
274
315
|
not_to match(WebMock::RequestSignature.new(:get, "www.example.com?a[]=b&a[]=c"))
|
|
275
316
|
end
|
|
@@ -305,7 +346,7 @@ describe WebMock::RequestPattern do
|
|
|
305
346
|
to match(WebMock::RequestSignature.new(:get, "www.example.com?a[]=b&a[]=c"))
|
|
306
347
|
end
|
|
307
348
|
|
|
308
|
-
it "should match request query params if params don't match" do
|
|
349
|
+
it "should not match request query params if params don't match" do
|
|
309
350
|
expect(WebMock::RequestPattern.new(:get, Addressable::Template.new("www.example.com"), query: {"x" => ["b", "c"]})).
|
|
310
351
|
not_to match(WebMock::RequestSignature.new(:get, "www.example.com?a[]=b&a[]=c"))
|
|
311
352
|
end
|
data/spec/unit/response_spec.rb
CHANGED
|
@@ -130,11 +130,15 @@ describe WebMock::Response do
|
|
|
130
130
|
# Users of webmock commonly make the mistake of stubbing the response
|
|
131
131
|
# body to return a hash, to prevent this:
|
|
132
132
|
#
|
|
133
|
-
it "should error if
|
|
133
|
+
it "should error if given a non-allowed type: a hash" do
|
|
134
134
|
expect { WebMock::Response.new(body: Hash.new) }.to \
|
|
135
135
|
raise_error(WebMock::Response::InvalidBody)
|
|
136
136
|
end
|
|
137
137
|
|
|
138
|
+
it "should error if given a non-allowed type: something that is not a hash" do
|
|
139
|
+
expect { WebMock::Response.new(body: 123) }.to \
|
|
140
|
+
raise_error(WebMock::Response::InvalidBody)
|
|
141
|
+
end
|
|
138
142
|
end
|
|
139
143
|
|
|
140
144
|
describe "from raw response" do
|
|
@@ -152,12 +156,12 @@ describe WebMock::Response do
|
|
|
152
156
|
|
|
153
157
|
it "should read headers" do
|
|
154
158
|
expect(@response.headers).to eq({
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
159
|
+
"Date"=>"Sat, 23 Jan 2010 01:01:05 GMT",
|
|
160
|
+
"Content-Type"=>"text/html; charset=UTF-8",
|
|
161
|
+
"Content-Length"=>"419",
|
|
162
|
+
"Connection"=>"Keep-Alive",
|
|
163
|
+
"Accept"=>"image/jpeg, image/png"
|
|
164
|
+
})
|
|
161
165
|
end
|
|
162
166
|
|
|
163
167
|
it "should read body" do
|
|
@@ -182,12 +186,12 @@ describe WebMock::Response do
|
|
|
182
186
|
|
|
183
187
|
it "should read headers" do
|
|
184
188
|
expect(@response.headers).to eq({
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
189
|
+
"Date"=>"Sat, 23 Jan 2010 01:01:05 GMT",
|
|
190
|
+
"Content-Type"=>"text/html; charset=UTF-8",
|
|
191
|
+
"Content-Length"=>"419",
|
|
192
|
+
"Connection"=>"Keep-Alive",
|
|
193
|
+
"Accept"=>"image/jpeg, image/png"
|
|
194
|
+
})
|
|
191
195
|
end
|
|
192
196
|
|
|
193
197
|
it "should read body" do
|
|
@@ -234,11 +238,11 @@ describe WebMock::Response do
|
|
|
234
238
|
it "should evaluate new response with evaluated options" do
|
|
235
239
|
request_signature = WebMock::RequestSignature.new(:post, "www.example.com", body: "abc", headers: {'A' => 'a'})
|
|
236
240
|
response = WebMock::DynamicResponse.new(lambda {|request|
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
241
|
+
{
|
|
242
|
+
body: request.body,
|
|
243
|
+
headers: request.headers,
|
|
244
|
+
status: 302
|
|
245
|
+
}
|
|
242
246
|
})
|
|
243
247
|
evaluated_response = response.evaluate(request_signature)
|
|
244
248
|
expect(evaluated_response.body).to eq("abc")
|
data/test/test_webmock.rb
CHANGED
|
@@ -3,4 +3,10 @@ require File.expand_path(File.dirname(__FILE__) + '/shared_test')
|
|
|
3
3
|
|
|
4
4
|
class TestWebMock < Test::Unit::TestCase
|
|
5
5
|
include SharedTest
|
|
6
|
+
|
|
7
|
+
def teardown
|
|
8
|
+
# Ensure global Test::Unit teardown was called
|
|
9
|
+
assert_empty WebMock::RequestRegistry.instance.requested_signatures.hash
|
|
10
|
+
assert_empty WebMock::StubRegistry.instance.request_stubs
|
|
11
|
+
end
|
|
6
12
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: webmock
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 3.9.
|
|
4
|
+
version: 3.9.5
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Bartosz Blimke
|
|
8
|
-
autorequire:
|
|
8
|
+
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2020-09
|
|
11
|
+
date: 2020-11-09 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: addressable
|
|
@@ -407,11 +407,11 @@ licenses:
|
|
|
407
407
|
- MIT
|
|
408
408
|
metadata:
|
|
409
409
|
bug_tracker_uri: https://github.com/bblimke/webmock/issues
|
|
410
|
-
changelog_uri: https://github.com/bblimke/webmock/blob/v3.9.
|
|
411
|
-
documentation_uri: https://www.rubydoc.info/gems/webmock/3.9.
|
|
412
|
-
source_code_uri: https://github.com/bblimke/webmock/tree/v3.9.
|
|
410
|
+
changelog_uri: https://github.com/bblimke/webmock/blob/v3.9.5/CHANGELOG.md
|
|
411
|
+
documentation_uri: https://www.rubydoc.info/gems/webmock/3.9.5
|
|
412
|
+
source_code_uri: https://github.com/bblimke/webmock/tree/v3.9.5
|
|
413
413
|
wiki_uri: https://github.com/bblimke/webmock/wiki
|
|
414
|
-
post_install_message:
|
|
414
|
+
post_install_message:
|
|
415
415
|
rdoc_options: []
|
|
416
416
|
require_paths:
|
|
417
417
|
- lib
|
|
@@ -427,7 +427,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
427
427
|
version: '0'
|
|
428
428
|
requirements: []
|
|
429
429
|
rubygems_version: 3.1.2
|
|
430
|
-
signing_key:
|
|
430
|
+
signing_key:
|
|
431
431
|
specification_version: 4
|
|
432
432
|
summary: Library for stubbing HTTP requests in Ruby.
|
|
433
433
|
test_files:
|