webmock 3.36.0 → 4.0.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 +335 -0
- data/README.md +227 -6
- data/lib/webmock/api.rb +4 -0
- data/lib/webmock/callback_registry.rb +14 -7
- data/lib/webmock/errors.rb +1 -1
- data/lib/webmock/http_lib_adapters/async_http_client_adapter.rb +18 -1
- data/lib/webmock/http_lib_adapters/curb_adapter.rb +292 -46
- data/lib/webmock/http_lib_adapters/em_http_request_adapter.rb +11 -3
- data/lib/webmock/http_lib_adapters/excon_adapter.rb +23 -2
- data/lib/webmock/http_lib_adapters/http_rb/response.rb +3 -0
- data/lib/webmock/http_lib_adapters/http_rb/webmock.rb +92 -5
- data/lib/webmock/http_lib_adapters/httpclient_adapter.rb +127 -109
- data/lib/webmock/http_lib_adapters/manticore_adapter.rb +1 -1
- data/lib/webmock/http_lib_adapters/net_http.rb +78 -10
- data/lib/webmock/http_lib_adapters/patron_adapter.rb +32 -13
- data/lib/webmock/http_lib_adapters/typhoeus_hydra_adapter.rb +65 -7
- data/lib/webmock/json_body_hint.rb +119 -12
- data/lib/webmock/request_body_diff.rb +16 -6
- data/lib/webmock/request_execution_verifier.rb +19 -6
- data/lib/webmock/request_pattern.rb +178 -33
- data/lib/webmock/request_registry.rb +75 -5
- data/lib/webmock/request_signature.rb +44 -5
- data/lib/webmock/request_signature_snippet.rb +33 -4
- data/lib/webmock/request_stub.rb +32 -7
- data/lib/webmock/response.rb +42 -3
- data/lib/webmock/stub_registry.rb +7 -6
- data/lib/webmock/stub_request_snippet.rb +9 -3
- data/lib/webmock/trailing_slash_hint.rb +55 -0
- data/lib/webmock/util/hash_counter.rb +27 -8
- data/lib/webmock/util/hash_keys_stringifier.rb +23 -1
- data/lib/webmock/util/headers.rb +17 -0
- data/lib/webmock/util/message_string.rb +28 -0
- data/lib/webmock/util/parsers/json.rb +23 -54
- data/lib/webmock/util/upload_body.rb +63 -0
- data/lib/webmock/util/uri.rb +21 -12
- data/lib/webmock/util/values_stringifier.rb +54 -0
- data/lib/webmock/version.rb +1 -1
- data/lib/webmock/webmock.rb +35 -4
- data/lib/webmock.rb +3 -0
- metadata +10 -7
data/lib/webmock/webmock.rb
CHANGED
|
@@ -43,24 +43,53 @@ module WebMock
|
|
|
43
43
|
end
|
|
44
44
|
end
|
|
45
45
|
|
|
46
|
-
def self.allow_net_connect!(options = {})
|
|
46
|
+
def self.allow_net_connect!(options = {}, &block)
|
|
47
|
+
return restoring_net_connect_settings { allow_net_connect!(options); block.call } if block
|
|
48
|
+
|
|
47
49
|
Config.instance.allow_net_connect = true
|
|
48
50
|
Config.instance.net_http_connect_on_start = options[:net_http_connect_on_start]
|
|
49
51
|
end
|
|
50
52
|
|
|
51
|
-
def self.disable_net_connect!(options = {})
|
|
53
|
+
def self.disable_net_connect!(options = {}, &block)
|
|
54
|
+
return restoring_net_connect_settings { disable_net_connect!(options); block.call } if block
|
|
55
|
+
|
|
52
56
|
Config.instance.allow_net_connect = false
|
|
53
57
|
Config.instance.allow_localhost = options[:allow_localhost]
|
|
54
58
|
Config.instance.allow = options[:allow]
|
|
55
59
|
Config.instance.net_http_connect_on_start = options[:net_http_connect_on_start]
|
|
56
60
|
end
|
|
57
61
|
|
|
62
|
+
NET_CONNECT_SETTINGS = %i[allow_net_connect allow_localhost allow net_http_connect_on_start].freeze
|
|
63
|
+
private_constant :NET_CONNECT_SETTINGS
|
|
64
|
+
|
|
65
|
+
# Runs the block, then puts back the net connect settings from before it,
|
|
66
|
+
# even if the block raises. Settings assigned inside the block are undone.
|
|
67
|
+
# An allow list changed in place stays changed, and blocks overlapping in
|
|
68
|
+
# different threads can restore each other's settings in the wrong order.
|
|
69
|
+
def self.restoring_net_connect_settings
|
|
70
|
+
saved = NET_CONNECT_SETTINGS.map { |name| [name, Config.instance.public_send(name)] }
|
|
71
|
+
begin
|
|
72
|
+
yield
|
|
73
|
+
ensure
|
|
74
|
+
saved.each { |name, value| Config.instance.public_send(:"#{name}=", value) }
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
private_class_method :restoring_net_connect_settings
|
|
78
|
+
|
|
58
79
|
class << self
|
|
59
80
|
alias :enable_net_connect! :allow_net_connect!
|
|
60
81
|
alias :disallow_net_connect! :disable_net_connect!
|
|
61
82
|
end
|
|
62
83
|
|
|
63
84
|
def self.net_connect_allowed?(uri = nil)
|
|
85
|
+
net_connect_allowed_by_settings?(uri)
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
# Whether WebMock's own settings allow a real connection. VCR, for one,
|
|
89
|
+
# redefines net_connect_allowed? to allow every request and decides each
|
|
90
|
+
# one in a global stub, so a connection that no stub sees, such as one
|
|
91
|
+
# taken from an async-http connection pool, is checked with this.
|
|
92
|
+
def self.net_connect_allowed_by_settings?(uri = nil)
|
|
64
93
|
return !!Config.instance.allow_net_connect if uri.nil?
|
|
65
94
|
|
|
66
95
|
if uri.is_a?(String)
|
|
@@ -90,8 +119,10 @@ module WebMock
|
|
|
90
119
|
allowed.match?(uri.to_s) ||
|
|
91
120
|
(uri.port == uri.default_port && allowed.match?(uri.omit(:port).to_s))
|
|
92
121
|
when String
|
|
93
|
-
|
|
94
|
-
|
|
122
|
+
# Host names are case insensitive. casecmp folds ASCII letters only,
|
|
123
|
+
# unlike casecmp?, which would also equate "straße" and "strasse".
|
|
124
|
+
(uri.host && allowed.casecmp(uri.host) == 0) ||
|
|
125
|
+
allowed.casecmp("#{uri.host}:#{uri.port}") == 0 ||
|
|
95
126
|
net_connect_allowed_url?(allowed, uri)
|
|
96
127
|
else
|
|
97
128
|
if allowed.respond_to?(:call)
|
data/lib/webmock.rb
CHANGED
|
@@ -15,6 +15,8 @@ require_relative 'webmock/util/uri'
|
|
|
15
15
|
require_relative 'webmock/util/headers'
|
|
16
16
|
require_relative 'webmock/util/content_type'
|
|
17
17
|
require_relative 'webmock/util/hash_counter'
|
|
18
|
+
require_relative 'webmock/util/upload_body'
|
|
19
|
+
require_relative 'webmock/util/message_string'
|
|
18
20
|
require_relative 'webmock/util/hash_keys_stringifier'
|
|
19
21
|
require_relative 'webmock/util/values_stringifier'
|
|
20
22
|
require_relative 'webmock/util/parsers/json'
|
|
@@ -38,6 +40,7 @@ require_relative 'webmock/stub_request_snippet'
|
|
|
38
40
|
require_relative 'webmock/request_signature_snippet'
|
|
39
41
|
require_relative 'webmock/request_body_diff'
|
|
40
42
|
require_relative 'webmock/json_body_hint'
|
|
43
|
+
require_relative 'webmock/trailing_slash_hint'
|
|
41
44
|
|
|
42
45
|
require_relative 'webmock/assertion_failure'
|
|
43
46
|
require_relative 'webmock/request_execution_verifier'
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: webmock
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version:
|
|
4
|
+
version: 4.0.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Bartosz Blimke
|
|
@@ -29,14 +29,14 @@ dependencies:
|
|
|
29
29
|
requirements:
|
|
30
30
|
- - ">="
|
|
31
31
|
- !ruby/object:Gem::Version
|
|
32
|
-
version: 0.
|
|
32
|
+
version: 0.4.6
|
|
33
33
|
type: :runtime
|
|
34
34
|
prerelease: false
|
|
35
35
|
version_requirements: !ruby/object:Gem::Requirement
|
|
36
36
|
requirements:
|
|
37
37
|
- - ">="
|
|
38
38
|
- !ruby/object:Gem::Version
|
|
39
|
-
version: 0.
|
|
39
|
+
version: 0.4.6
|
|
40
40
|
- !ruby/object:Gem::Dependency
|
|
41
41
|
name: hashdiff
|
|
42
42
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -341,15 +341,18 @@ files:
|
|
|
341
341
|
- lib/webmock/stub_registry.rb
|
|
342
342
|
- lib/webmock/stub_request_snippet.rb
|
|
343
343
|
- lib/webmock/test_unit.rb
|
|
344
|
+
- lib/webmock/trailing_slash_hint.rb
|
|
344
345
|
- lib/webmock/util/content_type.rb
|
|
345
346
|
- lib/webmock/util/hash_counter.rb
|
|
346
347
|
- lib/webmock/util/hash_keys_stringifier.rb
|
|
347
348
|
- lib/webmock/util/hash_validator.rb
|
|
348
349
|
- lib/webmock/util/headers.rb
|
|
350
|
+
- lib/webmock/util/message_string.rb
|
|
349
351
|
- lib/webmock/util/parsers/json.rb
|
|
350
352
|
- lib/webmock/util/parsers/parse_error.rb
|
|
351
353
|
- lib/webmock/util/parsers/xml.rb
|
|
352
354
|
- lib/webmock/util/query_mapper.rb
|
|
355
|
+
- lib/webmock/util/upload_body.rb
|
|
353
356
|
- lib/webmock/util/uri.rb
|
|
354
357
|
- lib/webmock/util/values_stringifier.rb
|
|
355
358
|
- lib/webmock/util/version_checker.rb
|
|
@@ -360,9 +363,9 @@ licenses:
|
|
|
360
363
|
- MIT
|
|
361
364
|
metadata:
|
|
362
365
|
bug_tracker_uri: https://github.com/bblimke/webmock/issues
|
|
363
|
-
changelog_uri: https://github.com/bblimke/webmock/blob/
|
|
364
|
-
documentation_uri: https://www.rubydoc.info/gems/webmock/
|
|
365
|
-
source_code_uri: https://github.com/bblimke/webmock/tree/
|
|
366
|
+
changelog_uri: https://github.com/bblimke/webmock/blob/v4.0.0/CHANGELOG.md
|
|
367
|
+
documentation_uri: https://www.rubydoc.info/gems/webmock/4.0.0
|
|
368
|
+
source_code_uri: https://github.com/bblimke/webmock/tree/v4.0.0
|
|
366
369
|
wiki_uri: https://github.com/bblimke/webmock/wiki
|
|
367
370
|
rdoc_options: []
|
|
368
371
|
require_paths:
|
|
@@ -371,7 +374,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
371
374
|
requirements:
|
|
372
375
|
- - ">="
|
|
373
376
|
- !ruby/object:Gem::Version
|
|
374
|
-
version: '
|
|
377
|
+
version: '3.0'
|
|
375
378
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
376
379
|
requirements:
|
|
377
380
|
- - ">="
|