webmock 3.0.1 → 3.20.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.
Files changed (138) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +558 -2
  3. data/README.md +200 -42
  4. data/lib/webmock/api.rb +14 -0
  5. data/lib/webmock/assertion_failure.rb +2 -0
  6. data/lib/webmock/callback_registry.rb +2 -0
  7. data/lib/webmock/config.rb +2 -0
  8. data/lib/webmock/cucumber.rb +2 -0
  9. data/lib/webmock/deprecation.rb +2 -0
  10. data/lib/webmock/errors.rb +2 -0
  11. data/lib/webmock/http_lib_adapters/async_http_client_adapter.rb +223 -0
  12. data/lib/webmock/http_lib_adapters/curb_adapter.rb +21 -5
  13. data/lib/webmock/http_lib_adapters/em_http_request_adapter.rb +20 -9
  14. data/lib/webmock/http_lib_adapters/excon_adapter.rb +7 -2
  15. data/lib/webmock/http_lib_adapters/http_lib_adapter.rb +2 -0
  16. data/lib/webmock/http_lib_adapters/http_lib_adapter_registry.rb +2 -0
  17. data/lib/webmock/http_lib_adapters/http_rb/client.rb +4 -1
  18. data/lib/webmock/http_lib_adapters/http_rb/request.rb +19 -1
  19. data/lib/webmock/http_lib_adapters/http_rb/response.rb +29 -3
  20. data/lib/webmock/http_lib_adapters/http_rb/streamer.rb +11 -3
  21. data/lib/webmock/http_lib_adapters/http_rb/webmock.rb +9 -3
  22. data/lib/webmock/http_lib_adapters/http_rb_adapter.rb +2 -0
  23. data/lib/webmock/http_lib_adapters/httpclient_adapter.rb +30 -9
  24. data/lib/webmock/http_lib_adapters/manticore_adapter.rb +35 -15
  25. data/lib/webmock/http_lib_adapters/net_http.rb +38 -89
  26. data/lib/webmock/http_lib_adapters/net_http_response.rb +3 -1
  27. data/lib/webmock/http_lib_adapters/patron_adapter.rb +6 -4
  28. data/lib/webmock/http_lib_adapters/typhoeus_hydra_adapter.rb +18 -2
  29. data/lib/webmock/matchers/any_arg_matcher.rb +15 -0
  30. data/lib/webmock/matchers/hash_argument_matcher.rb +23 -0
  31. data/lib/webmock/matchers/hash_excluding_matcher.rb +17 -0
  32. data/lib/webmock/matchers/hash_including_matcher.rb +6 -23
  33. data/lib/webmock/minitest.rb +2 -0
  34. data/lib/webmock/rack_response.rb +3 -1
  35. data/lib/webmock/request_body_diff.rb +3 -1
  36. data/lib/webmock/request_execution_verifier.rb +4 -3
  37. data/lib/webmock/request_pattern.rb +132 -52
  38. data/lib/webmock/request_registry.rb +3 -1
  39. data/lib/webmock/request_signature.rb +5 -3
  40. data/lib/webmock/request_signature_snippet.rb +6 -4
  41. data/lib/webmock/request_stub.rb +34 -0
  42. data/lib/webmock/response.rb +22 -14
  43. data/lib/webmock/responses_sequence.rb +2 -0
  44. data/lib/webmock/rspec/matchers/request_pattern_matcher.rb +2 -0
  45. data/lib/webmock/rspec/matchers/webmock_matcher.rb +2 -0
  46. data/lib/webmock/rspec/matchers.rb +2 -0
  47. data/lib/webmock/rspec.rb +12 -3
  48. data/lib/webmock/stub_registry.rb +28 -11
  49. data/lib/webmock/stub_request_snippet.rb +12 -6
  50. data/lib/webmock/test_unit.rb +3 -3
  51. data/lib/webmock/util/hash_counter.rb +15 -9
  52. data/lib/webmock/util/hash_keys_stringifier.rb +2 -0
  53. data/lib/webmock/util/hash_validator.rb +2 -0
  54. data/lib/webmock/util/headers.rb +39 -11
  55. data/lib/webmock/util/json.rb +3 -2
  56. data/lib/webmock/util/query_mapper.rb +11 -7
  57. data/lib/webmock/util/uri.rb +13 -11
  58. data/lib/webmock/util/values_stringifier.rb +22 -0
  59. data/lib/webmock/util/version_checker.rb +7 -5
  60. data/lib/webmock/version.rb +3 -1
  61. data/lib/webmock/webmock.rb +22 -3
  62. data/lib/webmock.rb +55 -48
  63. metadata +106 -175
  64. data/.gemtest +0 -0
  65. data/.gitignore +0 -34
  66. data/.rspec-tm +0 -2
  67. data/.travis.yml +0 -20
  68. data/Gemfile +0 -9
  69. data/Rakefile +0 -30
  70. data/minitest/test_helper.rb +0 -34
  71. data/minitest/test_webmock.rb +0 -9
  72. data/minitest/webmock_spec.rb +0 -60
  73. data/spec/acceptance/curb/curb_spec.rb +0 -466
  74. data/spec/acceptance/curb/curb_spec_helper.rb +0 -147
  75. data/spec/acceptance/em_http_request/em_http_request_spec.rb +0 -406
  76. data/spec/acceptance/em_http_request/em_http_request_spec_helper.rb +0 -77
  77. data/spec/acceptance/excon/excon_spec.rb +0 -75
  78. data/spec/acceptance/excon/excon_spec_helper.rb +0 -50
  79. data/spec/acceptance/http_rb/http_rb_spec.rb +0 -73
  80. data/spec/acceptance/http_rb/http_rb_spec_helper.rb +0 -51
  81. data/spec/acceptance/httpclient/httpclient_spec.rb +0 -210
  82. data/spec/acceptance/httpclient/httpclient_spec_helper.rb +0 -57
  83. data/spec/acceptance/manticore/manticore_spec.rb +0 -56
  84. data/spec/acceptance/manticore/manticore_spec_helper.rb +0 -35
  85. data/spec/acceptance/net_http/net_http_shared.rb +0 -153
  86. data/spec/acceptance/net_http/net_http_spec.rb +0 -317
  87. data/spec/acceptance/net_http/net_http_spec_helper.rb +0 -64
  88. data/spec/acceptance/net_http/real_net_http_spec.rb +0 -20
  89. data/spec/acceptance/patron/patron_spec.rb +0 -118
  90. data/spec/acceptance/patron/patron_spec_helper.rb +0 -54
  91. data/spec/acceptance/shared/allowing_and_disabling_net_connect.rb +0 -313
  92. data/spec/acceptance/shared/callbacks.rb +0 -147
  93. data/spec/acceptance/shared/complex_cross_concern_behaviors.rb +0 -36
  94. data/spec/acceptance/shared/enabling_and_disabling_webmock.rb +0 -95
  95. data/spec/acceptance/shared/precedence_of_stubs.rb +0 -15
  96. data/spec/acceptance/shared/request_expectations.rb +0 -916
  97. data/spec/acceptance/shared/returning_declared_responses.rb +0 -388
  98. data/spec/acceptance/shared/stubbing_requests.rb +0 -583
  99. data/spec/acceptance/typhoeus/typhoeus_hydra_spec.rb +0 -135
  100. data/spec/acceptance/typhoeus/typhoeus_hydra_spec_helper.rb +0 -60
  101. data/spec/acceptance/webmock_shared.rb +0 -41
  102. data/spec/fixtures/test.txt +0 -1
  103. data/spec/quality_spec.rb +0 -84
  104. data/spec/spec_helper.rb +0 -48
  105. data/spec/support/example_curl_output.txt +0 -22
  106. data/spec/support/failures.rb +0 -9
  107. data/spec/support/my_rack_app.rb +0 -53
  108. data/spec/support/network_connection.rb +0 -19
  109. data/spec/support/webmock_server.rb +0 -69
  110. data/spec/unit/api_spec.rb +0 -75
  111. data/spec/unit/errors_spec.rb +0 -129
  112. data/spec/unit/http_lib_adapters/http_lib_adapter_registry_spec.rb +0 -17
  113. data/spec/unit/http_lib_adapters/http_lib_adapter_spec.rb +0 -12
  114. data/spec/unit/matchers/hash_including_matcher_spec.rb +0 -87
  115. data/spec/unit/rack_response_spec.rb +0 -112
  116. data/spec/unit/request_body_diff_spec.rb +0 -90
  117. data/spec/unit/request_execution_verifier_spec.rb +0 -208
  118. data/spec/unit/request_pattern_spec.rb +0 -590
  119. data/spec/unit/request_registry_spec.rb +0 -95
  120. data/spec/unit/request_signature_snippet_spec.rb +0 -89
  121. data/spec/unit/request_signature_spec.rb +0 -155
  122. data/spec/unit/request_stub_spec.rb +0 -199
  123. data/spec/unit/response_spec.rb +0 -282
  124. data/spec/unit/stub_registry_spec.rb +0 -103
  125. data/spec/unit/stub_request_snippet_spec.rb +0 -95
  126. data/spec/unit/util/hash_counter_spec.rb +0 -39
  127. data/spec/unit/util/hash_keys_stringifier_spec.rb +0 -27
  128. data/spec/unit/util/headers_spec.rb +0 -28
  129. data/spec/unit/util/json_spec.rb +0 -33
  130. data/spec/unit/util/query_mapper_spec.rb +0 -144
  131. data/spec/unit/util/uri_spec.rb +0 -299
  132. data/spec/unit/util/version_checker_spec.rb +0 -65
  133. data/spec/unit/webmock_spec.rb +0 -11
  134. data/test/http_request.rb +0 -24
  135. data/test/shared_test.rb +0 -95
  136. data/test/test_helper.rb +0 -23
  137. data/test/test_webmock.rb +0 -6
  138. 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,19 @@ module WebMock
