webmock 3.22.0 → 3.23.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ecff3692887f15d1f0e2e19df92093a40d4f6e5f7e4686d7e18ee4efaadf190f
4
- data.tar.gz: 6cf4e165350b7878223e28687db13d57df6fe07d90f50a087527d5d001b305e6
3
+ metadata.gz: 4cfe9b7372b311f25b6b531efc50e11297e19cb325306132b889bf2d67ab3fec
4
+ data.tar.gz: 4448d921dc29e08024392f7fe0c8ab5a832920a6e749801e1ca2257a1c050e0b
5
5
  SHA512:
6
- metadata.gz: 566cf68fd9c0ee2de8c5e54693e0caa2b956c537f9b82362b7eb7547214349b7966029d6cf12dcac0ca930b0b0f9ad2c32c7dace3a2bd84d43eecd488b194144
7
- data.tar.gz: a69faa775b378ee5108525cd431ab9bf242ac93afeb5fc351a7549aa852099fc9c84ceef4a6dccf265e7e27ed5e0894937a1abbc4fa9a641d9fb9c51c0e8ff90
6
+ metadata.gz: b6afe5a627d5c3c1498e5b4f35d07f9118977af57f4b7915b04bdeb67f2eb676bbbf5bfc28a895681c6635fe74d736d9a83d50916c2f80b1adb4b68d455de283
7
+ data.tar.gz: 8843478e3cbcd78b3e4cc6d6a09c757ff02328549ea37768f23d721adb3721ab0daf49a000fcc8fa600382964538d6bc5aec7a6d1fdde4668a608b3b2b6fda08
data/CHANGELOG.md CHANGED
@@ -1,10 +1,21 @@
1
1
  # Changelog
2
2
 
