webmock 3.5.0 → 3.25.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 +476 -2
- data/README.md +166 -42
- data/lib/webmock/api.rb +2 -0
- data/lib/webmock/assertion_failure.rb +2 -0
- data/lib/webmock/callback_registry.rb +2 -0
- data/lib/webmock/config.rb +2 -0
- data/lib/webmock/cucumber.rb +2 -0
- data/lib/webmock/deprecation.rb +2 -0
- data/lib/webmock/errors.rb +2 -0
- data/lib/webmock/http_lib_adapters/async_http_client_adapter.rb +228 -0
- data/lib/webmock/http_lib_adapters/curb_adapter.rb +14 -3
- data/lib/webmock/http_lib_adapters/em_http_request_adapter.rb +22 -9
- data/lib/webmock/http_lib_adapters/excon_adapter.rb +5 -0
- data/lib/webmock/http_lib_adapters/http_lib_adapter.rb +2 -0
- data/lib/webmock/http_lib_adapters/http_lib_adapter_registry.rb +2 -0
- data/lib/webmock/http_lib_adapters/http_rb/client.rb +4 -1
- data/lib/webmock/http_lib_adapters/http_rb/request.rb +17 -5
- data/lib/webmock/http_lib_adapters/http_rb/response.rb +49 -5
- data/lib/webmock/http_lib_adapters/http_rb/streamer.rb +11 -3
- data/lib/webmock/http_lib_adapters/http_rb/webmock.rb +8 -2
- data/lib/webmock/http_lib_adapters/http_rb_adapter.rb +7 -5
- data/lib/webmock/http_lib_adapters/httpclient_adapter.rb +25 -7
- data/lib/webmock/http_lib_adapters/manticore_adapter.rb +35 -15
- data/lib/webmock/http_lib_adapters/net_http.rb +59 -112
- data/lib/webmock/http_lib_adapters/net_http_response.rb +3 -1
- data/lib/webmock/http_lib_adapters/patron_adapter.rb +4 -2
- data/lib/webmock/http_lib_adapters/typhoeus_hydra_adapter.rb +18 -2
- data/lib/webmock/matchers/any_arg_matcher.rb +2 -0
- data/lib/webmock/matchers/hash_argument_matcher.rb +2 -0
- data/lib/webmock/matchers/hash_excluding_matcher.rb +2 -0
- data/lib/webmock/matchers/hash_including_matcher.rb +2 -0
- data/lib/webmock/minitest.rb +2 -0
- data/lib/webmock/rack_response.rb +5 -1
- data/lib/webmock/request_body_diff.rb +3 -1
- data/lib/webmock/request_execution_verifier.rb +2 -0
- data/lib/webmock/request_pattern.rb +118 -61
- data/lib/webmock/request_registry.rb +2 -0
- data/lib/webmock/request_signature.rb +4 -2
- data/lib/webmock/request_signature_snippet.rb +2 -0
- data/lib/webmock/request_stub.rb +34 -0
- data/lib/webmock/response.rb +22 -14
- data/lib/webmock/responses_sequence.rb +2 -0
- data/lib/webmock/rspec/matchers/request_pattern_matcher.rb +2 -0
- data/lib/webmock/rspec/matchers/webmock_matcher.rb +2 -0
- data/lib/webmock/rspec/matchers.rb +2 -0
- data/lib/webmock/rspec.rb +4 -1
- data/lib/webmock/stub_registry.rb +28 -11
- data/lib/webmock/stub_request_snippet.rb +2 -0
- data/lib/webmock/test_unit.rb +3 -3
- data/lib/webmock/util/hash_counter.rb +12 -6
- data/lib/webmock/util/hash_keys_stringifier.rb +2 -0
- data/lib/webmock/util/hash_validator.rb +2 -0
- data/lib/webmock/util/headers.rb +23 -10
- data/lib/webmock/util/parsers/json.rb +72 -0
- data/lib/webmock/util/parsers/parse_error.rb +7 -0
- data/lib/webmock/util/parsers/xml.rb +16 -0
- data/lib/webmock/util/query_mapper.rb +6 -2
- data/lib/webmock/util/uri.rb +11 -9
- data/lib/webmock/util/values_stringifier.rb +2 -0
- data/lib/webmock/util/version_checker.rb +7 -5
- data/lib/webmock/version.rb +3 -1
- data/lib/webmock/webmock.rb +22 -3
- data/lib/webmock.rb +5 -2
- metadata +99 -175
- data/.gemtest +0 -0
- data/.gitignore +0 -34
- data/.rspec-tm +0 -2
- data/.travis.yml +0 -21
- data/Gemfile +0 -9
- data/Rakefile +0 -30
- data/lib/webmock/util/json.rb +0 -67
- data/minitest/test_helper.rb +0 -34
- data/minitest/test_webmock.rb +0 -9
- data/minitest/webmock_spec.rb +0 -60
- data/spec/acceptance/curb/curb_spec.rb +0 -481
- data/spec/acceptance/curb/curb_spec_helper.rb +0 -147
- data/spec/acceptance/em_http_request/em_http_request_spec.rb +0 -406
- data/spec/acceptance/em_http_request/em_http_request_spec_helper.rb +0 -77
- data/spec/acceptance/excon/excon_spec.rb +0 -77
- data/spec/acceptance/excon/excon_spec_helper.rb +0 -50
- data/spec/acceptance/http_rb/http_rb_spec.rb +0 -82
- data/spec/acceptance/http_rb/http_rb_spec_helper.rb +0 -54
- data/spec/acceptance/httpclient/httpclient_spec.rb +0 -217
- data/spec/acceptance/httpclient/httpclient_spec_helper.rb +0 -57
- data/spec/acceptance/manticore/manticore_spec.rb +0 -56
- data/spec/acceptance/manticore/manticore_spec_helper.rb +0 -35
- data/spec/acceptance/net_http/net_http_shared.rb +0 -153
- data/spec/acceptance/net_http/net_http_spec.rb +0 -331
- data/spec/acceptance/net_http/net_http_spec_helper.rb +0 -64
- data/spec/acceptance/net_http/real_net_http_spec.rb +0 -20
- data/spec/acceptance/patron/patron_spec.rb +0 -125
- data/spec/acceptance/patron/patron_spec_helper.rb +0 -54
- data/spec/acceptance/shared/allowing_and_disabling_net_connect.rb +0 -313
- data/spec/acceptance/shared/callbacks.rb +0 -147
- data/spec/acceptance/shared/complex_cross_concern_behaviors.rb +0 -36
- data/spec/acceptance/shared/enabling_and_disabling_webmock.rb +0 -95
- data/spec/acceptance/shared/precedence_of_stubs.rb +0 -15
- data/spec/acceptance/shared/request_expectations.rb +0 -923
- data/spec/acceptance/shared/returning_declared_responses.rb +0 -388
- data/spec/acceptance/shared/stubbing_requests.rb +0 -638
- data/spec/acceptance/typhoeus/typhoeus_hydra_spec.rb +0 -135
- data/spec/acceptance/typhoeus/typhoeus_hydra_spec_helper.rb +0 -60
- data/spec/acceptance/webmock_shared.rb +0 -41
- data/spec/fixtures/test.txt +0 -1
- data/spec/quality_spec.rb +0 -84
- data/spec/spec_helper.rb +0 -48
- data/spec/support/example_curl_output.txt +0 -22
- data/spec/support/failures.rb +0 -9
- data/spec/support/my_rack_app.rb +0 -53
- data/spec/support/network_connection.rb +0 -19
- data/spec/support/webmock_server.rb +0 -69
- data/spec/unit/api_spec.rb +0 -175
- data/spec/unit/errors_spec.rb +0 -129
- data/spec/unit/http_lib_adapters/http_lib_adapter_registry_spec.rb +0 -17
- data/spec/unit/http_lib_adapters/http_lib_adapter_spec.rb +0 -12
- data/spec/unit/matchers/hash_excluding_matcher_spec.rb +0 -61
- data/spec/unit/matchers/hash_including_matcher_spec.rb +0 -87
- data/spec/unit/rack_response_spec.rb +0 -112
- data/spec/unit/request_body_diff_spec.rb +0 -90
- data/spec/unit/request_execution_verifier_spec.rb +0 -208
- data/spec/unit/request_pattern_spec.rb +0 -596
- data/spec/unit/request_registry_spec.rb +0 -95
- data/spec/unit/request_signature_snippet_spec.rb +0 -89
- data/spec/unit/request_signature_spec.rb +0 -155
- data/spec/unit/request_stub_spec.rb +0 -199
- data/spec/unit/response_spec.rb +0 -282
- data/spec/unit/stub_registry_spec.rb +0 -103
- data/spec/unit/stub_request_snippet_spec.rb +0 -115
- data/spec/unit/util/hash_counter_spec.rb +0 -39
- data/spec/unit/util/hash_keys_stringifier_spec.rb +0 -27
- data/spec/unit/util/headers_spec.rb +0 -28
- data/spec/unit/util/json_spec.rb +0 -33
- data/spec/unit/util/query_mapper_spec.rb +0 -150
- data/spec/unit/util/uri_spec.rb +0 -299
- data/spec/unit/util/version_checker_spec.rb +0 -65
- data/spec/unit/webmock_spec.rb +0 -11
- data/test/http_request.rb +0 -24
- data/test/shared_test.rb +0 -108
- data/test/test_helper.rb +0 -23
- data/test/test_webmock.rb +0 -6
- data/webmock.gemspec +0 -46
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'net/http'
|
2
4
|
require 'net/https'
|
3
5
|
require 'stringio'
|
@@ -10,24 +12,25 @@ module WebMock
|
|
10
12
|
adapter_for :net_http
|
11
13
|
|
12
14
|
OriginalNetHTTP = Net::HTTP unless const_defined?(:OriginalNetHTTP)
|
13
|
-
|
15
|
+
# This will be removed in Ruby 3.5. In Ruby 3.4, const_remove will warn.
|
16
|
+
HAS_LEGACY_CONSTANT = Net.const_defined?(:HTTPSession)
|
14
17
|
|
15
18
|
def self.enable!
|
16
|
-
Net.send(:remove_const, :BufferedIO)
|
17
19
|
Net.send(:remove_const, :HTTP)
|
18
|
-
Net.send(:remove_const, :HTTPSession)
|
19
20
|
Net.send(:const_set, :HTTP, @webMockNetHTTP)
|
20
|
-
|
21
|
-
|
21
|
+
if HAS_LEGACY_CONSTANT
|
22
|
+
remove_silently(Net, :HTTPSession)
|
23
|
+
Net.send(:const_set, :HTTPSession, @webMockNetHTTP)
|
24
|
+
end
|
22
25
|
end
|
23
26
|
|
24
27
|
def self.disable!
|
25
|
-
Net.send(:remove_const, :BufferedIO)
|
26
28
|
Net.send(:remove_const, :HTTP)
|
27
|
-
Net.send(:remove_const, :HTTPSession)
|
28
29
|
Net.send(:const_set, :HTTP, OriginalNetHTTP)
|
29
|
-
|
30
|
-
|
30
|
+
if HAS_LEGACY_CONSTANT
|
31
|
+
remove_silently(Net, :HTTPSession)
|
32
|
+
Net.send(:const_set, :HTTPSession, OriginalNetHTTP)
|
33
|
+
end
|
31
34
|
|
32
35
|
#copy all constants from @webMockNetHTTP to original Net::HTTP
|
33
36
|
#in case any constants were added to @webMockNetHTTP instead of Net::HTTP
|
@@ -40,6 +43,14 @@ module WebMock
|
|
40
43
|
end
|
41
44
|
end
|
42
45
|
|
46
|
+
def self.remove_silently(mod, const) #:nodoc:
|
47
|
+
# Don't warn on removing the deprecated constant
|
48
|
+
verbose, $VERBOSE = $VERBOSE, nil
|
49
|
+
mod.send(:remove_const, const)
|
50
|
+
ensure
|
51
|
+
$VERBOSE = verbose
|
52
|
+
end
|
53
|
+
|
43
54
|
@webMockNetHTTP = Class.new(Net::HTTP) do
|
44
55
|
class << self
|
45
56
|
def socket_type
|
@@ -80,7 +91,7 @@ module WebMock
|
|
80
91
|
@socket = Net::HTTP.socket_type.new
|
81
92
|
WebMock::CallbackRegistry.invoke_callbacks(
|
82
93
|
{lib: :net_http}, request_signature, webmock_response)
|
83
|
-
build_net_http_response(webmock_response, &block)
|
94
|
+
build_net_http_response(webmock_response, request.uri, &block)
|
84
95
|
elsif WebMock.net_connect_allowed?(request_signature.uri)
|
85
96
|
check_right_http_connection
|
86
97
|
after_request = lambda do |response|
|
@@ -98,13 +109,8 @@ module WebMock
|
|
98
109
|
after_request.call(response)
|
99
110
|
}
|
100
111
|
if started?
|
101
|
-
|
102
|
-
|
103
|
-
else
|
104
|
-
start_with_connect_without_finish {
|
105
|
-
super_with_after_request.call
|
106
|
-
}
|
107
|
-
end
|
112
|
+
ensure_actual_connection
|
113
|
+
super_with_after_request.call
|
108
114
|
else
|
109
115
|
start_with_connect {
|
110
116
|
super_with_after_request.call
|
@@ -119,39 +125,40 @@ module WebMock
|
|
119
125
|
raise IOError, 'HTTP session already opened' if @started
|
120
126
|
if block_given?
|
121
127
|
begin
|
128
|
+
@socket = Net::HTTP.socket_type.new
|
122
129
|
@started = true
|
123
130
|
return yield(self)
|
124
131
|
ensure
|
125
132
|
do_finish
|
126
133
|
end
|
127
134
|
end
|
135
|
+
@socket = Net::HTTP.socket_type.new
|
128
136
|
@started = true
|
129
137
|
self
|
130
138
|
end
|
131
139
|
|
132
140
|
|
133
|
-
def
|
134
|
-
if
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
end
|
141
|
+
def ensure_actual_connection
|
142
|
+
if @socket.is_a?(StubSocket)
|
143
|
+
@socket&.close
|
144
|
+
@socket = nil
|
145
|
+
do_start
|
139
146
|
end
|
140
|
-
do_start
|
141
|
-
self
|
142
147
|
end
|
143
148
|
|
144
149
|
alias_method :start_with_connect, :start
|
145
150
|
|
146
151
|
def start(&block)
|
147
|
-
|
152
|
+
uri = Addressable::URI.parse(WebMock::NetHTTPUtility.get_uri(self))
|
153
|
+
|
154
|
+
if WebMock.net_http_connect_on_start?(uri)
|
148
155
|
super(&block)
|
149
156
|
else
|
150
157
|
start_without_connect(&block)
|
151
158
|
end
|
152
159
|
end
|
153
160
|
|
154
|
-
def build_net_http_response(webmock_response, &block)
|
161
|
+
def build_net_http_response(webmock_response, request_uri, &block)
|
155
162
|
response = Net::HTTPResponse.send(:response_class, webmock_response.status[0].to_s).new("1.0", webmock_response.status[0].to_s, webmock_response.status[1])
|
156
163
|
body = webmock_response.body
|
157
164
|
body = nil if webmock_response.status[0].to_s == '204'
|
@@ -166,10 +173,12 @@ module WebMock
|
|
166
173
|
|
167
174
|
response.instance_variable_set(:@read, true)
|
168
175
|
|
176
|
+
response.uri = request_uri
|
177
|
+
|
169
178
|
response.extend Net::WebMockHTTPResponse
|
170
179
|
|
171
180
|
if webmock_response.should_timeout
|
172
|
-
raise
|
181
|
+
raise Net::OpenTimeout, "execution expired"
|
173
182
|
end
|
174
183
|
|
175
184
|
webmock_response.raise_error_if_any
|
@@ -179,16 +188,6 @@ module WebMock
|
|
179
188
|
response
|
180
189
|
end
|
181
190
|
|
182
|
-
def timeout_exception
|
183
|
-
if defined?(Net::OpenTimeout)
|
184
|
-
# Ruby 2.x
|
185
|
-
Net::OpenTimeout
|
186
|
-
else
|
187
|
-
# Fallback, if things change
|
188
|
-
Timeout::Error
|
189
|
-
end
|
190
|
-
end
|
191
|
-
|
192
191
|
def build_webmock_response(net_http_response)
|
193
192
|
webmock_response = WebMock::Response.new
|
194
193
|
webmock_response.status = [
|
@@ -222,84 +221,43 @@ module WebMock
|
|
222
221
|
end
|
223
222
|
end
|
224
223
|
|
225
|
-
# patch for StringIO behavior in Ruby 2.2.3
|
226
|
-
# https://github.com/bblimke/webmock/issues/558
|
227
|
-
class PatchedStringIO < StringIO #:nodoc:
|
228
|
-
|
229
|
-
alias_method :orig_read_nonblock, :read_nonblock
|
230
|
-
|
231
|
-
def read_nonblock(size, *args)
|
232
|
-
orig_read_nonblock(size)
|
233
|
-
end
|
234
|
-
|
235
|
-
end
|
236
|
-
|
237
224
|
class StubSocket #:nodoc:
|
238
225
|
|
239
|
-
attr_accessor :read_timeout, :continue_timeout
|
226
|
+
attr_accessor :read_timeout, :continue_timeout, :write_timeout
|
240
227
|
|
241
228
|
def initialize(*args)
|
229
|
+
@closed = false
|
242
230
|
end
|
243
231
|
|
244
232
|
def closed?
|
245
|
-
@closed
|
233
|
+
@closed
|
246
234
|
end
|
247
235
|
|
248
236
|
def close
|
237
|
+
@closed = true
|
238
|
+
nil
|
249
239
|
end
|
250
240
|
|
251
241
|
def readuntil(*args)
|
252
242
|
end
|
253
243
|
|
254
|
-
|
255
|
-
|
256
|
-
module Net #:nodoc: all
|
257
|
-
|
258
|
-
class WebMockNetBufferedIO < BufferedIO
|
259
|
-
def initialize(io, read_timeout: 60, write_timeout: 60, continue_timeout: nil, debug_output: nil)
|
260
|
-
@read_timeout = read_timeout
|
261
|
-
@write_timeout = write_timeout
|
262
|
-
@rbuf = ''.dup
|
263
|
-
@debug_output = debug_output
|
264
|
-
|
265
|
-
@io = case io
|
266
|
-
when Socket, OpenSSL::SSL::SSLSocket, IO
|
267
|
-
io
|
268
|
-
when StringIO
|
269
|
-
PatchedStringIO.new(io.string)
|
270
|
-
when String
|
271
|
-
PatchedStringIO.new(io)
|
272
|
-
end
|
273
|
-
raise "Unable to create local socket" unless @io
|
274
|
-
end
|
275
|
-
|
276
|
-
if RUBY_VERSION >= '2.6.0'
|
277
|
-
def rbuf_fill
|
278
|
-
current_thread_id = Thread.current.object_id
|
279
|
-
|
280
|
-
trace = TracePoint.trace(:line) do |tp|
|
281
|
-
next unless Thread.current.object_id == current_thread_id
|
282
|
-
if tp.binding.local_variable_defined?(:tmp)
|
283
|
-
tp.binding.local_variable_set(:tmp, nil)
|
284
|
-
end
|
285
|
-
end
|
286
|
-
|
287
|
-
super
|
288
|
-
|
289
|
-
trace.disable
|
290
|
-
end
|
291
|
-
end
|
244
|
+
def io
|
245
|
+
@io ||= StubIO.new
|
292
246
|
end
|
293
247
|
|
248
|
+
class StubIO
|
249
|
+
def setsockopt(*args); end
|
250
|
+
def peer_cert; end
|
251
|
+
def peeraddr; ["AF_INET", 443, "127.0.0.1", "127.0.0.1"] end
|
252
|
+
def ssl_version; "TLSv1.3" end
|
253
|
+
def cipher; ["TLS_AES_128_GCM_SHA256", "TLSv1.3", 128, 128] end
|
254
|
+
end
|
294
255
|
end
|
295
256
|
|
296
|
-
|
297
257
|
module WebMock
|
298
258
|
module NetHTTPUtility
|
299
259
|
|
300
260
|
def self.request_signature_from_request(net_http, request, body = nil)
|
301
|
-
protocol = net_http.use_ssl? ? "https" : "http"
|
302
|
-
|
303
261
|
path = request.path
|
304
262
|
|
305
263
|
if path.respond_to?(:request_uri) #https://github.com/bblimke/webmock/issues/288
|
@@ -308,11 +266,10 @@ module WebMock
|
|
308
266
|
|
309
267
|
path = WebMock::Util::URI.heuristic_parse(path).request_uri if path =~ /^http/
|
310
268
|
|
311
|
-
uri =
|
269
|
+
uri = get_uri(net_http, path)
|
312
270
|
method = request.method.downcase.to_sym
|
313
271
|
|
314
272
|
headers = Hash[*request.to_hash.map {|k,v| [k, v]}.inject([]) {|r,x| r + x}]
|
315
|
-
validate_headers(headers)
|
316
273
|
|
317
274
|
if request.body_stream
|
318
275
|
body = request.body_stream.read
|
@@ -328,23 +285,13 @@ module WebMock
|
|
328
285
|
WebMock::RequestSignature.new(method, uri, body: request.body, headers: headers)
|
329
286
|
end
|
330
287
|
|
331
|
-
def self.
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
#
|
336
|
-
|
337
|
-
#
|
338
|
-
# This could create a false positive in a test suite with WebMock.
|
339
|
-
#
|
340
|
-
# So before this point, WebMock raises an ArgumentError if any of the headers are symbols
|
341
|
-
# instead of the cryptic NoMethodError "undefined method `split' ...` from Net::HTTP
|
342
|
-
if Gem::Version.new(RUBY_VERSION.dup) < Gem::Version.new('2.3.0')
|
343
|
-
header_as_symbol = headers.keys.find {|header| header.is_a? Symbol}
|
344
|
-
if header_as_symbol
|
345
|
-
raise ArgumentError.new("Net:HTTP does not accept headers as symbols")
|
346
|
-
end
|
347
|
-
end
|
288
|
+
def self.get_uri(net_http, path = nil)
|
289
|
+
protocol = net_http.use_ssl? ? "https" : "http"
|
290
|
+
|
291
|
+
hostname = net_http.address
|
292
|
+
hostname = "[#{hostname}]" if /\A\[.*\]\z/ !~ hostname && /:/ =~ hostname
|
293
|
+
|
294
|
+
"#{protocol}://#{hostname}:#{net_http.port}#{path}"
|
348
295
|
end
|
349
296
|
|
350
297
|
def self.check_right_http_connection
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# This code is entierly copied from VCR (http://github.com/myronmarston/vcr) by courtesy of Myron Marston
|
2
4
|
|
3
5
|
# A Net::HTTP response that has already been read raises an IOError when #read_body
|
@@ -23,7 +25,7 @@ module Net
|
|
23
25
|
return nil if @body.nil?
|
24
26
|
|
25
27
|
dest ||= ::Net::ReadAdapter.new(block)
|
26
|
-
dest << @body
|
28
|
+
dest << @body.dup
|
27
29
|
@body = dest
|
28
30
|
ensure
|
29
31
|
# allow subsequent calls to #read_body to proceed as normal, without our hack...
|
@@ -1,10 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
begin
|
2
4
|
require 'patron'
|
3
5
|
rescue LoadError
|
4
6
|
# patron not found
|
5
7
|
end
|
6
8
|
|
7
|
-
if defined?(::Patron)
|
9
|
+
if defined?(::Patron::Session)
|
8
10
|
module WebMock
|
9
11
|
module HttpLibAdapters
|
10
12
|
class PatronAdapter < ::WebMock::HttpLibAdapter
|
@@ -118,7 +120,7 @@ if defined?(::Patron)
|
|
118
120
|
def self.build_webmock_response(patron_response)
|
119
121
|
webmock_response = WebMock::Response.new
|
120
122
|
reason = patron_response.status_line.
|
121
|
-
scan(%r(\AHTTP/(\d
|
123
|
+
scan(%r(\AHTTP/(\d+(?:\.\d+)?)\s+(\d\d\d)\s*([^\r\n]+)?))[0][2]
|
122
124
|
webmock_response.status = [patron_response.status, reason]
|
123
125
|
webmock_response.body = patron_response.body
|
124
126
|
webmock_response.headers = patron_response.headers
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
begin
|
2
4
|
require 'typhoeus'
|
3
5
|
rescue LoadError
|
@@ -94,7 +96,14 @@ if defined?(Typhoeus)
|
|
94
96
|
status_message: "",
|
95
97
|
body: "",
|
96
98
|
headers: {},
|
97
|
-
return_code: :operation_timedout
|
99
|
+
return_code: :operation_timedout,
|
100
|
+
total_time: 0.0,
|
101
|
+
starttransfer_time: 0.0,
|
102
|
+
appconnect_time: 0.0,
|
103
|
+
pretransfer_time: 0.0,
|
104
|
+
connect_time: 0.0,
|
105
|
+
namelookup_time: 0.0,
|
106
|
+
redirect_time: 0.0
|
98
107
|
)
|
99
108
|
else
|
100
109
|
::Typhoeus::Response.new(
|
@@ -102,7 +111,14 @@ if defined?(Typhoeus)
|
|
102
111
|
status_message: webmock_response.status[1],
|
103
112
|
body: webmock_response.body,
|
104
113
|
headers: webmock_response.headers,
|
105
|
-
effective_url: request_signature.uri
|
114
|
+
effective_url: request_signature.uri,
|
115
|
+
total_time: 0.0,
|
116
|
+
starttransfer_time: 0.0,
|
117
|
+
appconnect_time: 0.0,
|
118
|
+
pretransfer_time: 0.0,
|
119
|
+
connect_time: 0.0,
|
120
|
+
namelookup_time: 0.0,
|
121
|
+
redirect_time: 0.0
|
106
122
|
)
|
107
123
|
end
|
108
124
|
response.mock = :webmock
|
data/lib/webmock/minitest.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module WebMock
|
2
4
|
class RackResponse < Response
|
3
5
|
def initialize(app)
|
@@ -45,7 +47,9 @@ module WebMock
|
|
45
47
|
# Rack-specific variables
|
46
48
|
env['rack.input'] = StringIO.new(body)
|
47
49
|
env['rack.errors'] = $stderr
|
48
|
-
|
50
|
+
if !Rack.const_defined?(:RELEASE) || Rack::RELEASE < "3"
|
51
|
+
env['rack.version'] = Rack::VERSION
|
52
|
+
end
|
49
53
|
env['rack.url_scheme'] = uri.scheme
|
50
54
|
env['rack.run_once'] = true
|
51
55
|
env['rack.session'] = session
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "hashdiff"
|
2
4
|
require "json"
|
3
5
|
|
@@ -12,7 +14,7 @@ module WebMock
|
|
12
14
|
def body_diff
|
13
15
|
return {} unless request_signature_diffable? && request_stub_diffable?
|
14
16
|
|
15
|
-
|
17
|
+
Hashdiff.diff(request_signature_body_hash, request_stub_body_hash)
|
16
18
|
end
|
17
19
|
|
18
20
|
attr_reader :request_signature, :request_stub
|