10
12
  adapter_for :net_http
11
13
 
12
14
  OriginalNetHTTP = Net::HTTP unless const_defined?(:OriginalNetHTTP)
13
- OriginalNetBufferedIO = Net::BufferedIO unless const_defined?(:OriginalNetBufferedIO)
14
15
 
15
16
  def self.enable!
16
- Net.send(:remove_const, :BufferedIO)
17
17
  Net.send(:remove_const, :HTTP)
18
18
  Net.send(:remove_const, :HTTPSession)
19
19
  Net.send(:const_set, :HTTP, @webMockNetHTTP)
20
20
  Net.send(:const_set, :HTTPSession, @webMockNetHTTP)
21
- Net.send(:const_set, :BufferedIO, Net::WebMockNetBufferedIO)
22
21
  end
23
22
 
24
23
  def self.disable!
25
- Net.send(:remove_const, :BufferedIO)
26
24
  Net.send(:remove_const, :HTTP)
27
25
  Net.send(:remove_const, :HTTPSession)
28
26
  Net.send(:const_set, :HTTP, OriginalNetHTTP)
29
27
  Net.send(:const_set, :HTTPSession, OriginalNetHTTP)
30
- Net.send(:const_set, :BufferedIO, OriginalNetBufferedIO)
31
28
 
