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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 438dab0f90920381d01009b8c75892ac83e46043e170c17e1dba5e46ca755c61
4
- data.tar.gz: a760f4b2399f465c62cf03268c13a7ae973900945ed0c4631e146c44f688a97d
3
+ metadata.gz: e83aa4c98567eb2c64f39136600540212c108d9d5596119c81d26457757f5233
4
+ data.tar.gz: 78547f4192e94786194a63d4a7c93e144b1a5781c95619e869984d0438dad69d
5
5
  SHA512:
6
- metadata.gz: c8033597431b3e8ce43e60837d31f18d1ffa52c35079827e122a4616587f29b480b2340786c841bbe9f6b9390c5df08e9b84e933160412c8dc1d5c8a9b214f8b
7
- data.tar.gz: e0580a7b6b712073edf7d6c38fbf7b6df00a294aa9910f1de0e2de61535de67d07315b5d10f141d7e3387bf91aaee7ce6bb204d40190b5357b2120dc0d7d4427
6
+ metadata.gz: 6461f17c27d962adc571dc23a9f6f232e4855c71384f7dcb6d8f6132497f46c46c7e196d75d75e920605f5fdc8a70962ac4ea61cd2109340ebb0b6a7cd6a5782
7
+ data.tar.gz: '084c4a3a1225eb9b1bd159a831eb9a8dd488493b0253c28773514c6966e0ae89c9f778f14f68ff67d57d7382b6582790f226ae1708c096e28661d4936aacf5e1'
data/CHANGELOG.md CHANGED
@@ -1,12 +1,28 @@
1
1
  # Changelog
2
2
 
3
- # 3.16.2
3
+ # 3.17.0
4
4
 
5
- * Minimum required Ruby version is 2.0 again.
5
+ * Minimum required Ruby version is 2.3
6
6
 
7
- # 3.16.1
7
+ Thanks to [Go Sueyoshi](https://github.com/sue445)
8
8
 
9
- * Minimum required Ruby version is 2.3
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
- do_start if @socket.is_a?(StubSocket)
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 ||= true
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
- query_parameters.each do |key, actual|
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
- if actual.is_a?(Hash) && expected.is_a?(Hash)
351
- return false unless matching_body_hashes?(actual, expected, content_type)
352
- else
353
- expected = WebMock::Util::ValuesStringifier.stringify_values(expected) if url_encoded_body?(content_type)
354
- return false unless expected === actual
355
- end
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 && headers.fetch('Content-Type', "").start_with?('application/x-www-form-urlencoded'))
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 && headers.fetch('Content-Type', "").start_with?('application/json'))
42
+ !!(headers&.fetch('Content-Type', nil)&.start_with?('application/json'))
43
43
  end
44
44
 
45
45
  private
@@ -1,3 +1,3 @@
1
1
  module WebMock
2
- VERSION = '3.16.2' unless defined?(::WebMock::VERSION)
2
+ VERSION = '3.17.0' unless defined?(::WebMock::VERSION)
3
3
  end
@@ -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 = 'http://github.com/bblimke/webmock'
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.0'
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.16.2
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-10 00:00:00.000000000 Z
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: http://github.com/bblimke/webmock
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.16.2/CHANGELOG.md
425
- documentation_uri: https://www.rubydoc.info/gems/webmock/3.16.2
426
- source_code_uri: https://github.com/bblimke/webmock/tree/v3.16.2
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.0'
436
+ version: '2.3'
437
437
  required_rubygems_version: !ruby/object:Gem::Requirement
438
438
  requirements:
439
439
  - - ">="