3
+ # 3.23.1
4
+
5
+ * Added support for async-http version >= 0.65.0 [PR](https://github.com/bblimke/webmock/pull/1056)
6
+
7
+ Thanks to [Jacob Frautschi](https://github.com/jakeonfire)
8
+
9
+ # 3.23.0
10
+
11
+ * Fixed HTTP.rb adapter to support streaming real responses when WebMock is enabled.
12
+
13
+ Thanks to [Viacheslav Nepomniashchikh](https://github.com/aka-nez) for reporting and investigating this [issue](https://github.com/bblimke/webmock/issues/1017).
14
+
3
15
  # 3.22.0
4
16
 
5
17
  * Addressed an issue in the HTTPClient adapter where memoized stubbed responses and memoized request_signatures were incorrectly persisted between subsequent requests ([#1019](https://github.com/bblimke/webmock/issues/1019)). The implementation of a more robust thread-safety solution by [Tom Beauvais](https://github.com/tbeauvais) in [PR #300](https://github.com/bblimke/webmock/pull/300) not only resolved the memoization problem but also enhanced the overall thread safety of the adapter. This update ensures that stubbed responses and request signatures are correctly isolated to individual requests, improving both consistency and thread safety.
6
18
 
7
-
8
19
  # 3.21.2
9
20
 
10
21
  * Corrected type checking in `WebMock::Response#assert_valid_body!` to accurately recognize `Hash` objects. Additionally, improved the clarity of the error message for unsupported body types, guiding users towards proper usage.
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  WebMock
2
2
  =======
3
3
  [![Gem Version](https://badge.fury.io/rb/webmock.svg)](http://badge.fury.io/rb/webmock)
4
- [![Build Status](https://github.com/bblimke/webmock/workflows/CI/badge.svg?branch=master)](https://github.com/bblimke/webmock/actions)
4
+ [![Build Status](https://github.com/bblimke/webmock/actions/workflows/CI.yml/badge.svg?branch=master)](https://github.com/bblimke/webmock/actions)
5
5
  [![Code Climate](https://codeclimate.com/github/bblimke/webmock/badges/gpa.svg)](https://codeclimate.com/github/bblimke/webmock)
6
6
  [![Mentioned in Awesome Ruby](https://awesome.re/mentioned-badge.svg)](https://github.com/markets/awesome-ruby)
7
7
 
@@ -43,6 +43,7 @@ Supported Ruby Interpreters
43
43
  * MRI 3.0
44
44
  * MRI 3.1
45
45
  * MRI 3.2
46
+ * MRI 3.3
46
47
  * JRuby
47
48
 
48
49
  ## Installation
@@ -1202,6 +1203,7 @@ People who submitted patches and new features or suggested improvements. Many th
1202
1203
  * Victor Maslov
1203
1204
  * Gio Lodi
1204
1205
  * Ryan Brooks
1206
+ * Jacob Frautschi
1205
1207
 
1206
1208
  For a full list of contributors you can visit the
1207
1209
  [contributors](https://github.com/bblimke/webmock/contributors) page.
@@ -152,11 +152,15 @@ if defined?(Async::HTTP)
152
152
 
153
153
  private
154
154
 
155
+ def socket_class
156
+ defined?(Async::IO::Socket) ? Async::IO::Socket : Socket
157
+ end
158
+
155
159
  def create_connected_sockets
156
160
  pair = begin
157
- Async::IO::Socket.pair(Socket::AF_UNIX, Socket::SOCK_STREAM)
161
+ socket_class.pair(Socket::AF_UNIX, Socket::SOCK_STREAM)
158
162
  rescue Errno::EAFNOSUPPORT
159
- Async::IO::Socket.pair(Socket::AF_INET, Socket::SOCK_STREAM)
163
+ socket_class.pair(Socket::AF_INET, Socket::SOCK_STREAM)
160
164
  end
161
165
  pair.tap do |sockets|
162
166
  sockets.each do |socket|
@@ -6,9 +6,19 @@ module HTTP
6
6
  webmock_response = ::WebMock::Response.new
7
7
 
8
8
  webmock_response.status = [status.to_i, reason]
9
+
9
10
  webmock_response.body = body.to_s
10
- webmock_response.headers = headers.to_h
11
+ # This call is used to reset the body of the response to enable it to be streamed if necessary.
12
+ # The `body.to_s` call above reads the body, which allows WebMock to trigger any registered callbacks.
13
+ # However, once the body is read to_s, it cannot be streamed again and attempting to do so
14
+ # will raise a "HTTP::StateError: body has already been consumed" error.
15
+ # To avoid this error, we replace the original body with a new one.
16
+ # The new body has its @stream attribute set to new Streamer, instead of the original Connection.
17
+ # Unfortunately, it's not possible to reset the original body to its initial streaming state.
18
+ # Therefore, this replacement is the best workaround currently available.
19
+ reset_body_to_allow_it_to_be_streamed!(webmock_response)
11
20
 
21
+ webmock_response.headers = headers.to_h
12
22
  webmock_response
13
23
  end
14
24
 
@@ -21,16 +31,7 @@ module HTTP
21
31
  # HTTP.rb 3.0+ uses a keyword argument to pass the encoding, but 1.x
22
32
  # and 2.x use a positional argument, and 0.x don't support supplying
23
33
  # the encoding.
24
- body = if HTTP::VERSION < "1.0.0"
25
- Body.new(Streamer.new(webmock_response.body))
26
- elsif HTTP::VERSION < "3.0.0"
27
- Body.new(Streamer.new(webmock_response.body), webmock_response.body.encoding)
28
- else
29
- Body.new(
30
- Streamer.new(webmock_response.body, encoding: webmock_response.body.encoding),
31
- encoding: webmock_response.body.encoding
32
- )
33
- end
34
+ body = build_http_rb_response_body_from_webmock_response(webmock_response)
34
35
 
35
36
  return new(status, "1.1", headers, body, uri) if HTTP::VERSION < "1.0.0"
36
37
 
@@ -54,7 +55,18 @@ module HTTP
54
55
  })
55
56
  end
56
57
 
57
- private
58
+ def build_http_rb_response_body_from_webmock_response(webmock_response)
59
+ if HTTP::VERSION < "1.0.0"
60
+ Body.new(Streamer.new(webmock_response.body))
61
+ elsif HTTP::VERSION < "3.0.0"
62
+ Body.new(Streamer.new(webmock_response.body), webmock_response.body.encoding)
63
+ else
64
+ Body.new(
65
+ Streamer.new(webmock_response.body, encoding: webmock_response.body.encoding),
66
+ encoding: webmock_response.body.encoding
67
+ )
68
+ end
69
+ end
58
70
 
59
71
  def normalize_uri(uri)
60
72
  return unless uri
@@ -65,5 +77,11 @@ module HTTP
65
77
  uri
66
78
  end
67
79
  end
80
+
81
+ private
82
+
83
+ def reset_body_to_allow_it_to_be_streamed!(webmock_response)
84
+ @body = self.class.build_http_rb_response_body_from_webmock_response(webmock_response)
85
+ end
68
86
  end
69
87
  end
@@ -31,9 +31,9 @@ if defined?(HTTP) && defined?(HTTP::VERSION)
31
31
  end
32
32
  end
33
33
 
34
- require "webmock/http_lib_adapters/http_rb/client"
35
- require "webmock/http_lib_adapters/http_rb/request"
36
- require "webmock/http_lib_adapters/http_rb/response"
37
- require "webmock/http_lib_adapters/http_rb/streamer"
38
- require "webmock/http_lib_adapters/http_rb/webmock"
34
+ require_relative "http_rb/client"
35
+ require_relative "http_rb/request"
36
+ require_relative "http_rb/response"
37
+ require_relative "http_rb/streamer"
38
+ require_relative "http_rb/webmock"
39
39
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module WebMock
4
- VERSION = '3.22.0' unless defined?(::WebMock::VERSION)
4
+ VERSION = '3.23.1' unless defined?(::WebMock::VERSION)
5
5
  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.22.0
4
+ version: 3.23.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bartosz Blimke
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-02-21 00:00:00.000000000 Z
11
+ date: 2024-05-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable
@@ -371,9 +371,9 @@ licenses:
371
371
  - MIT
372
372
  metadata:
373
373
  bug_tracker_uri: https://github.com/bblimke/webmock/issues
374
- changelog_uri: https://github.com/bblimke/webmock/blob/v3.22.0/CHANGELOG.md
375
- documentation_uri: https://www.rubydoc.info/gems/webmock/3.22.0
376
- source_code_uri: https://github.com/bblimke/webmock/tree/v3.22.0
374
+ changelog_uri: https://github.com/bblimke/webmock/blob/v3.23.1/CHANGELOG.md
375
+ documentation_uri: https://www.rubydoc.info/gems/webmock/3.23.1
376
+ source_code_uri: https://github.com/bblimke/webmock/tree/v3.23.1
377
377
  wiki_uri: https://github.com/bblimke/webmock/wiki
378
378
  post_install_message:
379
379
  rdoc_options: []
@@ -390,7 +390,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
390
390
  - !ruby/object:Gem::Version
391
391
  version: '0'
392
392
  requirements: []
393
- rubygems_version: 3.5.6
393
+ rubygems_version: 3.5.7
394
394
  signing_key:
395
395
  specification_version: 4
396
396
  summary: Library for stubbing HTTP requests in Ruby.