32
29
  #copy all constants from @webMockNetHTTP to original Net::HTTP
33
30
  #in case any constants were added to @webMockNetHTTP instead of Net::HTTP
@@ -98,13 +95,8 @@ module WebMock
98
95
  after_request.call(response)
99
96
  }
100
97
  if started?
101
- if WebMock::Config.instance.net_http_connect_on_start
102
- super_with_after_request.call
103
- else
104
- start_with_connect_without_finish {
105
- super_with_after_request.call
106
- }
107
- end
98
+ ensure_actual_connection
99
+ super_with_after_request.call
108
100
  else
109
101
  start_with_connect {
110
102
  super_with_after_request.call
@@ -119,32 +111,33 @@ module WebMock
119
111
  raise IOError, 'HTTP session already opened' if @started
120
112
  if block_given?
121
113
  begin
114
+ @socket = Net::HTTP.socket_type.new
122
115
  @started = true
123
116
  return yield(self)
124
117
  ensure
125
118
  do_finish
126
119
  end
127
120
  end
121
+ @socket = Net::HTTP.socket_type.new
128
122
  @started = true
129
123
  self
130
124
  end
131
125
 
132
126
 
133
- def start_with_connect_without_finish # :yield: http
134
- if block_given?
135
- begin
136
- do_start
137
- return yield(self)
138
- end
127
+ def ensure_actual_connection
128
+ if @socket.is_a?(StubSocket)
129
+ @socket&.close
130
+ @socket = nil
131
+ do_start
139
132
  end
140
- do_start
141
- self
142
133
  end
143
134
 
144
135
  alias_method :start_with_connect, :start
145
136
 
146
137
  def start(&block)
147
- if WebMock::Config.instance.net_http_connect_on_start
138
+ uri = Addressable::URI.parse(WebMock::NetHTTPUtility.get_uri(self))
139
+
140
+ if WebMock.net_http_connect_on_start?(uri)
148
141
  super(&block)
149
142
  else
150
143
  start_without_connect(&block)
@@ -154,7 +147,7 @@ module WebMock
154
147
  def build_net_http_response(webmock_response, &block)
155
148
  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
149
  body = webmock_response.body
157
- body = nil if body.to_s == ''
150
+ body = nil if webmock_response.status[0].to_s == '204'
158
151
 
159
152
  response.instance_variable_set(:@body, body)
160
153
  webmock_response.headers.to_a.each do |name, values|
@@ -169,7 +162,7 @@ module WebMock
169
162
  response.extend Net::WebMockHTTPResponse
170
163
 
171
164
  if webmock_response.should_timeout
172
- raise timeout_exception, "execution expired"
165
+ raise Net::OpenTimeout, "execution expired"
173
166
  end
174
167
 
175
168
  webmock_response.raise_error_if_any
@@ -179,16 +172,6 @@ module WebMock
179
172
  response
180
173
  end
181
174
 
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
175
  def build_webmock_response(net_http_response)
193
176
  webmock_response = WebMock::Response.new
194
177
  webmock_response.status = [
@@ -222,66 +205,43 @@ module WebMock
222
205
  end
223
206
  end
224
207
 
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
208
  class StubSocket #:nodoc:
238
209
 
239
- attr_accessor :read_timeout, :continue_timeout
210
+ attr_accessor :read_timeout, :continue_timeout, :write_timeout
240
211
 
241
212
  def initialize(*args)
213
+ @closed = false
242
214
  end
243
215
 
244
216
  def closed?
245
- @closed ||= true
217
+ @closed
246
218
  end
247
219
 
248
220
  def close
221
+ @closed = true
222
+ nil
249
223
  end
250
224
 
251
225
  def readuntil(*args)
252
226
  end
253
227
 
254
- end
255
-
256
- module Net #:nodoc: all
257
-
258
- class WebMockNetBufferedIO < BufferedIO
259
- def initialize(io, read_timeout: 60, continue_timeout: nil, debug_output: nil)
260
- @read_timeout = read_timeout
261
- @rbuf = ''
262
- @debug_output = debug_output
263
-
264
- @io = case io
265
- when Socket, OpenSSL::SSL::SSLSocket, IO
266
- io
267
- when StringIO
268
- PatchedStringIO.new(io.string)
269
- when String
270
- PatchedStringIO.new(io)
271
- end
272
- raise "Unable to create local socket" unless @io
273
- end
228
+ def io
229
+ @io ||= StubIO.new
274
230
  end
275
231
 
232
+ class StubIO
233
+ def setsockopt(*args); end
234
+ def peer_cert; end
235
+ def peeraddr; ["AF_INET", 443, "127.0.0.1", "127.0.0.1"] end
236
+ def ssl_version; "TLSv1.3" end
237
+ def cipher; ["TLS_AES_128_GCM_SHA256", "TLSv1.3", 128, 128] end
238
+ end
276
239
  end
277
240
 
278
-
279
241
  module WebMock
280
242
  module NetHTTPUtility
281
243
 
282
244
  def self.request_signature_from_request(net_http, request, body = nil)
283
- protocol = net_http.use_ssl? ? "https" : "http"
284
-
285
245
  path = request.path
286
246
 
287
247
  if path.respond_to?(:request_uri) #https://github.com/bblimke/webmock/issues/288
@@ -290,11 +250,10 @@ module WebMock
290
250
 
291
251
  path = WebMock::Util::URI.heuristic_parse(path).request_uri if path =~ /^http/
292
252
 
293
- uri = "#{protocol}://#{net_http.address}:#{net_http.port}#{path}"
253
+ uri = get_uri(net_http, path)
294
254
  method = request.method.downcase.to_sym
295
255
 
296
256
  headers = Hash[*request.to_hash.map {|k,v| [k, v]}.inject([]) {|r,x| r + x}]
297
- validate_headers(headers)
298
257
 
299
258
  if request.body_stream
300
259
  body = request.body_stream.read
@@ -310,23 +269,13 @@ module WebMock
310
269
  WebMock::RequestSignature.new(method, uri, body: request.body, headers: headers)
311
270
  end
312
271
 
313
- def self.validate_headers(headers)
314
- # For Ruby versions < 2.3.0, if you make a request with headers that are symbols
315
- # Net::HTTP raises a NoMethodError
316
- #
317
- # WebMock normalizes headers when creating a RequestSignature,
318
- # and will update all headers from symbols to strings.
319
- #
320
- # This could create a false positive in a test suite with WebMock.
321
- #
322
- # So before this point, WebMock raises an ArgumentError if any of the headers are symbols
323
- # instead of the cryptic NoMethodError "undefined method `split' ...` from Net::HTTP
324
- if Gem::Version.new(RUBY_VERSION.dup) < Gem::Version.new('2.3.0')
325
- header_as_symbol = headers.keys.find {|header| header.is_a? Symbol}
326
- if header_as_symbol
327
- raise ArgumentError.new("Net:HTTP does not accept headers as symbols")
328
- end
329
- end
272
+ def self.get_uri(net_http, path = nil)
273
+ protocol = net_http.use_ssl? ? "https" : "http"
274
+
275
+ hostname = net_http.address
276
+ hostname = "[#{hostname}]" if /\A\[.*\]\z/ !~ hostname && /:/ =~ hostname
277
+
278
+ "#{protocol}://#{hostname}:#{net_http.port}#{path}"
330
279
  end
331
280
 
332
281
  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,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  begin
2
4
  require 'patron'
3
5
  rescue LoadError
@@ -69,7 +71,7 @@ if defined?(::Patron)
69
71
  uri = WebMock::Util::URI.heuristic_parse(req.url)
70
72
  uri.path = uri.normalized_path.gsub("[^:]//","/")
71
73
 
72
- if [:put, :post].include?(req.action)
74
+ if [:put, :post, :patch].include?(req.action)
73
75
  if req.file_name
74
76
  if !File.exist?(req.file_name) || !File.readable?(req.file_name)
75
77
  raise ArgumentError.new("Unable to open specified file.")
@@ -106,11 +108,11 @@ if defined?(::Patron)
106
108
  header_data = ([status_line] + header_fields).join("\r\n")
107
109
 
108
110
  ::Patron::Response.new(
109
- "",
111
+ "".dup,
110
112
  webmock_response.status[0],
111
113
  0,
112
114
  header_data,
113
- webmock_response.body,
115
+ webmock_response.body.dup,
114
116
  default_response_charset
115
117
  )
116
118
  end
@@ -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+\.\d+)\s+(\d\d\d)\s*([^\r\n]+)?))[0][2]
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
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module WebMock
4
+ module Matchers
5
+ # this is a based on RSpec::Mocks::ArgumentMatchers::AnyArgMatcher
6
+ class AnyArgMatcher
7
+ def initialize(ignore)
8
+ end
9
+
10
+ def ==(other)
11
+ true
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module WebMock
4
+ module Matchers
5
+ # Base class for Hash matchers
6
+ # https://github.com/rspec/rspec-mocks/blob/master/lib/rspec/mocks/argument_matchers.rb
7
+ class HashArgumentMatcher
8
+ def initialize(expected)
9
+ @expected = Hash[WebMock::Util::HashKeysStringifier.stringify_keys!(expected, deep: true).sort]
10
+ end
11
+
12
+ def ==(_actual, &block)
13
+ @expected.all?(&block)
14
+ rescue NoMethodError
15
+ false
16
+ end
17
+
18
+ def self.from_rspec_matcher(matcher)
19
+ new(matcher.instance_variable_get(:@expected))
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module WebMock
4
+ module Matchers
5
+ # this is a based on RSpec::Mocks::ArgumentMatchers::HashExcludingMatcher
6
+ # https://github.com/rspec/rspec-mocks/blob/master/lib/rspec/mocks/argument_matchers.rb
7
+ class HashExcludingMatcher < HashArgumentMatcher
8
+ def ==(actual)
9
+ super { |key, value| !actual.key?(key) || value != actual[key] }
10
+ end
11
+
12
+ def inspect
13
+ "hash_excluding(#{@expected.inspect})"
14
+ end
15
+ end
16
+ end
17
+ end
@@ -1,14 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module WebMock
2
4
  module Matchers
