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.
- checksums.yaml +5 -5
- data/CHANGELOG.md +558 -2
- data/README.md +200 -42
- data/lib/webmock/api.rb +14 -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 +223 -0
- data/lib/webmock/http_lib_adapters/curb_adapter.rb +21 -5
- data/lib/webmock/http_lib_adapters/em_http_request_adapter.rb +20 -9
- data/lib/webmock/http_lib_adapters/excon_adapter.rb +7 -2
- 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 +19 -1
- data/lib/webmock/http_lib_adapters/http_rb/response.rb +29 -3
- data/lib/webmock/http_lib_adapters/http_rb/streamer.rb +11 -3
- data/lib/webmock/http_lib_adapters/http_rb/webmock.rb +9 -3
- data/lib/webmock/http_lib_adapters/http_rb_adapter.rb +2 -0
- data/lib/webmock/http_lib_adapters/httpclient_adapter.rb +30 -9
- data/lib/webmock/http_lib_adapters/manticore_adapter.rb +35 -15
- data/lib/webmock/http_lib_adapters/net_http.rb +38 -89
- data/lib/webmock/http_lib_adapters/net_http_response.rb +3 -1
- data/lib/webmock/http_lib_adapters/patron_adapter.rb +6 -4
- data/lib/webmock/http_lib_adapters/typhoeus_hydra_adapter.rb +18 -2
- data/lib/webmock/matchers/any_arg_matcher.rb +15 -0
- data/lib/webmock/matchers/hash_argument_matcher.rb +23 -0
- data/lib/webmock/matchers/hash_excluding_matcher.rb +17 -0
- data/lib/webmock/matchers/hash_including_matcher.rb +6 -23
- data/lib/webmock/minitest.rb +2 -0
- data/lib/webmock/rack_response.rb +3 -1
- data/lib/webmock/request_body_diff.rb +3 -1
- data/lib/webmock/request_execution_verifier.rb +4 -3
- data/lib/webmock/request_pattern.rb +132 -52
- data/lib/webmock/request_registry.rb +3 -1
- data/lib/webmock/request_signature.rb +5 -3
- data/lib/webmock/request_signature_snippet.rb +6 -4
- 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 +12 -3
- data/lib/webmock/stub_registry.rb +28 -11
- data/lib/webmock/stub_request_snippet.rb +12 -6
- data/lib/webmock/test_unit.rb +3 -3
- data/lib/webmock/util/hash_counter.rb +15 -9
- 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 +39 -11
- data/lib/webmock/util/json.rb +3 -2
- data/lib/webmock/util/query_mapper.rb +11 -7
- data/lib/webmock/util/uri.rb +13 -11
- data/lib/webmock/util/values_stringifier.rb +22 -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 +55 -48
- metadata +106 -175
- data/.gemtest +0 -0
- data/.gitignore +0 -34
- data/.rspec-tm +0 -2
- data/.travis.yml +0 -20
- data/Gemfile +0 -9
- data/Rakefile +0 -30
- 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 -466
- 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 -75
- data/spec/acceptance/excon/excon_spec_helper.rb +0 -50
- data/spec/acceptance/http_rb/http_rb_spec.rb +0 -73
- data/spec/acceptance/http_rb/http_rb_spec_helper.rb +0 -51
- data/spec/acceptance/httpclient/httpclient_spec.rb +0 -210
- 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 -317
- 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 -118
- 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 -916
- data/spec/acceptance/shared/returning_declared_responses.rb +0 -388
- data/spec/acceptance/shared/stubbing_requests.rb +0 -583
- 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 -75
- 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_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 -590
- 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 -95
- 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 -144
- 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 -95
- 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
|
module WebMock
|
|
2
4
|
class StubRequestSnippet
|
|
3
5
|
def initialize(request_stub)
|
|
@@ -10,23 +12,27 @@ module WebMock
|
|
|
10
12
|
|
|
11
13
|
def to_s(with_response = true)
|
|
12
14
|
request_pattern = @request_stub.request_pattern
|
|
13
|
-
string = "stub_request(:#{request_pattern.method_pattern.to_s},"
|
|
15
|
+
string = "stub_request(:#{request_pattern.method_pattern.to_s},".dup
|
|
14
16
|
string << " \"#{request_pattern.uri_pattern.to_s}\")"
|
|
15
17
|
|
|
16
|
-
with = ""
|
|
18
|
+
with = "".dup
|
|
17
19
|
|
|
18
20
|
if (request_pattern.body_pattern)
|
|
19
|
-
with << "body: #{request_pattern.body_pattern.to_s}"
|
|
21
|
+
with << "\n body: #{request_pattern.body_pattern.to_s}"
|
|
20
22
|
end
|
|
21
23
|
|
|
22
24
|
if (request_pattern.headers_pattern)
|
|
23
|
-
with << "
|
|
25
|
+
with << "," unless with.empty?
|
|
24
26
|
|
|
25
|
-
with << "headers: #{request_pattern.headers_pattern.
|
|
27
|
+
with << "\n headers: #{request_pattern.headers_pattern.pp_to_s}"
|
|
26
28
|
end
|
|
27
29
|
string << ".\n with(#{with})" unless with.empty?
|
|
28
30
|
if with_response
|
|
29
|
-
|
|
31
|
+
if request_pattern.headers_pattern && request_pattern.headers_pattern.matches?({ 'Accept' => "application/json" })
|
|
32
|
+
string << ".\n to_return(status: 200, body: \"{}\", headers: {})"
|
|
33
|
+
else
|
|
34
|
+
string << ".\n to_return(status: 200, body: \"\", headers: {})"
|
|
35
|
+
end
|
|
30
36
|
end
|
|
31
37
|
string
|
|
32
38
|
end
|
data/lib/webmock/test_unit.rb
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'test/unit'
|
|
2
4
|
require 'webmock'
|
|
3
5
|
|
|
@@ -8,12 +10,10 @@ module Test
|
|
|
8
10
|
class TestCase
|
|
9
11
|
include WebMock::API
|
|
10
12
|
|
|
11
|
-
|
|
13
|
+
teardown
|
|
12
14
|
def teardown_with_webmock
|
|
13
|
-
teardown_without_webmock
|
|
14
15
|
WebMock.reset!
|
|
15
16
|
end
|
|
16
|
-
alias_method :teardown, :teardown_with_webmock
|
|
17
17
|
|
|
18
18
|
end
|
|
19
19
|
end
|
|
@@ -1,37 +1,43 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'thread'
|
|
2
4
|
|
|
3
5
|
module WebMock
|
|
4
6
|
module Util
|
|
5
|
-
class
|
|
7
|
+
class HashCounter
|
|
6
8
|
attr_accessor :hash
|
|
9
|
+
|
|
7
10
|
def initialize
|
|
8
|
-
self.hash =
|
|
11
|
+
self.hash = Hash.new(0)
|
|
9
12
|
@order = {}
|
|
10
13
|
@max = 0
|
|
11
14
|
@lock = ::Mutex.new
|
|
12
15
|
end
|
|
13
|
-
|
|
16
|
+
|
|
17
|
+
def put(key, num=1)
|
|
14
18
|
@lock.synchronize do
|
|
15
|
-
hash[key]
|
|
16
|
-
@order[key] = @max
|
|
19
|
+
hash[key] += num
|
|
20
|
+
@order[key] = @max += 1
|
|
17
21
|
end
|
|
18
22
|
end
|
|
19
|
-
|
|
23
|
+
|
|
24
|
+
def get(key)
|
|
20
25
|
@lock.synchronize do
|
|
21
|
-
hash[key]
|
|
26
|
+
hash[key]
|
|
22
27
|
end
|
|
23
28
|
end
|
|
24
29
|
|
|
25
30
|
def select(&block)
|
|
26
31
|
return unless block_given?
|
|
32
|
+
|
|
27
33
|
@lock.synchronize do
|
|
28
34
|
hash.select(&block)
|
|
29
35
|
end
|
|
30
36
|
end
|
|
31
37
|
|
|
32
38
|
def each(&block)
|
|
33
|
-
@order.to_a.
|
|
34
|
-
|
|
39
|
+
@order.to_a.sort_by { |a| a[1] }.each do |a|
|
|
40
|
+
yield(a[0], hash[a[0]])
|
|
35
41
|
end
|
|
36
42
|
end
|
|
37
43
|
end
|
data/lib/webmock/util/headers.rb
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
module WebMock
|
|
4
4
|
|
|
@@ -6,23 +6,26 @@ module WebMock
|
|
|
6
6
|
|
|
7
7
|
class Headers
|
|
8
8
|
|
|
9
|
+
STANDARD_HEADER_DELIMITER = '-'
|
|
10
|
+
NONSTANDARD_HEADER_DELIMITER = '_'
|
|
11
|
+
JOIN = ', '
|
|
12
|
+
|
|
9
13
|
def self.normalize_headers(headers)
|
|
10
14
|
return nil unless headers
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
15
|
+
|
|
16
|
+
headers.each_with_object({}) do |(name, value), new_headers|
|
|
17
|
+
new_headers[normalize_name(name)] =
|
|
18
|
+
case value
|
|
14
19
|
when Regexp then value
|
|
15
|
-
when Array then (value.size == 1) ? value.first : value.map
|
|
20
|
+
when Array then (value.size == 1) ? value.first.to_s : value.map(&:to_s).sort
|
|
16
21
|
else value.to_s
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
20
|
-
Hash[*array.inject([]) {|r,x| r + x}]
|
|
22
|
+
end
|
|
23
|
+
end
|
|
21
24
|
end
|
|
22
25
|
|
|
23
26
|
def self.sorted_headers_string(headers)
|
|
24
27
|
headers = WebMock::Util::Headers.normalize_headers(headers)
|
|
25
|
-
str = '{'
|
|
28
|
+
str = '{'.dup
|
|
26
29
|
str << headers.map do |k,v|
|
|
27
30
|
v = case v
|
|
28
31
|
when Regexp then v.inspect
|
|
@@ -34,12 +37,37 @@ module WebMock
|
|
|
34
37
|
str << '}'
|
|
35
38
|
end
|
|
36
39
|
|
|
40
|
+
def self.pp_headers_string(headers)
|
|
41
|
+
headers = WebMock::Util::Headers.normalize_headers(headers)
|
|
42
|
+
seperator = "\n\t "
|
|
43
|
+
str = "{#{seperator} ".dup
|
|
44
|
+
str << headers.map do |k,v|
|
|
45
|
+
v = case v
|
|
46
|
+
when Regexp then v.inspect
|
|
47
|
+
when Array then "["+v.map{|w| "'#{w.to_s}'"}.join(", ")+"]"
|
|
48
|
+
else "'#{v.to_s}'"
|
|
49
|
+
end
|
|
50
|
+
"'#{k}'=>#{v}"
|
|
51
|
+
end.sort.join(",#{seperator} ")
|
|
52
|
+
str << "\n }"
|
|
53
|
+
end
|
|
54
|
+
|
|
37
55
|
def self.decode_userinfo_from_header(header)
|
|
38
56
|
header.sub(/^Basic /, "").unpack("m").first
|
|
39
57
|
end
|
|
40
58
|
|
|
41
59
|
def self.basic_auth_header(*credentials)
|
|
42
|
-
|
|
60
|
+
strict_base64_encoded = [credentials.join(':')].pack("m0")
|
|
61
|
+
"Basic #{strict_base64_encoded.chomp}"
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def self.normalize_name(name)
|
|
65
|
+
name
|
|
66
|
+
.to_s
|
|
67
|
+
.tr(NONSTANDARD_HEADER_DELIMITER, STANDARD_HEADER_DELIMITER)
|
|
68
|
+
.split(STANDARD_HEADER_DELIMITER)
|
|
69
|
+
.map!(&:capitalize)
|
|
70
|
+
.join(STANDARD_HEADER_DELIMITER)
|
|
43
71
|
end
|
|
44
72
|
|
|
45
73
|
end
|
data/lib/webmock/util/json.rb
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
# This is a copy of https://github.com/jnunemaker/crack/blob/master/lib/crack/json.rb
|
|
2
4
|
# with date parsing removed
|
|
3
5
|
# Copyright (c) 2004-2008 David Heinemeier Hansson
|
|
@@ -24,13 +26,12 @@ module WebMock
|
|
|
24
26
|
|
|
25
27
|
# Ensure that ":" and "," are always followed by a space
|
|
26
28
|
def self.convert_json_to_yaml(json) #:nodoc:
|
|
27
|
-
scanner, quoting, marks,
|
|
29
|
+
scanner, quoting, marks, times = StringScanner.new(json), false, [], []
|
|
28
30
|
while scanner.scan_until(/(\\['"]|['":,\\]|\\.)/)
|
|
29
31
|
case char = scanner[1]
|
|
30
32
|
when '"', "'"
|
|
31
33
|
if !quoting
|
|
32
34
|
quoting = char
|
|
33
|
-
pos = scanner.pos
|
|
34
35
|
elsif quoting == char
|
|
35
36
|
quoting = false
|
|
36
37
|
end
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module WebMock::Util
|
|
2
4
|
class QueryMapper
|
|
3
5
|
class << self
|
|
@@ -81,7 +83,7 @@ module WebMock::Util
|
|
|
81
83
|
value = if value.nil?
|
|
82
84
|
nil
|
|
83
85
|
else
|
|
84
|
-
::Addressable::URI.unencode_component(value.
|
|
86
|
+
::Addressable::URI.unencode_component(value.tr('+', ' '))
|
|
85
87
|
end
|
|
86
88
|
key = Addressable::URI.unencode_component(key)
|
|
87
89
|
key = key.dup.force_encoding(Encoding::ASCII_8BIT) if key.respond_to?(:force_encoding)
|
|
@@ -122,7 +124,7 @@ module WebMock::Util
|
|
|
122
124
|
|
|
123
125
|
def fill_accumulator_for_subscript(accumulator, key, value)
|
|
124
126
|
current_node = accumulator
|
|
125
|
-
subkeys = key.split(/(?=\[\
|
|
127
|
+
subkeys = key.split(/(?=\[[^\[\]]+)/)
|
|
126
128
|
subkeys[0..-2].each do |subkey|
|
|
127
129
|
node = subkey =~ /\[\]\z/ ? [] : {}
|
|
128
130
|
subkey = subkey.gsub(/[\[\]]/, '')
|
|
@@ -161,7 +163,7 @@ module WebMock::Util
|
|
|
161
163
|
else
|
|
162
164
|
if array_value
|
|
163
165
|
current_node[last_key] ||= []
|
|
164
|
-
current_node[last_key] << value
|
|
166
|
+
current_node[last_key] << value unless value.nil?
|
|
165
167
|
else
|
|
166
168
|
current_node[last_key] = value
|
|
167
169
|
end
|
|
@@ -186,7 +188,9 @@ module WebMock::Util
|
|
|
186
188
|
new_query_values = new_query_values.to_hash
|
|
187
189
|
new_query_values = new_query_values.inject([]) do |object, (key, value)|
|
|
188
190
|
key = key.to_s if key.is_a?(::Symbol) || key.nil?
|
|
189
|
-
if value.is_a?(Array)
|
|
191
|
+
if value.is_a?(Array) && value.empty?
|
|
192
|
+
object << [key.to_s + '[]']
|
|
193
|
+
elsif value.is_a?(Array)
|
|
190
194
|
value.each { |v| object << [key.to_s + '[]', v] }
|
|
191
195
|
elsif value.is_a?(Hash)
|
|
192
196
|
value.each { |k, v| object << ["#{key.to_s}[#{k}]", v]}
|
|
@@ -204,7 +208,7 @@ module WebMock::Util
|
|
|
204
208
|
end
|
|
205
209
|
end
|
|
206
210
|
|
|
207
|
-
buffer = ''
|
|
211
|
+
buffer = ''.dup
|
|
208
212
|
new_query_values.each do |parent, value|
|
|
209
213
|
encoded_parent = ::Addressable::URI.encode_component(
|
|
210
214
|
parent.dup, ::Addressable::URI::CharacterClasses::UNRESERVED
|
|
@@ -251,14 +255,14 @@ module WebMock::Util
|
|
|
251
255
|
]
|
|
252
256
|
end
|
|
253
257
|
value.sort!
|
|
254
|
-
buffer = ''
|
|
258
|
+
buffer = ''.dup
|
|
255
259
|
value.each do |key, val|
|
|
256
260
|
new_parent = options[:notation] != :flat_array ? "#{parent}[#{key}]" : parent
|
|
257
261
|
buffer << "#{to_query(new_parent, val, options)}&"
|
|
258
262
|
end
|
|
259
263
|
buffer.chop
|
|
260
264
|
when ::Array
|
|
261
|
-
buffer = ''
|
|
265
|
+
buffer = ''.dup
|
|
262
266
|
value.each_with_index do |val, i|
|
|
263
267
|
new_parent = options[:notation] != :flat_array ? "#{parent}[#{i}]" : parent
|
|
264
268
|
buffer << "#{to_query(new_parent, val, options)}&"
|
data/lib/webmock/util/uri.rb
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module WebMock
|
|
2
4
|
|
|
3
5
|
module Util
|
|
@@ -33,7 +35,7 @@ module WebMock
|
|
|
33
35
|
NORMALIZED_URIS[uri].dup
|
|
34
36
|
end
|
|
35
37
|
|
|
36
|
-
def self.variations_of_uri_as_strings(uri_object)
|
|
38
|
+
def self.variations_of_uri_as_strings(uri_object, only_with_scheme: false)
|
|
37
39
|
normalized_uri = normalize_uri(uri_object.dup).freeze
|
|
38
40
|
uris = [ normalized_uri ]
|
|
39
41
|
|
|
@@ -41,13 +43,13 @@ module WebMock
|
|
|
41
43
|
uris = uris_with_trailing_slash_and_without(uris)
|
|
42
44
|
end
|
|
43
45
|
|
|
44
|
-
uris = uris_encoded_and_unencoded(uris)
|
|
45
|
-
|
|
46
46
|
if normalized_uri.port == Addressable::URI.port_mapping[normalized_uri.scheme]
|
|
47
47
|
uris = uris_with_inferred_port_and_without(uris)
|
|
48
48
|
end
|
|
49
49
|
|
|
50
|
-
|
|
50
|
+
uris = uris_encoded_and_unencoded(uris)
|
|
51
|
+
|
|
52
|
+
if normalized_uri.scheme == "http" && !only_with_scheme
|
|
51
53
|
uris = uris_with_scheme_and_without(uris)
|
|
52
54
|
end
|
|
53
55
|
|
|
@@ -68,7 +70,7 @@ module WebMock
|
|
|
68
70
|
|
|
69
71
|
def self.is_uri_localhost?(uri)
|
|
70
72
|
uri.is_a?(Addressable::URI) &&
|
|
71
|
-
%w(localhost 127.0.0.1 0.0.0.0).include?(uri.host)
|
|
73
|
+
%w(localhost 127.0.0.1 0.0.0.0 [::1]).include?(uri.host)
|
|
72
74
|
end
|
|
73
75
|
|
|
74
76
|
private
|
|
@@ -80,27 +82,27 @@ module WebMock
|
|
|
80
82
|
|
|
81
83
|
def self.uris_with_inferred_port_and_without(uris)
|
|
82
84
|
uris.map { |uri|
|
|
83
|
-
|
|
84
|
-
[ uri, uri.gsub(%r{(:80)|(:443)}, "").freeze ]
|
|
85
|
+
[ uri, uri.omit(:port)]
|
|
85
86
|
}.flatten
|
|
86
87
|
end
|
|
87
88
|
|
|
88
89
|
def self.uris_encoded_and_unencoded(uris)
|
|
89
90
|
uris.map do |uri|
|
|
90
|
-
[
|
|
91
|
+
[
|
|
92
|
+
uri.to_s.force_encoding(Encoding::ASCII_8BIT),
|
|
93
|
+
Addressable::URI.unencode(uri, String).force_encoding(Encoding::ASCII_8BIT).freeze
|
|
94
|
+
]
|
|
91
95
|
end.flatten
|
|
92
96
|
end
|
|
93
97
|
|
|
94
98
|
def self.uris_with_scheme_and_without(uris)
|
|
95
99
|
uris.map { |uri|
|
|
96
|
-
uri = uri.dup.force_encoding(Encoding::ASCII_8BIT) if uri.respond_to?(:force_encoding)
|
|
97
100
|
[ uri, uri.gsub(%r{^https?://},"").freeze ]
|
|
98
101
|
}.flatten
|
|
99
102
|
end
|
|
100
103
|
|
|
101
104
|
def self.uris_with_trailing_slash_and_without(uris)
|
|
102
|
-
uris
|
|
103
|
-
uri = uri.dup.force_encoding(Encoding::ASCII_8BIT) if uri.respond_to?(:force_encoding)
|
|
105
|
+
uris.map { |uri|
|
|
104
106
|
[ uri, uri.omit(:path).freeze ]
|
|
105
107
|
}.flatten
|
|
106
108
|
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
class WebMock::Util::ValuesStringifier
|
|
4
|
+
def self.stringify_values(value)
|
|
5
|
+
case value
|
|
6
|
+
when String, Numeric, TrueClass, FalseClass
|
|
7
|
+
value.to_s
|
|
8
|
+
when Hash
|
|
9
|
+
Hash[
|
|
10
|
+
value.map do |k, v|
|
|
11
|
+
[k, stringify_values(v)]
|
|
12
|
+
end
|
|
13
|
+
]
|
|
14
|
+
when Array
|
|
15
|
+
value.map do |v|
|
|
16
|
+
stringify_values(v)
|
|
17
|
+
end
|
|
18
|
+
else
|
|
19
|
+
value
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
# This code was created based on https://github.com/myronmarston/vcr/blob/master/lib/vcr/util/version_checker.rb
|
|
2
4
|
# Thanks to @myronmarston
|
|
3
5
|
|
|
@@ -84,12 +86,12 @@ module WebMock
|
|
|
84
86
|
def compare_version
|
|
85
87
|
case
|
|
86
88
|
when @major < @min_major then :too_low
|
|
89
|
+
when @major == @min_major && @minor < @min_minor then :too_low
|
|
90
|
+
when @major == @min_major && @minor == @min_minor && @patch < @min_patch then :too_low
|
|
87
91
|
when @max_major && @major > @max_major then :too_high
|
|
88
|
-
when @major > @
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
when @minor > @min_minor then :ok
|
|
92
|
-
when @patch < @min_patch then :too_low
|
|
92
|
+
when @max_major && @major == @max_major && @max_minor && @minor > @max_minor then :too_high
|
|
93
|
+
|
|
94
|
+
else :ok
|
|
93
95
|
end
|
|
94
96
|
end
|
|
95
97
|
|
data/lib/webmock/version.rb
CHANGED
data/lib/webmock/webmock.rb
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module WebMock
|
|
2
4
|
|
|
3
5
|
def self.included(clazz)
|
|
@@ -53,16 +55,33 @@ module WebMock
|
|
|
53
55
|
Config.instance.net_http_connect_on_start = options[:net_http_connect_on_start]
|
|
54
56
|
end
|
|
55
57
|
|
|
58
|
+
class << self
|
|
59
|
+
alias :enable_net_connect! :allow_net_connect!
|
|
60
|
+
alias :disallow_net_connect! :disable_net_connect!
|
|
61
|
+
end
|
|
62
|
+
|
|
56
63
|
def self.net_connect_allowed?(uri = nil)
|
|
64
|
+
return !!Config.instance.allow_net_connect if uri.nil?
|
|
65
|
+
|
|
57
66
|
if uri.is_a?(String)
|
|
58
67
|
uri = WebMock::Util::URI.normalize_uri(uri)
|
|
59
68
|
end
|
|
60
69
|
|
|
61
|
-
Config.instance.allow_net_connect ||
|
|
70
|
+
!!Config.instance.allow_net_connect ||
|
|
62
71
|
( Config.instance.allow_localhost && WebMock::Util::URI.is_uri_localhost?(uri) ||
|
|
63
72
|
Config.instance.allow && net_connect_explicit_allowed?(Config.instance.allow, uri) )
|
|
64
73
|
end
|
|
65
74
|
|
|
75
|
+
def self.net_http_connect_on_start?(uri)
|
|
76
|
+
allowed = Config.instance.net_http_connect_on_start || false
|
|
77
|
+
|
|
78
|
+
if [true, false].include?(allowed)
|
|
79
|
+
allowed
|
|
80
|
+
else
|
|
81
|
+
net_connect_explicit_allowed?(allowed, uri)
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
|
|
66
85
|
def self.net_connect_explicit_allowed?(allowed, uri=nil)
|
|
67
86
|
case allowed
|
|
68
87
|
when Array
|
|
@@ -133,8 +152,8 @@ module WebMock
|
|
|
133
152
|
puts WebMock::RequestExecutionVerifier.executed_requests_message
|
|
134
153
|
end
|
|
135
154
|
|
|
136
|
-
def self.globally_stub_request(&block)
|
|
137
|
-
WebMock::StubRegistry.instance.register_global_stub(&block)
|
|
155
|
+
def self.globally_stub_request(order = :before_local_stubs, &block)
|
|
156
|
+
WebMock::StubRegistry.instance.register_global_stub(order, &block)
|
|
138
157
|
end
|
|
139
158
|
|
|
140
159
|
%w(
|
data/lib/webmock.rb
CHANGED
|
@@ -1,54 +1,61 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'singleton'
|
|
2
4
|
|
|
3
5
|
require 'addressable/uri'
|
|
4
6
|
require 'addressable/template'
|
|
5
7
|
require 'crack/xml'
|
|
6
8
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
9
|
+
require_relative 'webmock/deprecation'
|
|
10
|
+
require_relative 'webmock/version'
|
|
11
|
+
|
|
12
|
+
require_relative 'webmock/errors'
|
|
13
|
+
|
|
14
|
+
require_relative 'webmock/util/query_mapper'
|
|
15
|
+
require_relative 'webmock/util/uri'
|
|
16
|
+
require_relative 'webmock/util/headers'
|
|
17
|
+
require_relative 'webmock/util/hash_counter'
|
|
18
|
+
require_relative 'webmock/util/hash_keys_stringifier'
|
|
19
|
+
require_relative 'webmock/util/values_stringifier'
|
|
20
|
+
require_relative 'webmock/util/json'
|
|
21
|
+
require_relative 'webmock/util/version_checker'
|
|
22
|
+
require_relative 'webmock/util/hash_validator'
|
|
23
|
+
|
|
24
|
+
require_relative 'webmock/matchers/hash_argument_matcher'
|
|
25
|
+
require_relative 'webmock/matchers/hash_excluding_matcher'
|
|
26
|
+
require_relative 'webmock/matchers/hash_including_matcher'
|
|
27
|
+
require_relative 'webmock/matchers/any_arg_matcher'
|
|
28
|
+
|
|
29
|
+
require_relative 'webmock/request_pattern'
|
|
30
|
+
require_relative 'webmock/request_signature'
|
|
31
|
+
require_relative 'webmock/responses_sequence'
|
|
32
|
+
require_relative 'webmock/request_stub'
|
|
33
|
+
require_relative 'webmock/response'
|
|
34
|
+
require_relative 'webmock/rack_response'
|
|
35
|
+
|
|
36
|
+
require_relative 'webmock/stub_request_snippet'
|
|
37
|
+
require_relative 'webmock/request_signature_snippet'
|
|
38
|
+
require_relative 'webmock/request_body_diff'
|
|
39
|
+
|
|
40
|
+
require_relative 'webmock/assertion_failure'
|
|
41
|
+
require_relative 'webmock/request_execution_verifier'
|
|
42
|
+
require_relative 'webmock/config'
|
|
43
|
+
require_relative 'webmock/callback_registry'
|
|
44
|
+
require_relative 'webmock/request_registry'
|
|
45
|
+
require_relative 'webmock/stub_registry'
|
|
46
|
+
require_relative 'webmock/api'
|
|
47
|
+
|
|
48
|
+
require_relative 'webmock/http_lib_adapters/http_lib_adapter_registry'
|
|
49
|
+
require_relative 'webmock/http_lib_adapters/http_lib_adapter'
|
|
50
|
+
require_relative 'webmock/http_lib_adapters/net_http'
|
|
51
|
+
require_relative 'webmock/http_lib_adapters/http_rb_adapter'
|
|
52
|
+
require_relative 'webmock/http_lib_adapters/httpclient_adapter'
|
|
53
|
+
require_relative 'webmock/http_lib_adapters/patron_adapter'
|
|
54
|
+
require_relative 'webmock/http_lib_adapters/curb_adapter'
|
|
55
|
+
require_relative 'webmock/http_lib_adapters/em_http_request_adapter'
|
|
56
|
+
require_relative 'webmock/http_lib_adapters/typhoeus_hydra_adapter'
|
|
57
|
+
require_relative 'webmock/http_lib_adapters/excon_adapter'
|
|
58
|
+
require_relative 'webmock/http_lib_adapters/manticore_adapter'
|
|
59
|
+
require_relative 'webmock/http_lib_adapters/async_http_client_adapter'
|
|
60
|
+
|
|
61
|
+
require_relative 'webmock/webmock'
|