webmock 3.26.4 → 3.28.0
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 +38 -0
- data/README.md +20 -0
- data/lib/webmock/http_lib_adapters/async_http_client_adapter.rb +13 -1
- data/lib/webmock/http_lib_adapters/curb_adapter.rb +1 -1
- data/lib/webmock/matchers/hash_excluding_matcher.rb +1 -1
- data/lib/webmock/rack_response.rb +0 -10
- data/lib/webmock/request_pattern.rb +5 -1
- data/lib/webmock/request_signature.rb +8 -2
- data/lib/webmock/request_signature_snippet.rb +0 -9
- data/lib/webmock/version.rb +1 -1
- metadata +5 -5
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 337d9a801a6b8cabda8c8d3646346e475d9ec46f15453301314b1575b5e6e1f6
|
|
4
|
+
data.tar.gz: c33b8a74b6fbd42807eb12bb2a385441f953abfb1112c63f8fc1249be0aea38d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 6dad3e43360bf3a82ff3cb6ba1655884c6a0fa4de4767699cc1ce832da1eb1cfe6bf0f37082a1e6d4c80edd839925bb468fad5a75012eb786b6f31342ce510a5
|
|
7
|
+
data.tar.gz: bfbaecd774edb88c0c09de2c8079d05b0d94b197343684cdd426f66e6c24237d9ba7302373a32b3608a1ea59c902f766e9b28b8532671dedfb83e12b8474b4d3
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,43 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
# 3.28.0
|
|
4
|
+
|
|
5
|
+
* Fix `to_rack` apps receiving a `rack.session` they did not set up (#985)
|
|
6
|
+
|
|
7
|
+
WebMock used to add a session hash to the Rack env, shared by every request to the same stub. This confused apps that check whether a session is present, such as Rails API-only apps, and carried session data over between requests. WebMock now leaves `rack.session` and `rack.session.options` unset, as a real server does. If your app needs a session, include session middleware in the app you pass to `to_rack`. `RackResponse#session` and `RackResponse#session_options` have been removed.
|
|
8
|
+
|
|
9
|
+
Thanks to [Jan Graichen](https://github.com/jgraichen)
|
|
10
|
+
|
|
11
|
+
* Fix crash when matching a hash body pattern against a JSON or XML request that has no body
|
|
12
|
+
|
|
13
|
+
Thanks to [Chris](https://github.com/ChrisJr404)
|
|
14
|
+
|
|
15
|
+
* No longer warn about curb versions newer than the last one tested
|
|
16
|
+
|
|
17
|
+
* Document regexp values in `hash_including`
|
|
18
|
+
|
|
19
|
+
Thanks to [Christian Bruckmayer](https://github.com/ChrisBr)
|
|
20
|
+
|
|
21
|
+
* Remove unused `RequestSignatureSnippet#request_params`
|
|
22
|
+
|
|
23
|
+
Thanks to [Daniel Pepper](https://github.com/dpep)
|
|
24
|
+
|
|
25
|
+
# 3.27.0
|
|
26
|
+
|
|
27
|
+
* Fix crash in async-http adapter when a request header has a nil value
|
|
28
|
+
|
|
29
|
+
Thanks to [hikmetba-bit](https://github.com/hikmetba-bit)
|
|
30
|
+
|
|
31
|
+
* The async-http adapter now matches stubs against raw request header values instead of values parsed by protocol-http, consistent with the other adapters
|
|
32
|
+
|
|
33
|
+
* Add RSpec `hash_excluding` support to body matching
|
|
34
|
+
|
|
35
|
+
Thanks to [Chris Gunther](https://github.com/cgunther)
|
|
36
|
+
|
|
37
|
+
* Fix `hash_excluding` ignoring keys given without a value and regexp values, in both query and body matching
|
|
38
|
+
|
|
39
|
+
* Fix crash when matching a request that has more than one `Content-Type` header
|
|
40
|
+
|
|
3
41
|
# 3.26.4
|
|
4
42
|
|
|
5
43
|
* Fix race condition in `HTTPClient` adapter async requests by @koic in #1131
|
data/README.md
CHANGED
|
@@ -184,6 +184,24 @@ stub_request(:post, "www.example.com").
|
|
|
184
184
|
|
|
185
185
|
RestClient.post('www.example.com', "data[a]=1&data[b]=five&x=1",
|
|
186
186
|
:content_type => 'application/x-www-form-urlencoded') # ===> Success
|
|
187
|
+
|
|
188
|
+
stub_request(:post, "www.example.com").
|
|
189
|
+
with(body: hash_including(id: /\d/))
|
|
190
|
+
|
|
191
|
+
RestClient.post('www.example.com', "id=1",
|
|
192
|
+
:content_type => 'application/x-www-form-urlencoded') # ===> Success
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
### Matching request body against excluding partial hash.
|
|
196
|
+
|
|
197
|
+
```ruby
|
|
198
|
+
stub_request(:post, "www.example.com").
|
|
199
|
+
with(body: hash_excluding({data: {a: '2', b: 'six'}}))
|
|
200
|
+
|
|
201
|
+
RestClient.post('www.example.com', "data[a]=1&data[b]=five&x=1",
|
|
202
|
+
:content_type => 'application/x-www-form-urlencoded') # ===> Success
|
|
203
|
+
RestClient.post('www.example.com', "data[a]=2&data[b]=six&x=1",
|
|
204
|
+
:content_type => 'application/x-www-form-urlencoded') # ===> Failure
|
|
187
205
|
```
|
|
188
206
|
|
|
189
207
|
### Matching custom request headers
|
|
@@ -426,6 +444,8 @@ stub_request(:get, "www.example.com").to_rack(MyRackApp)
|
|
|
426
444
|
RestClient.post('www.example.com') # ===> "Hello"
|
|
427
445
|
```
|
|
428
446
|
|
|
447
|
+
WebMock does not set `rack.session` in the Rack env, just as a real server would not. If your app needs a session, include session middleware in the app you pass to `to_rack`.
|
|
448
|
+
|
|
429
449
|
### Raising errors
|
|
430
450
|
|
|
431
451
|
#### Exception declared by class
|
|
@@ -111,11 +111,23 @@ if defined?(Async::HTTP)
|
|
|
111
111
|
WebMock::RequestSignature.new(
|
|
112
112
|
request.method.downcase.to_sym,
|
|
113
113
|
"#{request.scheme}://#{request.authority}#{request.path}",
|
|
114
|
-
headers: request
|
|
114
|
+
headers: build_request_headers(request),
|
|
115
115
|
body: body
|
|
116
116
|
)
|
|
117
117
|
end
|
|
118
118
|
|
|
119
|
+
# Protocol::HTTP::Headers#to_h parses values through the header policies
|
|
120
|
+
# (since protocol-http 0.56.0) and raises when a value is nil. Build the
|
|
121
|
+
# hash from the raw fields instead, skipping entries with no value since
|
|
122
|
+
# they carry nothing to match against. Keys are downcased so the same
|
|
123
|
+
# header sent in different casings is grouped together.
|
|
124
|
+
def build_request_headers(request)
|
|
125
|
+
request.headers.each.each_with_object({}) do |(key, value), headers|
|
|
126
|
+
next if value.nil?
|
|
127
|
+
(headers[key.downcase] ||= []) << value
|
|
128
|
+
end
|
|
129
|
+
end
|
|
130
|
+
|
|
119
131
|
def build_webmock_response(response)
|
|
120
132
|
body = response.read
|
|
121
133
|
response.body = ::Protocol::HTTP::Body::Buffered.wrap(body)
|
|
@@ -13,7 +13,7 @@ if defined?(Curl)
|
|
|
13
13
|
# in curb 1.3.0 through 1.3.5. Fixed in curb 1.3.6. See https://github.com/taf2/curb/issues/478
|
|
14
14
|
unsupported_curb_versions += %w[1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5] if RUBY_VERSION < '2.7'
|
|
15
15
|
|
|
16
|
-
WebMock::VersionChecker.new('Curb', Curl::CURB_VERSION, '0.7.16',
|
|
16
|
+
WebMock::VersionChecker.new('Curb', Curl::CURB_VERSION, '0.7.16', nil, unsupported_curb_versions).check_version!
|
|
17
17
|
|
|
18
18
|
module WebMock
|
|
19
19
|
module HttpLibAdapters
|
|
@@ -6,7 +6,7 @@ module WebMock
|
|
|
6
6
|
# https://github.com/rspec/rspec-mocks/blob/master/lib/rspec/mocks/argument_matchers.rb
|
|
7
7
|
class HashExcludingMatcher < HashArgumentMatcher
|
|
8
8
|
def ==(actual)
|
|
9
|
-
super { |key, value| !actual.key?(key) || value
|
|
9
|
+
super { |key, value| !actual.key?(key) || !(value === actual[key]) }
|
|
10
10
|
end
|
|
11
11
|
|
|
12
12
|
def inspect
|
|
@@ -52,8 +52,6 @@ module WebMock
|
|
|
52
52
|
end
|
|
53
53
|
env['rack.url_scheme'] = uri.scheme
|
|
54
54
|
env['rack.run_once'] = true
|
|
55
|
-
env['rack.session'] = session
|
|
56
|
-
env['rack.session.options'] = session_options
|
|
57
55
|
|
|
58
56
|
headers.each do |k, v|
|
|
59
57
|
env["HTTP_#{k.tr('-','_').upcase}"] = v
|
|
@@ -61,13 +59,5 @@ module WebMock
|
|
|
61
59
|
|
|
62
60
|
env
|
|
63
61
|
end
|
|
64
|
-
|
|
65
|
-
def session
|
|
66
|
-
@session ||= {}
|
|
67
|
-
end
|
|
68
|
-
|
|
69
|
-
def session_options
|
|
70
|
-
@session_options ||= {}
|
|
71
|
-
end
|
|
72
62
|
end
|
|
73
63
|
end
|
|
@@ -33,7 +33,7 @@ module WebMock
|
|
|
33
33
|
end
|
|
34
34
|
|
|
35
35
|
def matches?(request_signature)
|
|
36
|
-
content_type = request_signature.
|
|
36
|
+
content_type = request_signature.content_type
|
|
37
37
|
content_type = content_type.split(';').first if content_type
|
|
38
38
|
@method_pattern.matches?(request_signature.method) &&
|
|
39
39
|
@uri_pattern.matches?(request_signature.uri) &&
|
|
@@ -275,6 +275,8 @@ module WebMock
|
|
|
275
275
|
normalize_hash(pattern)
|
|
276
276
|
elsif rSpecHashIncludingMatcher?(pattern)
|
|
277
277
|
WebMock::Matchers::HashIncludingMatcher.from_rspec_matcher(pattern)
|
|
278
|
+
elsif rSpecHashExcludingMatcher?(pattern)
|
|
279
|
+
WebMock::Matchers::HashExcludingMatcher.from_rspec_matcher(pattern)
|
|
278
280
|
else
|
|
279
281
|
pattern
|
|
280
282
|
end
|
|
@@ -304,6 +306,8 @@ module WebMock
|
|
|
304
306
|
private
|
|
305
307
|
|
|
306
308
|
def body_as_hash(body, content_type)
|
|
309
|
+
return if body.nil?
|
|
310
|
+
|
|
307
311
|
case body_format(content_type)
|
|
308
312
|
when :json then
|
|
309
313
|
WebMock::Util::Parsers::JSON.parse(body)
|
|
@@ -36,12 +36,18 @@ module WebMock
|
|
|
36
36
|
end
|
|
37
37
|
alias == eql?
|
|
38
38
|
|
|
39
|
+
# A request can carry Content-Type more than once, in which case the
|
|
40
|
+
# normalized header value is an Array. Use its first value.
|
|
41
|
+
def content_type
|
|
42
|
+
Array(headers&.fetch('Content-Type', nil)).first
|
|
43
|
+
end
|
|
44
|
+
|
|
39
45
|
def url_encoded?
|
|
40
|
-
!!
|
|
46
|
+
!!content_type&.start_with?('application/x-www-form-urlencoded')
|
|
41
47
|
end
|
|
42
48
|
|
|
43
49
|
def json_headers?
|
|
44
|
-
!!
|
|
50
|
+
!!content_type&.start_with?('application/json')
|
|
45
51
|
end
|
|
46
52
|
|
|
47
53
|
private
|
|
@@ -42,15 +42,6 @@ module WebMock
|
|
|
42
42
|
diff.empty? ? "" : "Body diff:\n #{pretty_print_to_string(diff)}"
|
|
43
43
|
end
|
|
44
44
|
|
|
45
|
-
def request_params
|
|
46
|
-
@request_params ||=
|
|
47
|
-
if request_signature.json_headers?
|
|
48
|
-
JSON.parse(request_signature.body)
|
|
49
|
-
else
|
|
50
|
-
""
|
|
51
|
-
end
|
|
52
|
-
end
|
|
53
|
-
|
|
54
45
|
def pretty_print_to_string(string_to_print)
|
|
55
46
|
StringIO.open("".dup) do |stream|
|
|
56
47
|
PP.pp(string_to_print, stream)
|
data/lib/webmock/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: webmock
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 3.
|
|
4
|
+
version: 3.28.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Bartosz Blimke
|
|
@@ -358,9 +358,9 @@ licenses:
|
|
|
358
358
|
- MIT
|
|
359
359
|
metadata:
|
|
360
360
|
bug_tracker_uri: https://github.com/bblimke/webmock/issues
|
|
361
|
-
changelog_uri: https://github.com/bblimke/webmock/blob/v3.
|
|
362
|
-
documentation_uri: https://www.rubydoc.info/gems/webmock/3.
|
|
363
|
-
source_code_uri: https://github.com/bblimke/webmock/tree/v3.
|
|
361
|
+
changelog_uri: https://github.com/bblimke/webmock/blob/v3.28.0/CHANGELOG.md
|
|
362
|
+
documentation_uri: https://www.rubydoc.info/gems/webmock/3.28.0
|
|
363
|
+
source_code_uri: https://github.com/bblimke/webmock/tree/v3.28.0
|
|
364
364
|
wiki_uri: https://github.com/bblimke/webmock/wiki
|
|
365
365
|
rdoc_options: []
|
|
366
366
|
require_paths:
|
|
@@ -376,7 +376,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
376
376
|
- !ruby/object:Gem::Version
|
|
377
377
|
version: '0'
|
|
378
378
|
requirements: []
|
|
379
|
-
rubygems_version: 4.0.
|
|
379
|
+
rubygems_version: 4.0.20
|
|
380
380
|
specification_version: 4
|
|
381
381
|
summary: Library for stubbing HTTP requests in Ruby.
|
|
382
382
|
test_files: []
|