3
- #this is a based on RSpec::Mocks::ArgumentMatchers::HashIncludingMatcher
4
- #https://github.com/rspec/rspec-mocks/blob/master/lib/rspec/mocks/argument_matchers.rb
5
- class HashIncludingMatcher
6
- def initialize(expected)
7
- @expected = Hash[WebMock::Util::HashKeysStringifier.stringify_keys!(expected, deep: true).sort]
8
- end
9
-
5
+ # this is a based on RSpec::Mocks::ArgumentMatchers::HashIncludingMatcher
6
+ # https://github.com/rspec/rspec-mocks/blob/master/lib/rspec/mocks/argument_matchers.rb
7
+ class HashIncludingMatcher < HashArgumentMatcher
10
8
  def ==(actual)
11
- @expected.all? {|k,v| actual.has_key?(k) && v === actual[k]}
9
+ super { |key, value| actual.key?(key) && value === actual[key] }
12
10
  rescue NoMethodError
13
11
  false
14
12
  end
@@ -16,21 +14,6 @@ module WebMock
16
14
  def inspect
17
15
  "hash_including(#{@expected.inspect})"
18
16
  end
19
-
20
- def self.from_rspec_matcher(matcher)
21
- new(matcher.instance_variable_get(:@expected))
22
- end
23
17
  end
