webmock 3.16.2 → 3.17.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 +20 -4
- data/README.md +3 -0
- data/lib/webmock/http_lib_adapters/net_http.rb +12 -2
- data/lib/webmock/request_pattern.rb +23 -7
- data/lib/webmock/request_signature.rb +2 -2
- data/lib/webmock/version.rb +1 -1
- data/spec/acceptance/net_http/net_http_spec.rb +16 -0
- data/spec/unit/request_pattern_spec.rb +6 -0
- data/webmock.gemspec +2 -2
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e83aa4c98567eb2c64f39136600540212c108d9d5596119c81d26457757f5233
|
4
|
+
data.tar.gz: 78547f4192e94786194a63d4a7c93e144b1a5781c95619e869984d0438dad69d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6461f17c27d962adc571dc23a9f6f232e4855c71384f7dcb6d8f6132497f46c46c7e196d75d75e920605f5fdc8a70962ac4ea61cd2109340ebb0b6a7cd6a5782
|
7
|
+
data.tar.gz: '084c4a3a1225eb9b1bd159a831eb9a8dd488493b0253c28773514c6966e0ae89c9f778f14f68ff67d57d7382b6582790f226ae1708c096e28661d4936aacf5e1'
|
data/CHANGELOG.md
CHANGED
@@ -1,12 +1,28 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
-
# 3.
|
3
|
+
# 3.17.0
|
4
4
|
|
5
|
-
* Minimum required Ruby version is 2.
|
5
|
+
* Minimum required Ruby version is 2.3
|
6
6
|
|
7
|
-
|
7
|
+
Thanks to [Go Sueyoshi](https://github.com/sue445)
|
8
8
|
|
9
|
-
*
|
9
|
+
* When using Net::HTTP, stubbed socket StubSocket#close and StubSocket#closed? behave more like the real sockets.
|
10
|
+
|
11
|
+
Thanks to [Ray Zane](https://github.com/rzane)
|
12
|
+
|
13
|
+
* Added `peeraddr`, `ssl_version` and `cipher` methods to stubbed sockets used by Net::HTTP.
|
14
|
+
|
15
|
+
Thanks to [Ray Zane](https://github.com/rzane)
|
16
|
+
|
17
|
+
* Added support for matching top-level array in JSON request body.
|
18
|
+
|
19
|
+
E.g.
|
20
|
+
|
21
|
+
````
|
22
|
+
stub_request(:post, 'www.example.com').with(body: [{a: 1}])
|
23
|
+
````
|
24
|
+
|
25
|
+
Thanks to [Cedric Sohrauer](https://github.com/cedrics)
|
10
26
|
|
11
27
|
# 3.16.0
|
12
28
|
|
data/README.md
CHANGED
@@ -1166,6 +1166,9 @@ People who submitted patches and new features or suggested improvements. Many th
|
|
1166
1166
|
* Timmitry
|
1167
1167
|
* Michael Fairley
|
1168
1168
|
* Ray Zane
|
1169
|
+
* Go Sueyoshi
|
1170
|
+
* Cedric Sohrauer
|
1171
|
+
* Akira Matsuda
|
1169
1172
|
|
1170
1173
|
For a full list of contributors you can visit the
|
1171
1174
|
[contributors](https://github.com/bblimke/webmock/contributors) page.
|
@@ -128,7 +128,11 @@ module WebMock
|
|
128
128
|
|
129
129
|
|
130
130
|
def ensure_actual_connection
|
131
|
-
|
131
|
+
if @socket.is_a?(StubSocket)
|
132
|
+
@socket&.close
|
133
|
+
@socket = nil
|
134
|
+
do_start
|
135
|
+
end
|
132
136
|
end
|
133
137
|
|
134
138
|
alias_method :start_with_connect, :start
|
@@ -232,13 +236,16 @@ class StubSocket #:nodoc:
|
|
232
236
|
attr_accessor :read_timeout, :continue_timeout, :write_timeout
|
233
237
|
|
234
238
|
def initialize(*args)
|
239
|
+
@closed = false
|
235
240
|
end
|
236
241
|
|
237
242
|
def closed?
|
238
|
-
@closed
|
243
|
+
@closed
|
239
244
|
end
|
240
245
|
|
241
246
|
def close
|
247
|
+
@closed = true
|
248
|
+
nil
|
242
249
|
end
|
243
250
|
|
244
251
|
def readuntil(*args)
|
@@ -251,6 +258,9 @@ class StubSocket #:nodoc:
|
|
251
258
|
class StubIO
|
252
259
|
def setsockopt(*args); end
|
253
260
|
def peer_cert; end
|
261
|
+
def peeraddr; ["AF_INET", 443, "127.0.0.1", "127.0.0.1"] end
|
262
|
+
def ssl_version; "TLSv1.3" end
|
263
|
+
def cipher; ["TLS_AES_128_GCM_SHA256", "TLSv1.3", 128, 128] end
|
254
264
|
end
|
255
265
|
end
|
256
266
|
|
@@ -281,6 +281,8 @@ module WebMock
|
|
281
281
|
if (@pattern).is_a?(Hash)
|
282
282
|
return true if @pattern.empty?
|
283
283
|
matching_body_hashes?(body_as_hash(body, content_type), @pattern, content_type)
|
284
|
+
elsif (@pattern).is_a?(Array)
|
285
|
+
matching_body_array?(body_as_hash(body, content_type), @pattern, content_type)
|
284
286
|
elsif (@pattern).is_a?(WebMock::Matchers::HashIncludingMatcher)
|
285
287
|
@pattern == body_as_hash(body, content_type)
|
286
288
|
else
|
@@ -344,19 +346,33 @@ module WebMock
|
|
344
346
|
def matching_body_hashes?(query_parameters, pattern, content_type)
|
345
347
|
return false unless query_parameters.is_a?(Hash)
|
346
348
|
return false unless query_parameters.keys.sort == pattern.keys.sort
|
347
|
-
|
349
|
+
|
350
|
+
query_parameters.all? do |key, actual|
|
348
351
|
expected = pattern[key]
|
352
|
+
matching_values(actual, expected, content_type)
|
353
|
+
end
|
354
|
+
end
|
349
355
|
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
+
def matching_body_array?(query_parameters, pattern, content_type)
|
357
|
+
return false unless query_parameters.is_a?(Array)
|
358
|
+
return false unless query_parameters.length == pattern.length
|
359
|
+
|
360
|
+
query_parameters.each_with_index do |actual, index|
|
361
|
+
expected = pattern[index]
|
362
|
+
reutrn false unless matching_values(actual, expected, content_type)
|
356
363
|
end
|
364
|
+
|
357
365
|
true
|
358
366
|
end
|
359
367
|
|
368
|
+
def matching_values(actual, expected, content_type)
|
369
|
+
return matching_body_hashes?(actual, expected, content_type) if actual.is_a?(Hash) && expected.is_a?(Hash)
|
370
|
+
return matching_body_array?(actual, expected, content_type) if actual.is_a?(Array) && expected.is_a?(Array)
|
371
|
+
|
372
|
+
expected = WebMock::Util::ValuesStringifier.stringify_values(expected) if url_encoded_body?(content_type)
|
373
|
+
expected === actual
|
374
|
+
end
|
375
|
+
|
360
376
|
def empty_string?(string)
|
361
377
|
string.nil? || string == ""
|
362
378
|
end
|
@@ -35,11 +35,11 @@ module WebMock
|
|
35
35
|
alias == eql?
|
36
36
|
|
37
37
|
def url_encoded?
|
38
|
-
!!(headers
|
38
|
+
!!(headers&.fetch('Content-Type', nil)&.start_with?('application/x-www-form-urlencoded'))
|
39
39
|
end
|
40
40
|
|
41
41
|
def json_headers?
|
42
|
-
!!(headers
|
42
|
+
!!(headers&.fetch('Content-Type', nil)&.start_with?('application/json'))
|
43
43
|
end
|
44
44
|
|
45
45
|
private
|
data/lib/webmock/version.rb
CHANGED
@@ -213,6 +213,22 @@ describe "Net:HTTP" do
|
|
213
213
|
end
|
214
214
|
end
|
215
215
|
|
216
|
+
if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.7.0')
|
217
|
+
it "uses the StubSocket to provide IP address" do
|
218
|
+
Net::HTTP.start("http://example.com") do |http|
|
219
|
+
expect(http.ipaddr).to eq("127.0.0.1")
|
220
|
+
end
|
221
|
+
end
|
222
|
+
end
|
223
|
+
|
224
|
+
it "defines common socket methods" do
|
225
|
+
Net::HTTP.start("http://example.com") do |http|
|
226
|
+
socket = http.instance_variable_get(:@socket)
|
227
|
+
expect(socket.io.ssl_version).to eq("TLSv1.3")
|
228
|
+
expect(socket.io.cipher).to eq(["TLS_AES_128_GCM_SHA256", "TLSv1.3", 128, 128])
|
229
|
+
end
|
230
|
+
end
|
231
|
+
|
216
232
|
describe "connecting on Net::HTTP.start" do
|
217
233
|
before(:each) do
|
218
234
|
@http = Net::HTTP.new('www.google.com', 443)
|
@@ -547,6 +547,12 @@ describe WebMock::RequestPattern do
|
|
547
547
|
body: "{\"a\":\"1\",\"b\":\"five\",\"c\":{\"d\":[\"e\",\"f\"]}}"))
|
548
548
|
end
|
549
549
|
|
550
|
+
it "should match if the request body has a top level array" do
|
551
|
+
expect(WebMock::RequestPattern.new(:post, 'www.example.com', body: [{a: 1}])).
|
552
|
+
to match(WebMock::RequestSignature.new(:post, "www.example.com",
|
553
|
+
headers: {content_type: content_type}, body: "[{\"a\":1}]"))
|
554
|
+
end
|
555
|
+
|
550
556
|
it "should not match when body is not json" do
|
551
557
|
expect(WebMock::RequestPattern.new(:post, 'www.example.com', body: body_hash)).
|
552
558
|
not_to match(WebMock::RequestSignature.new(:post, "www.example.com",
|
data/webmock.gemspec
CHANGED
@@ -8,7 +8,7 @@ Gem::Specification.new do |s|
|
|
8
8
|
s.platform = Gem::Platform::RUBY
|
9
9
|
s.authors = ['Bartosz Blimke']
|
10
10
|
s.email = ['bartosz.blimke@gmail.com']
|
11
|
-
s.homepage = '
|
11
|
+
s.homepage = 'https://github.com/bblimke/webmock'
|
12
12
|
s.summary = %q{Library for stubbing HTTP requests in Ruby.}
|
13
13
|
s.description = %q{WebMock allows stubbing HTTP requests and setting expectations on HTTP requests.}
|
14
14
|
s.license = "MIT"
|
@@ -21,7 +21,7 @@ Gem::Specification.new do |s|
|
|
21
21
|
'wiki_uri' => 'https://github.com/bblimke/webmock/wiki'
|
22
22
|
}
|
23
23
|
|
24
|
-
s.required_ruby_version = '>= 2.
|
24
|
+
s.required_ruby_version = '>= 2.3'
|
25
25
|
|
26
26
|
s.add_dependency 'addressable', '>= 2.8.0'
|
27
27
|
s.add_dependency 'crack', '>= 0.3.2'
|
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.
|
4
|
+
version: 3.17.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: 2022-08-
|
11
|
+
date: 2022-08-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: addressable
|
@@ -416,14 +416,14 @@ files:
|
|
416
416
|
- test/test_helper.rb
|
417
417
|
- test/test_webmock.rb
|
418
418
|
- webmock.gemspec
|
419
|
-
homepage:
|
419
|
+
homepage: https://github.com/bblimke/webmock
|
420
420
|
licenses:
|
421
421
|
- MIT
|
422
422
|
metadata:
|
423
423
|
bug_tracker_uri: https://github.com/bblimke/webmock/issues
|
424
|
-
changelog_uri: https://github.com/bblimke/webmock/blob/v3.
|
425
|
-
documentation_uri: https://www.rubydoc.info/gems/webmock/3.
|
426
|
-
source_code_uri: https://github.com/bblimke/webmock/tree/v3.
|
424
|
+
changelog_uri: https://github.com/bblimke/webmock/blob/v3.17.0/CHANGELOG.md
|
425
|
+
documentation_uri: https://www.rubydoc.info/gems/webmock/3.17.0
|
426
|
+
source_code_uri: https://github.com/bblimke/webmock/tree/v3.17.0
|
427
427
|
wiki_uri: https://github.com/bblimke/webmock/wiki
|
428
428
|
post_install_message:
|
429
429
|
rdoc_options: []
|
@@ -433,7 +433,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
433
433
|
requirements:
|
434
434
|
- - ">="
|
435
435
|
- !ruby/object:Gem::Version
|
436
|
-
version: '2.
|
436
|
+
version: '2.3'
|
437
437
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
438
438
|
requirements:
|
439
439
|
- - ">="
|