webmock 3.18.1 → 3.19.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 +34 -0
- data/README.md +34 -15
- 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 +2 -0
- data/lib/webmock/http_lib_adapters/curb_adapter.rb +2 -0
- data/lib/webmock/http_lib_adapters/em_http_request_adapter.rb +14 -6
- data/lib/webmock/http_lib_adapters/excon_adapter.rb +2 -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 +2 -0
- data/lib/webmock/http_lib_adapters/http_rb/request.rb +3 -1
- data/lib/webmock/http_lib_adapters/http_rb/response.rb +2 -0
- data/lib/webmock/http_lib_adapters/http_rb/streamer.rb +2 -0
- data/lib/webmock/http_lib_adapters/http_rb/webmock.rb +2 -0
- data/lib/webmock/http_lib_adapters/http_rb_adapter.rb +2 -0
- data/lib/webmock/http_lib_adapters/httpclient_adapter.rb +2 -0
- data/lib/webmock/http_lib_adapters/manticore_adapter.rb +2 -0
- data/lib/webmock/http_lib_adapters/net_http.rb +2 -0
- data/lib/webmock/http_lib_adapters/net_http_response.rb +2 -0
- data/lib/webmock/http_lib_adapters/patron_adapter.rb +2 -0
- data/lib/webmock/http_lib_adapters/typhoeus_hydra_adapter.rb +2 -0
- 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 +2 -0
- data/lib/webmock/request_body_diff.rb +2 -0
- data/lib/webmock/request_execution_verifier.rb +2 -0
- data/lib/webmock/request_pattern.rb +3 -1
- data/lib/webmock/request_registry.rb +2 -0
- data/lib/webmock/request_signature.rb +2 -0
- data/lib/webmock/request_signature_snippet.rb +2 -0
- data/lib/webmock/request_stub.rb +7 -1
- data/lib/webmock/response.rb +2 -0
- 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 +2 -0
- data/lib/webmock/stub_registry.rb +2 -0
- data/lib/webmock/stub_request_snippet.rb +2 -0
- data/lib/webmock/test_unit.rb +2 -0
- 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 +22 -8
- data/lib/webmock/util/json.rb +2 -0
- data/lib/webmock/util/query_mapper.rb +2 -0
- data/lib/webmock/util/uri.rb +3 -1
- 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 +2 -0
- data/lib/webmock.rb +2 -0
- metadata +36 -168
- data/.gemtest +0 -0
- data/.github/workflows/CI.yml +0 -38
- data/.gitignore +0 -34
- data/.rspec-tm +0 -2
- data/Gemfile +0 -9
- data/Rakefile +0 -38
- data/minitest/test_helper.rb +0 -34
- data/minitest/test_webmock.rb +0 -9
- data/minitest/webmock_spec.rb +0 -60
- data/spec/acceptance/async_http_client/async_http_client_spec.rb +0 -375
- data/spec/acceptance/async_http_client/async_http_client_spec_helper.rb +0 -73
- data/spec/acceptance/curb/curb_spec.rb +0 -510
- data/spec/acceptance/curb/curb_spec_helper.rb +0 -147
- data/spec/acceptance/em_http_request/em_http_request_spec.rb +0 -462
- 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 -52
- data/spec/acceptance/http_rb/http_rb_spec.rb +0 -93
- 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 -107
- data/spec/acceptance/manticore/manticore_spec_helper.rb +0 -35
- data/spec/acceptance/net_http/net_http_shared.rb +0 -190
- data/spec/acceptance/net_http/net_http_spec.rb +0 -395
- 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 -123
- 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 -148
- 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 -930
- data/spec/acceptance/shared/returning_declared_responses.rb +0 -409
- data/spec/acceptance/shared/stubbing_requests.rb +0 -678
- 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 -70
- 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 -748
- 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 -175
- data/spec/unit/request_stub_spec.rb +0 -234
- data/spec/unit/response_spec.rb +0 -314
- 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 -157
- data/spec/unit/util/uri_spec.rb +0 -371
- data/spec/unit/util/version_checker_spec.rb +0 -65
- data/spec/unit/webmock_spec.rb +0 -114
- 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 -12
- data/webmock.gemspec +0 -54
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 57ade97b45c0a5c72d60b74f83afd38ff397fd878c43e02de7e7d148e1d1ace8
|
|
4
|
+
data.tar.gz: b8c6e112eb3eec3d0f5bcaff76c6c8209d84eeb71f625bedfebc63b1fe6756f2
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: de9230ccdbfaa25cc814d9ffa1091edf85d279e1982728e64d7c721355897d8eb2a0bd3ad94eff36917f0d696287edc8218d3882255bcc6234393f90c084c28b
|
|
7
|
+
data.tar.gz: 58d85aeb70b455fc02322c0f868e4937cc4d93b9db0c0a3dd9fede8b08bebf8adf2a7d9a0aebb3e1e40a52b079d8841530075ecef203ff16a937a20954b50861
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,39 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
# 3.19.0
|
|
4
|
+
|
|
5
|
+
* Do not alter real (non-stubbed) request headers when handling em-http-request requests.
|
|
6
|
+
|
|
7
|
+
Thanks to [Yoann Lecuyer](https://github.com/ylecuyer)
|
|
8
|
+
|
|
9
|
+
* Fix matching stubs with HashExcludingMatcher
|
|
10
|
+
|
|
11
|
+
Thanks to [Lucas Arnaud](https://github.com/lucasarnaud)
|
|
12
|
+
|
|
13
|
+
* Remove development and test files from the gem package
|
|
14
|
+
|
|
15
|
+
Thanks to [Orien Madgwick](https://github.com/orien)
|
|
16
|
+
|
|
17
|
+
* Fix supported http client gem version checks.
|
|
18
|
+
|
|
19
|
+
Thanks to [Marc Rohloff](https://github.com/marcrohloff) and [Roman Stražanec](https://github.com/romanstrazanec)
|
|
20
|
+
|
|
21
|
+
* Non-string body passed to #to_return_json is now converted to JSON string.
|
|
22
|
+
|
|
23
|
+
Thanks to [inkstak](https://github.com/inkstak)
|
|
24
|
+
|
|
25
|
+
* `[::1]` is recognised as localhost e.g when passing `allow_localhost` option to `disable_net_connect!`
|
|
26
|
+
|
|
27
|
+
Thanks to [Yuki Inoue](https://github.com/Yuki-Inoue)
|
|
28
|
+
|
|
29
|
+
* Optimized `normalize_headers` for performance
|
|
30
|
+
|
|
31
|
+
Thanks to [Brandon Weaver](https://github.com/baweaver)
|
|
32
|
+
|
|
33
|
+
* Added Frozen string literal to files to optimise memory usage
|
|
34
|
+
|
|
35
|
+
Thanks to [Josh Nichols](https://github.com/technicalpickles)
|
|
36
|
+
|
|
3
37
|
# 3.18.1
|
|
4
38
|
|
|
5
39
|
* Reverted simplified connection handing in Net::HTTP adapter due to https://github.com/bblimke/webmock/issues/999
|
data/README.md
CHANGED
|
@@ -4,8 +4,6 @@ WebMock
|
|
|
4
4
|
[](https://github.com/bblimke/webmock/actions)
|
|
5
5
|
[](https://codeclimate.com/github/bblimke/webmock)
|
|
6
6
|
[](https://github.com/markets/awesome-ruby)
|
|
7
|
-
[](http://inch-ci.org/github/bblimke/webmock)
|
|
8
|
-
[](https://dependabot.com/compatibility-score.html?dependency-name=webmock&package-manager=bundler&version-scheme=semver)
|
|
9
7
|
|
|
10
8
|
Library for stubbing and setting expectations on HTTP requests in Ruby.
|
|
11
9
|
|
|
@@ -40,32 +38,34 @@ Supported HTTP libraries
|
|
|
40
38
|
|
|
41
39
|
Supported Ruby Interpreters
|
|
42
40
|
---------------------------
|
|
43
|
-
|
|
44
|
-
* MRI 2.5
|
|
45
41
|
* MRI 2.6
|
|
46
42
|
* MRI 2.7
|
|
43
|
+
* MRI 3.0
|
|
44
|
+
* MRI 3.1
|
|
45
|
+
* MRI 3.2
|
|
47
46
|
* JRuby
|
|
48
|
-
* Rubinius
|
|
49
47
|
|
|
50
48
|
## Installation
|
|
51
49
|
|
|
52
50
|
```bash
|
|
53
|
-
|
|
51
|
+
gem install webmock
|
|
54
52
|
```
|
|
55
53
|
or alternatively:
|
|
56
54
|
|
|
57
55
|
```ruby
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
56
|
+
# add to your Gemfile
|
|
57
|
+
group :test do
|
|
58
|
+
gem "webmock"
|
|
59
|
+
end
|
|
62
60
|
```
|
|
63
61
|
|
|
64
62
|
### or to install the latest development version from github master
|
|
65
63
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
64
|
+
```bash
|
|
65
|
+
git clone http://github.com/bblimke/webmock.git
|
|
66
|
+
cd webmock
|
|
67
|
+
rake install
|
|
68
|
+
```
|
|
69
69
|
|
|
70
70
|
## Upgrading from v1.x to v2.x
|
|
71
71
|
|
|
@@ -330,6 +330,16 @@ stub_request(:any, "www.example.com").
|
|
|
330
330
|
Net::HTTP.get('www.example.com', '/') # ===> "abc\n"
|
|
331
331
|
```
|
|
332
332
|
|
|
333
|
+
### Response with JSON body
|
|
334
|
+
|
|
335
|
+
```ruby
|
|
336
|
+
|
|
337
|
+
stub_request(:any, "www.example.com").
|
|
338
|
+
to_return_json(body: {foo: "bar"})
|
|
339
|
+
|
|
340
|
+
Net::HTTP.get('www.example.com', '/') # ===> "{\"foo\": \"bar\"}"
|
|
341
|
+
```
|
|
342
|
+
|
|
333
343
|
### Response with custom status message
|
|
334
344
|
|
|
335
345
|
```ruby
|
|
@@ -383,7 +393,8 @@ RestClient.post('www.example.net', 'abc') # ===> "abc\n"
|
|
|
383
393
|
|
|
384
394
|
### Dynamically evaluated raw responses recorded with `curl -is`
|
|
385
395
|
|
|
386
|
-
|
|
396
|
+
`curl -is www.example.com > /tmp/www.example.com.txt`
|
|
397
|
+
|
|
387
398
|
```ruby
|
|
388
399
|
stub_request(:get, "www.example.com").
|
|
389
400
|
to_return(lambda { |request| File.new("/tmp/#{request.uri.host.to_s}.txt") })
|
|
@@ -540,7 +551,7 @@ RestClient.get('www.example.org:8080', '/') # ===> Allowed
|
|
|
540
551
|
With a `Regexp` matching the URI:
|
|
541
552
|
|
|
542
553
|
```ruby
|
|
543
|
-
WebMock.disable_net_connect!(allow: %r{ample
|
|
554
|
+
WebMock.disable_net_connect!(allow: %r{ample\.org/foo})
|
|
544
555
|
|
|
545
556
|
RestClient.get('www.example.org', '/foo/bar') # ===> Allowed
|
|
546
557
|
RestClient.get('sample.org', '/foo') # ===> Allowed
|
|
@@ -1170,6 +1181,14 @@ People who submitted patches and new features or suggested improvements. Many th
|
|
|
1170
1181
|
* Cedric Sohrauer
|
|
1171
1182
|
* Akira Matsuda
|
|
1172
1183
|
* Mark Spangler
|
|
1184
|
+
* Henrik Nyh
|
|
1185
|
+
* Yoann Lecuyer
|
|
1186
|
+
* Lucas Arnaud
|
|
1187
|
+
* Marc Rohloff
|
|
1188
|
+
* inkstak
|
|
1189
|
+
* Yuki Inoue
|
|
1190
|
+
* Brandon Weaver
|
|
1191
|
+
* Josh Nichols
|
|
1173
1192
|
|
|
1174
1193
|
For a full list of contributors you can visit the
|
|
1175
1194
|
[contributors](https://github.com/bblimke/webmock/contributors) page.
|
data/lib/webmock/api.rb
CHANGED
data/lib/webmock/config.rb
CHANGED
data/lib/webmock/cucumber.rb
CHANGED
data/lib/webmock/deprecation.rb
CHANGED
data/lib/webmock/errors.rb
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
begin
|
|
2
4
|
require 'em-http-request'
|
|
3
5
|
rescue LoadError
|
|
@@ -101,7 +103,7 @@ if defined?(EventMachine::HttpClient)
|
|
|
101
103
|
|
|
102
104
|
def connection_completed
|
|
103
105
|
@state = :response_header
|
|
104
|
-
send_request(
|
|
106
|
+
send_request(*headers_and_body_processed_by_middleware)
|
|
105
107
|
end
|
|
106
108
|
|
|
107
109
|
def send_request(head, body)
|
|
@@ -168,12 +170,18 @@ if defined?(EventMachine::HttpClient)
|
|
|
168
170
|
webmock_response
|
|
169
171
|
end
|
|
170
172
|
|
|
171
|
-
def
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
173
|
+
def headers_and_body_processed_by_middleware
|
|
174
|
+
@headers_and_body_processed_by_middleware ||= begin
|
|
175
|
+
head, body = build_request, @req.body
|
|
176
|
+
@conn.middleware.each do |m|
|
|
177
|
+
head, body = m.request(self, head, body) if m.respond_to?(:request)
|
|
178
|
+
end
|
|
179
|
+
[head, body]
|
|
176
180
|
end
|
|
181
|
+
end
|
|
182
|
+
|
|
183
|
+
def build_request_signature
|
|
184
|
+
headers, body = headers_and_body_processed_by_middleware
|
|
177
185
|
|
|
178
186
|
method = @req.method
|
|
179
187
|
uri = @req.uri.clone
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module HTTP
|
|
2
4
|
class Request
|
|
3
5
|
def webmock_signature
|
|
4
6
|
request_body = if defined?(HTTP::Request::Body)
|
|
5
|
-
|
|
7
|
+
String.new.tap { |string| body.each { |part| string << part } }
|
|
6
8
|
else
|
|
7
9
|
body
|
|
8
10
|
end
|
data/lib/webmock/minitest.rb
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module WebMock
|
|
2
4
|
|
|
3
5
|
module RSpecMatcherDetector
|
|
@@ -283,7 +285,7 @@ module WebMock
|
|
|
283
285
|
matching_body_hashes?(body_as_hash(body, content_type), @pattern, content_type)
|
|
284
286
|
elsif (@pattern).is_a?(Array)
|
|
285
287
|
matching_body_array?(body_as_hash(body, content_type), @pattern, content_type)
|
|
286
|
-
elsif (@pattern).is_a?(WebMock::Matchers::
|
|
288
|
+
elsif (@pattern).is_a?(WebMock::Matchers::HashArgumentMatcher)
|
|
287
289
|
@pattern == body_as_hash(body, content_type)
|
|
288
290
|
else
|
|
289
291
|
empty_string?(@pattern) && empty_string?(body) ||
|
data/lib/webmock/request_stub.rb
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module WebMock
|
|
2
4
|
class RequestStub
|
|
3
5
|
|
|
@@ -29,9 +31,13 @@ module WebMock
|
|
|
29
31
|
|
|
30
32
|
json_response_hashes = [*response_hashes].flatten.map do |resp_h|
|
|
31
33
|
headers, body = resp_h.values_at(:headers, :body)
|
|
34
|
+
|
|
35
|
+
body = body.call if body.respond_to?(:call)
|
|
36
|
+
body = body.to_json unless body.is_a?(String)
|
|
37
|
+
|
|
32
38
|
resp_h.merge(
|
|
33
39
|
headers: {content_type: 'application/json'}.merge(headers.to_h),
|
|
34
|
-
body: body
|
|
40
|
+
body: body
|
|
35
41
|
)
|
|
36
42
|
end
|
|
37
43
|
|
data/lib/webmock/response.rb
CHANGED
data/lib/webmock/rspec.rb
CHANGED
data/lib/webmock/test_unit.rb
CHANGED
|
@@ -1,29 +1,35 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'thread'
|
|
2
4
|
|
|
3
5
|
module WebMock
|
|
4
6
|
module Util
|
|
5
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
|