webmock 3.26.4 → 3.27.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 +16 -0
- data/README.md +12 -0
- data/lib/webmock/http_lib_adapters/async_http_client_adapter.rb +13 -1
- data/lib/webmock/matchers/hash_excluding_matcher.rb +1 -1
- data/lib/webmock/request_pattern.rb +3 -1
- data/lib/webmock/request_signature.rb +8 -2
- data/lib/webmock/version.rb +1 -1
- metadata +9 -6
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 9f11e25e75b578b0d4ce7d2c98cf02b893872c9766d7b707a21fb79e0293963c
|
|
4
|
+
data.tar.gz: 205c01525a5240686ca49c63be018e962db268173bcd68406aef76a5452cc96b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b10e29592ef2d90396ec90b2d5717584e942748eccebe200748609295be1111616b14c706c503ad54543f3ee90e54e0e06ddfd9860b3ed0e093cda225df714a4
|
|
7
|
+
data.tar.gz: cc80e50037959e1b9ff6fa600eea3c309e57c3aa6083d40e11288aecc1e81ebf1115cf07c10fba310543a58161674c8b62e829c7e5eedb9dadb8e6e81e894263
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
# 3.27.0
|
|
4
|
+
|
|
5
|
+
* Fix crash in async-http adapter when a request header has a nil value
|
|
6
|
+
|
|
7
|
+
Thanks to [hikmetba-bit](https://github.com/hikmetba-bit)
|
|
8
|
+
|
|
9
|
+
* The async-http adapter now matches stubs against raw request header values instead of values parsed by protocol-http, consistent with the other adapters
|
|
10
|
+
|
|
11
|
+
* Add RSpec `hash_excluding` support to body matching
|
|
12
|
+
|
|
13
|
+
Thanks to [Chris Gunther](https://github.com/cgunther)
|
|
14
|
+
|
|
15
|
+
* Fix `hash_excluding` ignoring keys given without a value and regexp values, in both query and body matching
|
|
16
|
+
|
|
17
|
+
* Fix crash when matching a request that has more than one `Content-Type` header
|
|
18
|
+
|
|
3
19
|
# 3.26.4
|
|
4
20
|
|
|
5
21
|
* Fix race condition in `HTTPClient` adapter async requests by @koic in #1131
|
data/README.md
CHANGED
|
@@ -186,6 +186,18 @@ RestClient.post('www.example.com', "data[a]=1&data[b]=five&x=1",
|
|
|
186
186
|
:content_type => 'application/x-www-form-urlencoded') # ===> Success
|
|
187
187
|
```
|
|
188
188
|
|
|
189
|
+
### Matching request body against excluding partial hash.
|
|
190
|
+
|
|
191
|
+
```ruby
|
|
192
|
+
stub_request(:post, "www.example.com").
|
|
193
|
+
with(body: hash_excluding({data: {a: '2', b: 'six'}}))
|
|
194
|
+
|
|
195
|
+
RestClient.post('www.example.com', "data[a]=1&data[b]=five&x=1",
|
|
196
|
+
:content_type => 'application/x-www-form-urlencoded') # ===> Success
|
|
197
|
+
RestClient.post('www.example.com', "data[a]=2&data[b]=six&x=1",
|
|
198
|
+
:content_type => 'application/x-www-form-urlencoded') # ===> Failure
|
|
199
|
+
```
|
|
200
|
+
|
|
189
201
|
### Matching custom request headers
|
|
190
202
|
|
|
191
203
|
```ruby
|
|
@@ -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)
|
|
@@ -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
|
|
@@ -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
|
|
@@ -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
|
data/lib/webmock/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: webmock
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 3.
|
|
4
|
+
version: 3.27.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Bartosz Blimke
|
|
8
|
+
autorequire:
|
|
8
9
|
bindir: bin
|
|
9
10
|
cert_chain: []
|
|
10
|
-
date:
|
|
11
|
+
date: 2026-10-10 00:00:00.000000000 Z
|
|
11
12
|
dependencies:
|
|
12
13
|
- !ruby/object:Gem::Dependency
|
|
13
14
|
name: addressable
|
|
@@ -358,10 +359,11 @@ licenses:
|
|
|
358
359
|
- MIT
|
|
359
360
|
metadata:
|
|
360
361
|
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.
|
|
362
|
+
changelog_uri: https://github.com/bblimke/webmock/blob/v3.27.0/CHANGELOG.md
|
|
363
|
+
documentation_uri: https://www.rubydoc.info/gems/webmock/3.27.0
|
|
364
|
+
source_code_uri: https://github.com/bblimke/webmock/tree/v3.27.0
|
|
364
365
|
wiki_uri: https://github.com/bblimke/webmock/wiki
|
|
366
|
+
post_install_message:
|
|
365
367
|
rdoc_options: []
|
|
366
368
|
require_paths:
|
|
367
369
|
- lib
|
|
@@ -376,7 +378,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
376
378
|
- !ruby/object:Gem::Version
|
|
377
379
|
version: '0'
|
|
378
380
|
requirements: []
|
|
379
|
-
rubygems_version:
|
|
381
|
+
rubygems_version: 3.5.16
|
|
382
|
+
signing_key:
|
|
380
383
|
specification_version: 4
|
|
381
384
|
summary: Library for stubbing HTTP requests in Ruby.
|
|
382
385
|
test_files: []
|