24
-
25
- #this is a based on RSpec::Mocks::ArgumentMatchers::AnyArgMatcher
26
- class AnyArgMatcher
27
- def initialize(ignore)
28
- end
29
-
30
- def ==(other)
31
- true
32
- end
33
- end
34
-
35
18
  end
36
19
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  begin
2
4
  require 'minitest/test'
3
5
  test_class = Minitest::Test
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module WebMock
2
4
  class RackResponse < Response
3
5
  def initialize(app)
@@ -17,7 +19,7 @@ module WebMock
17
19
  end
18
20
 
19
21
  def body_from_rack_response(response)
20
- body = ""
22
+ body = "".dup
21
23
  response.each { |line| body << line }
22
24
  response.close if response.respond_to?(:close)
23
25
  return body
@@ -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
- HashDiff.diff(request_signature_body_hash, request_stub_body_hash)
17
+ Hashdiff.diff(request_signature_body_hash, request_stub_body_hash)
16
18
  end
17
19
 
18
20
  attr_reader :request_signature, :request_stub
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module WebMock
2
4
  class RequestExecutionVerifier
3
5
 
@@ -53,9 +55,8 @@ module WebMock
53
55
 
54
56
  def failure_message_phrase(is_negated=false)
55
57
  negation = is_negated ? "was not" : "was"
56
- text = "The request #{request_pattern} #{negation} expected to execute #{quantity_phrase(is_negated)}but it executed #{times(times_executed)}"
57
- text << self.class.executed_requests_message
58
- text
58
+ "The request #{request_pattern} #{negation} expected to execute #{quantity_phrase(is_negated)}but it executed #{times(times_executed)}" +
59
+ self.class.executed_requests_message
59
60
  end
60
61
 
61
62
  def quantity_phrase(is_negated=false)