webmock 3.14.0 → 3.24.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +207 -3
- data/README.md +65 -20
- 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 +16 -4
- data/lib/webmock/http_lib_adapters/curb_adapter.rb +4 -2
- data/lib/webmock/http_lib_adapters/em_http_request_adapter.rb +17 -7
- 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 +3 -3
- data/lib/webmock/http_lib_adapters/http_rb/request.rb +17 -5
- data/lib/webmock/http_lib_adapters/http_rb/response.rb +32 -9
- data/lib/webmock/http_lib_adapters/http_rb/streamer.rb +10 -2
- 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 +26 -25
- data/lib/webmock/http_lib_adapters/manticore_adapter.rb +2 -0
- data/lib/webmock/http_lib_adapters/net_http.rb +28 -117
- data/lib/webmock/http_lib_adapters/net_http_response.rb +2 -0
- data/lib/webmock/http_lib_adapters/patron_adapter.rb +3 -1
- 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 +2 -0
- data/lib/webmock/request_execution_verifier.rb +2 -0
- data/lib/webmock/request_pattern.rb +35 -12
- 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 +15 -13
- 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 +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 +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 +12 -0
- data/lib/webmock.rb +4 -2
- metadata +66 -182
- data/.gemtest +0 -0
- data/.github/workflows/CI.yml +0 -37
- data/.gitignore +0 -34
- data/.rspec-tm +0 -2
- data/Gemfile +0 -9
- data/Rakefile +0 -38
- 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/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 -499
- 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 -153
- data/spec/acceptance/net_http/net_http_spec.rb +0 -369
- 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 -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 -736
- 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 -286
- 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 -60
- 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: 9283efd8ecb49795fe14fc5903295b0d143fbdd17f5cc1611e89d918f917c33f
|
4
|
+
data.tar.gz: ea556e59d242667816568c75f7c42be613e09f688c3ada07c65f0c9de0e3d05d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bcd310894ba47584609ffafcd332cbd824d3921ec938a7ca63e84e983436188dbf7f44a13137e407b3c5798fd9a02ced95e5797ac9ee3e923adf588cf04c4015
|
7
|
+
data.tar.gz: 617bcf11b564bf6cc2faf4a973e9882dbb9639e685ed989fe6bc11b65c1ea7e66d12a106484e2e641ff4fda4c8c7336fe83509852b2a858f94fe0a657b5aae6c
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,209 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
# 3.24.0
|
4
|
+
|
5
|
+
* Ignore parsing errors when parsing invalid JSON or XML body to match against body pattern #1066
|
6
|
+
|
7
|
+
Thanks to [Christian Schmidt](https://github.com/c960657)
|
8
|
+
|
9
|
+
* Added support for mocked HTTP::Connection#finished_request? method #1065
|
10
|
+
|
11
|
+
Thanks to [Christian Schmidt](https://github.com/c960657)
|
12
|
+
|
13
|
+
* Detect if Patron is loaded by checking if Patron::Session constant is defined #1068
|
14
|
+
|
15
|
+
Thanks to [Rodrigo Argumedo](https://github.com/rodrigoargumedo)
|
16
|
+
|
17
|
+
* Raising an ArgumentError when uri is passed as a Pathname object to stub_request or request expectation declaration.
|
18
|
+
|
19
|
+
* Dropped support for em-http-request on Ruby 3.4. The current version of em-http-request (1.1.7) is incompatible with Ruby 3.4 due to an unresolved issue (https://github.com/igrigorik/em-http-request/issues/365). Support for em-http-request will be re-enabled once the compatibility issue is resolved.
|
20
|
+
|
21
|
+
Thanks to [Christian Schmidt](https://github.com/c960657)
|
22
|
+
|
23
|
+
# 3.23.1
|
24
|
+
|
25
|
+
* Added support for async-http version >= 0.65.0 [PR](https://github.com/bblimke/webmock/pull/1056)
|
26
|
+
|
27
|
+
Thanks to [Jacob Frautschi](https://github.com/jakeonfire)
|
28
|
+
|
29
|
+
# 3.23.0
|
30
|
+
|
31
|
+
* Fixed HTTP.rb adapter to support streaming real responses when WebMock is enabled.
|
32
|
+
|
33
|
+
Thanks to [Viacheslav Nepomniashchikh](https://github.com/aka-nez) for reporting and investigating this [issue](https://github.com/bblimke/webmock/issues/1017).
|
34
|
+
|
35
|
+
# 3.22.0
|
36
|
+
|
37
|
+
* Addressed an issue in the HTTPClient adapter where memoized stubbed responses and memoized request_signatures were incorrectly persisted between subsequent requests ([#1019](https://github.com/bblimke/webmock/issues/1019)). The implementation of a more robust thread-safety solution by [Tom Beauvais](https://github.com/tbeauvais) in [PR #300](https://github.com/bblimke/webmock/pull/300) not only resolved the memoization problem but also enhanced the overall thread safety of the adapter. This update ensures that stubbed responses and request signatures are correctly isolated to individual requests, improving both consistency and thread safety.
|
38
|
+
|
39
|
+
# 3.21.2
|
40
|
+
|
41
|
+
* Corrected type checking in `WebMock::Response#assert_valid_body!` to accurately recognize `Hash` objects. Additionally, improved the clarity of the error message for unsupported body types, guiding users towards proper usage.
|
42
|
+
|
43
|
+
Thanks to [Jake Robb](https://github.com/jakerobb) for reporting.
|
44
|
+
|
45
|
+
# 3.21.1
|
46
|
+
|
47
|
+
* The stubbed Net::HTTPResponse#uri now returns request.uri, aligning it with the behavior of an actual Net::HTTPResponse.
|
48
|
+
|
49
|
+
Thanks to [Abe Voelker](https://github.com/abevoelker) for reporting and to [Victor Maslov](https://github.com/Nakilon) and [Gio Lodi](https://github.com/mokagio) for the suggested solution.
|
50
|
+
|
51
|
+
# 3.21.0
|
52
|
+
|
53
|
+
* Don't use deprecated Rack::VERSION for Rack >= 3
|
54
|
+
|
55
|
+
Thanks to [Étienne Barrié](https://github.com/etiennebarrie)
|
56
|
+
|
57
|
+
* Updated HTTPClient adapter, to build request signature using the URI after filters have been applied.
|
58
|
+
|
59
|
+
Thanks to [Matt Brown](https://github.com/mattbnz)
|
60
|
+
|
61
|
+
# 3.20.0
|
62
|
+
|
63
|
+
* Optimised EmHttpRequestAdapter performance.
|
64
|
+
|
65
|
+
Thanks to [Ricardo Trindade](https://github.com/RicardoTrindade)
|
66
|
+
|
67
|
+
* Removed runtime dependency on base64.
|
68
|
+
|
69
|
+
Thanks to [Earlopain](https://github.com/Earlopain)
|
70
|
+
|
71
|
+
* Typhoeus::Response objects constructed from stubbed responses now have all timing attributes set to 0.0.
|
72
|
+
|
73
|
+
Thanks to [James Brown](https://github.com/Roguelazer)
|
74
|
+
|
75
|
+
* Optimised WebMock::Util::Headers by removing redundant freeze invocations.
|
76
|
+
|
77
|
+
Thanks to [Kazuhiro NISHIYAMA](https://github.com/znz)
|
78
|
+
|
79
|
+
* The default stubbed response body, which is an empty String, is unfrozen.
|
80
|
+
|
81
|
+
* When building signatures of requests made by http.rb, the request body encoding is now preserved.
|
82
|
+
|
83
|
+
# 3.19.1
|
84
|
+
|
85
|
+
* When passing a Proc or lambda as response body to `to_return_json`, the body is evaluated at the time of request and not at the time of `to_return_json` method invocation.
|
86
|
+
|
87
|
+
Thanks to [Jason Karns](https://github.com/jasonkarns) for reporting.
|
88
|
+
|
89
|
+
# 3.19.0
|
90
|
+
|
91
|
+
* Do not alter real (non-stubbed) request headers when handling em-http-request requests.
|
92
|
+
|
93
|
+
Thanks to [Yoann Lecuyer](https://github.com/ylecuyer)
|
94
|
+
|
95
|
+
* Fix matching stubs with HashExcludingMatcher
|
96
|
+
|
97
|
+
Thanks to [Lucas Arnaud](https://github.com/lucasarnaud)
|
98
|
+
|
99
|
+
* Remove development and test files from the gem package
|
100
|
+
|
101
|
+
Thanks to [Orien Madgwick](https://github.com/orien)
|
102
|
+
|
103
|
+
* Fix supported http client gem version checks.
|
104
|
+
|
105
|
+
Thanks to [Marc Rohloff](https://github.com/marcrohloff) and [Roman Stražanec](https://github.com/romanstrazanec)
|
106
|
+
|
107
|
+
* Non-string body passed to #to_return_json is now converted to JSON string.
|
108
|
+
|
109
|
+
Thanks to [inkstak](https://github.com/inkstak)
|
110
|
+
|
111
|
+
* `[::1]` is recognised as localhost e.g when passing `allow_localhost` option to `disable_net_connect!`
|
112
|
+
|
113
|
+
Thanks to [Yuki Inoue](https://github.com/Yuki-Inoue)
|
114
|
+
|
115
|
+
* Optimized `normalize_headers` for performance
|
116
|
+
|
117
|
+
Thanks to [Brandon Weaver](https://github.com/baweaver)
|
118
|
+
|
119
|
+
* Added Frozen string literal to files to optimise memory usage
|
120
|
+
|
121
|
+
Thanks to [Josh Nichols](https://github.com/technicalpickles)
|
122
|
+
|
123
|
+
# 3.18.1
|
124
|
+
|
125
|
+
* Reverted simplified connection handing in Net::HTTP adapter due to https://github.com/bblimke/webmock/issues/999
|
126
|
+
|
127
|
+
# 3.18.0
|
128
|
+
|
129
|
+
* Net::BufferedIO is not replaced anymore.
|
130
|
+
|
131
|
+
Thanks to [Ray Zane](https://github.com/rzane)
|
132
|
+
|
133
|
+
* Simplified connection handing in Net::HTTP adapter.
|
134
|
+
|
135
|
+
Thanks to [Ray Zane](https://github.com/rzane)
|
136
|
+
|
137
|
+
# 3.17.1
|
138
|
+
|
139
|
+
* Fixed Syntax Error
|
140
|
+
|
141
|
+
Thanks to [Mark Spangler](https://github.com/mspangler)
|
142
|
+
|
143
|
+
# 3.17.0
|
144
|
+
|
145
|
+
* Minimum required Ruby version is 2.3
|
146
|
+
|
147
|
+
Thanks to [Go Sueyoshi](https://github.com/sue445)
|
148
|
+
|
149
|
+
* When using Net::HTTP, stubbed socket StubSocket#close and StubSocket#closed? behave more like the real sockets.
|
150
|
+
|
151
|
+
Thanks to [Ray Zane](https://github.com/rzane)
|
152
|
+
|
153
|
+
* Added `peeraddr`, `ssl_version` and `cipher` methods to stubbed sockets used by Net::HTTP.
|
154
|
+
|
155
|
+
Thanks to [Ray Zane](https://github.com/rzane)
|
156
|
+
|
157
|
+
* Added support for matching top-level array in JSON request body.
|
158
|
+
|
159
|
+
E.g.
|
160
|
+
|
161
|
+
````
|
162
|
+
stub_request(:post, 'www.example.com').with(body: [{a: 1}])
|
163
|
+
````
|
164
|
+
|
165
|
+
Thanks to [Cedric Sohrauer](https://github.com/cedrics)
|
166
|
+
|
167
|
+
# 3.16.2
|
168
|
+
|
169
|
+
* Minimum required Ruby version is 2.0.
|
170
|
+
|
171
|
+
# 3.16.0 (yanked)
|
172
|
+
|
173
|
+
* Fix leaky file descriptors and reuse socket for persistent connections.
|
174
|
+
|
175
|
+
Thanks to [Ray Zane](https://github.com/rzane)
|
176
|
+
|
177
|
+
* Allow specifying for what URIs or hosts, Net::HTTP should connect on start.
|
178
|
+
|
179
|
+
Thanks to [Ray Zane](https://github.com/rzane)
|
180
|
+
|
181
|
+
# 3.15.2
|
182
|
+
|
183
|
+
* Minimum required Ruby version is 2.0.
|
184
|
+
|
185
|
+
# 3.15.0 (yanked)
|
186
|
+
|
187
|
+
* fixed async-http adapter on Windows
|
188
|
+
|
189
|
+
Thanks to [Pavel Rosický](https://github.com/ahorek)
|
190
|
+
|
191
|
+
* Support for http.rb >= 5.0.2
|
192
|
+
|
193
|
+
Thanks to [ojab](https://github.com/ojab)
|
194
|
+
|
195
|
+
* Curb adapter supports headers with `:` character in the header value
|
196
|
+
|
197
|
+
Thanks to [Giorgio Gambino](https://github.com/mrbuzz)
|
198
|
+
|
199
|
+
* Support for matching body of JSON or application/x-www-form-urlencoded requests with content type header including charset.
|
200
|
+
|
201
|
+
Thanks to [Timmitry](https://github.com/Timmitry)
|
202
|
+
|
203
|
+
* Prevent double-wrapping http.rb features on non-stubbed requests
|
204
|
+
|
205
|
+
Thanks to [Michael Fairley](https://github.com/michaelfairley)
|
206
|
+
|
3
207
|
# 3.14.0
|
4
208
|
|
5
209
|
* Bump Addressable from 2.3.6 to 2.8.0
|
@@ -32,7 +236,7 @@
|
|
32
236
|
|
33
237
|
* Fixed async-http adapter to only considered requests as real if they are real.
|
34
238
|
|
35
|
-
Thanks to
|
239
|
+
Thanks to [Tony Schneider](https://github.com/tonywok) and [Samuel Williams](https://github.com/ioquatix)
|
36
240
|
|
37
241
|
# 3.11.2
|
38
242
|
|
@@ -605,9 +809,9 @@
|
|
605
809
|
* `WebMock.disable_net_connect` accepts `:allow` option with an object that responds to `#call`, receiving a `URI` object and returning a boolean:
|
606
810
|
|
607
811
|
|
608
|
-
|
812
|
+
denylist = ['google.com', 'facebook.com', 'apple.com']
|
609
813
|
allowed_sites = lambda{|uri|
|
610
|
-
|
814
|
+
denylist.none?{|site| uri.host.include?(site) }
|
611
815
|
}
|
612
816
|
WebMock.disable_net_connect!(:allow => allowed_sites)
|
613
817
|
|
data/README.md
CHANGED
@@ -1,11 +1,9 @@
|
|
1
1
|
WebMock
|
2
2
|
=======
|
3
3
|
[![Gem Version](https://badge.fury.io/rb/webmock.svg)](http://badge.fury.io/rb/webmock)
|
4
|
-
[![Build Status](https://github.com/bblimke/webmock/workflows/CI/badge.svg?branch=master)](https://github.com/bblimke/webmock/actions)
|
4
|
+
[![Build Status](https://github.com/bblimke/webmock/actions/workflows/CI.yml/badge.svg?branch=master)](https://github.com/bblimke/webmock/actions)
|
5
5
|
[![Code Climate](https://codeclimate.com/github/bblimke/webmock/badges/gpa.svg)](https://codeclimate.com/github/bblimke/webmock)
|
6
6
|
[![Mentioned in Awesome Ruby](https://awesome.re/mentioned-badge.svg)](https://github.com/markets/awesome-ruby)
|
7
|
-
[![Inline docs](http://inch-ci.org/github/bblimke/webmock.svg?branch=master)](http://inch-ci.org/github/bblimke/webmock)
|
8
|
-
[![SemVer](https://api.dependabot.com/badges/compatibility_score?dependency-name=webmock&package-manager=bundler&version-scheme=semver)](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,35 @@ 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
|
46
|
+
* MRI 3.3
|
47
47
|
* JRuby
|
48
|
-
* Rubinius
|
49
48
|
|
50
49
|
## Installation
|
51
50
|
|
52
51
|
```bash
|
53
|
-
|
52
|
+
gem install webmock
|
54
53
|
```
|
55
54
|
or alternatively:
|
56
55
|
|
57
56
|
```ruby
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
57
|
+
# add to your Gemfile
|
58
|
+
group :test do
|
59
|
+
gem "webmock"
|
60
|
+
end
|
62
61
|
```
|
63
62
|
|
64
63
|
### or to install the latest development version from github master
|
65
64
|
|
66
|
-
|
67
|
-
|
68
|
-
|
65
|
+
```bash
|
66
|
+
git clone http://github.com/bblimke/webmock.git
|
67
|
+
cd webmock
|
68
|
+
rake install
|
69
|
+
```
|
69
70
|
|
70
71
|
## Upgrading from v1.x to v2.x
|
71
72
|
|
@@ -330,6 +331,16 @@ stub_request(:any, "www.example.com").
|
|
330
331
|
Net::HTTP.get('www.example.com', '/') # ===> "abc\n"
|
331
332
|
```
|
332
333
|
|
334
|
+
### Response with JSON body
|
335
|
+
|
336
|
+
```ruby
|
337
|
+
|
338
|
+
stub_request(:any, "www.example.com").
|
339
|
+
to_return_json(body: {foo: "bar"})
|
340
|
+
|
341
|
+
Net::HTTP.get('www.example.com', '/') # ===> "{\"foo\": \"bar\"}"
|
342
|
+
```
|
343
|
+
|
333
344
|
### Response with custom status message
|
334
345
|
|
335
346
|
```ruby
|
@@ -383,7 +394,8 @@ RestClient.post('www.example.net', 'abc') # ===> "abc\n"
|
|
383
394
|
|
384
395
|
### Dynamically evaluated raw responses recorded with `curl -is`
|
385
396
|
|
386
|
-
|
397
|
+
`curl -is www.example.com > /tmp/www.example.com.txt`
|
398
|
+
|
387
399
|
```ruby
|
388
400
|
stub_request(:get, "www.example.com").
|
389
401
|
to_return(lambda { |request| File.new("/tmp/#{request.uri.host.to_s}.txt") })
|
@@ -540,7 +552,7 @@ RestClient.get('www.example.org:8080', '/') # ===> Allowed
|
|
540
552
|
With a `Regexp` matching the URI:
|
541
553
|
|
542
554
|
```ruby
|
543
|
-
WebMock.disable_net_connect!(allow: %r{ample
|
555
|
+
WebMock.disable_net_connect!(allow: %r{ample\.org/foo})
|
544
556
|
|
545
557
|
RestClient.get('www.example.org', '/foo/bar') # ===> Allowed
|
546
558
|
RestClient.get('sample.org', '/foo') # ===> Allowed
|
@@ -550,9 +562,9 @@ RestClient.get('sample.org', '/bar') # ===> Failure
|
|
550
562
|
With an object that responds to `#call`, receiving a `URI` object and returning a boolean:
|
551
563
|
|
552
564
|
```ruby
|
553
|
-
|
565
|
+
denylist = ['google.com', 'facebook.com', 'apple.com']
|
554
566
|
allowed_sites = lambda{|uri|
|
555
|
-
|
567
|
+
denylist.none?{|site| uri.host.include?(site) }
|
556
568
|
}
|
557
569
|
WebMock.disable_net_connect!(allow: allowed_sites)
|
558
570
|
|
@@ -595,7 +607,11 @@ which can be passed to `WebMock.allow_net_connect!` and `WebMock.disable_net_con
|
|
595
607
|
WebMock.allow_net_connect!(net_http_connect_on_start: true)
|
596
608
|
```
|
597
609
|
|
598
|
-
This forces WebMock Net::HTTP adapter to always connect on `Net::HTTP.start`.
|
610
|
+
This forces WebMock Net::HTTP adapter to always connect on `Net::HTTP.start`. At the time of connection being made there is no information about the request or URL yet, therefore WebMock is not able to decide whether to stub a request or not and all connections are allowed. To enable connections only to a specific domain (e.g. your test server) use:
|
611
|
+
|
612
|
+
```ruby
|
613
|
+
WebMock.allow_net_connect!(net_http_connect_on_start: "www.example.com")
|
614
|
+
```
|
599
615
|
|
600
616
|
## Setting Expectations
|
601
617
|
|
@@ -1161,13 +1177,42 @@ People who submitted patches and new features or suggested improvements. Many th
|
|
1161
1177
|
* Alex Vondrak
|
1162
1178
|
* Will Storey
|
1163
1179
|
* Eduardo Hernandez
|
1180
|
+
* ojab
|
1181
|
+
* Giorgio Gambino
|
1182
|
+
* Timmitry
|
1183
|
+
* Michael Fairley
|
1184
|
+
* Ray Zane
|
1185
|
+
* Go Sueyoshi
|
1186
|
+
* Cedric Sohrauer
|
1187
|
+
* Akira Matsuda
|
1188
|
+
* Mark Spangler
|
1189
|
+
* Henrik Nyh
|
1190
|
+
* Yoann Lecuyer
|
1191
|
+
* Lucas Arnaud
|
1192
|
+
* Marc Rohloff
|
1193
|
+
* inkstak
|
1194
|
+
* Yuki Inoue
|
1195
|
+
* Brandon Weaver
|
1196
|
+
* Josh Nichols
|
1197
|
+
* Ricardo Trindade
|
1198
|
+
* Earlopain
|
1199
|
+
* James Brown
|
1200
|
+
* Kazuhiro NISHIYAMA
|
1201
|
+
* Étienne Barrié
|
1202
|
+
* Matt Brown
|
1203
|
+
* Victor Maslov
|
1204
|
+
* Gio Lodi
|
1205
|
+
* Ryan Brooks
|
1206
|
+
* Jacob Frautschi
|
1207
|
+
* Christian Schmidt
|
1208
|
+
* Rodrigo Argumedo
|
1164
1209
|
|
1165
1210
|
For a full list of contributors you can visit the
|
1166
1211
|
[contributors](https://github.com/bblimke/webmock/contributors) page.
|
1167
1212
|
|
1168
1213
|
## Background
|
1169
1214
|
|
1170
|
-
Thank you Fakeweb! This library was inspired by [FakeWeb](
|
1215
|
+
Thank you Fakeweb! This library was inspired by [FakeWeb](https://github.com/chrisk/fakeweb).
|
1171
1216
|
I imported some solutions from that project to WebMock. I also copied some code i.e Net:HTTP adapter.
|
1172
1217
|
Fakeweb architecture unfortunately didn't allow me to extend it easily with the features I needed.
|
1173
1218
|
I also preferred some things to work differently i.e request stub precedence.
|
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 'async'
|
3
5
|
require 'async/http'
|
@@ -33,9 +35,9 @@ if defined?(Async::HTTP)
|
|
33
35
|
class WebMockClientWrapper < Client
|
34
36
|
def initialize(
|
35
37
|
endpoint,
|
36
|
-
protocol
|
37
|
-
scheme
|
38
|
-
authority
|
38
|
+
protocol: endpoint.protocol,
|
39
|
+
scheme: endpoint.scheme,
|
40
|
+
authority: endpoint.authority,
|
39
41
|
**options
|
40
42
|
)
|
41
43
|
webmock_endpoint = WebMockEndpoint.new(scheme, authority, protocol)
|
@@ -43,6 +45,7 @@ if defined?(Async::HTTP)
|
|
43
45
|
@network_client = WebMockClient.new(endpoint, **options)
|
44
46
|
@webmock_client = WebMockClient.new(webmock_endpoint, **options)
|
45
47
|
|
48
|
+
@endpoint = endpoint
|
46
49
|
@scheme = scheme
|
47
50
|
@authority = authority
|
48
51
|
end
|
@@ -150,8 +153,17 @@ if defined?(Async::HTTP)
|
|
150
153
|
|
151
154
|
private
|
152
155
|
|
156
|
+
def socket_class
|
157
|
+
defined?(Async::IO::Socket) ? Async::IO::Socket : Socket
|
158
|
+
end
|
159
|
+
|
153
160
|
def create_connected_sockets
|
154
|
-
|
161
|
+
pair = begin
|
162
|
+
socket_class.pair(Socket::AF_UNIX, Socket::SOCK_STREAM)
|
163
|
+
rescue Errno::EAFNOSUPPORT
|
164
|
+
socket_class.pair(Socket::AF_INET, Socket::SOCK_STREAM)
|
165
|
+
end
|
166
|
+
pair.tap do |sockets|
|
155
167
|
sockets.each do |socket|
|
156
168
|
socket.instance_variable_set :@alpn_protocol, nil
|
157
169
|
socket.instance_eval do
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
begin
|
2
4
|
require 'curb'
|
3
5
|
rescue LoadError
|
@@ -5,7 +7,7 @@ rescue LoadError
|
|
5
7
|
end
|
6
8
|
|
7
9
|
if defined?(Curl)
|
8
|
-
WebMock::VersionChecker.new('Curb', Curl::CURB_VERSION, '0.7.16', '0.
|
10
|
+
WebMock::VersionChecker.new('Curb', Curl::CURB_VERSION, '0.7.16', '1.0.1', ['0.8.7']).check_version!
|
9
11
|
|
10
12
|
module WebMock
|
11
13
|
module HttpLibAdapters
|
@@ -128,7 +130,7 @@ if defined?(Curl)
|
|
128
130
|
def headers_as_hash(headers)
|
129
131
|
if headers.is_a?(Array)
|
130
132
|
headers.inject({}) {|hash, header|
|
131
|
-
name, value = header.split(":").map(&:strip)
|
133
|
+
name, value = header.split(":", 2).map(&:strip)
|
132
134
|
hash[name] = value
|
133
135
|
hash
|
134
136
|
}
|
@@ -1,3 +1,7 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
return if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('3.4.0')
|
4
|
+
|
1
5
|
begin
|
2
6
|
require 'em-http-request'
|
3
7
|
rescue LoadError
|
@@ -101,7 +105,7 @@ if defined?(EventMachine::HttpClient)
|
|
101
105
|
|
102
106
|
def connection_completed
|
103
107
|
@state = :response_header
|
104
|
-
send_request(
|
108
|
+
send_request(*headers_and_body_processed_by_middleware)
|
105
109
|
end
|
106
110
|
|
107
111
|
def send_request(head, body)
|
@@ -154,7 +158,7 @@ if defined?(EventMachine::HttpClient)
|
|
154
158
|
raw_cookie = response_header.cookie
|
155
159
|
raw_cookie = [raw_cookie] if raw_cookie.is_a? String
|
156
160
|
|
157
|
-
cookie = raw_cookie.
|
161
|
+
cookie = raw_cookie.detect { |c| c.start_with? name }
|
158
162
|
cookie and cookie.split('=', 2)[1]
|
159
163
|
end
|
160
164
|
|
@@ -168,12 +172,18 @@ if defined?(EventMachine::HttpClient)
|
|
168
172
|
webmock_response
|
169
173
|
end
|
170
174
|
|
171
|
-
def
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
175
|
+
def headers_and_body_processed_by_middleware
|
176
|
+
@headers_and_body_processed_by_middleware ||= begin
|
177
|
+
head, body = build_request, @req.body
|
178
|
+
@conn.middleware.each do |m|
|
179
|
+
head, body = m.request(self, head, body) if m.respond_to?(:request)
|
180
|
+
end
|
181
|
+
[head, body]
|
176
182
|
end
|
183
|
+
end
|
184
|
+
|
185
|
+
def build_request_signature
|
186
|
+
headers, body = headers_and_body_processed_by_middleware
|
177
187
|
|
178
188
|
method = @req.method
|
179
189
|
uri = @req.uri.clone
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module HTTP
|
2
4
|
class Client
|
3
5
|
alias_method :__perform__, :perform
|
@@ -5,9 +7,7 @@ module HTTP
|
|
5
7
|
def perform(request, options)
|
6
8
|
return __perform__(request, options) unless webmock_enabled?
|
7
9
|
|
8
|
-
|
9
|
-
options.features.each { |_name, feature| response = feature.wrap_response(response) }
|
10
|
-
response
|
10
|
+
WebMockPerform.new(request, options) { __perform__(request, options) }.exec
|
11
11
|
end
|
12
12
|
|
13
13
|
def webmock_enabled?
|
@@ -1,11 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module HTTP
|
2
4
|
class Request
|
3
5
|
def webmock_signature
|
4
|
-
request_body =
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
6
|
+
request_body = nil
|
7
|
+
|
8
|
+
if defined?(HTTP::Request::Body)
|
9
|
+
request_body = String.new
|
10
|
+
first_chunk_encoding = nil
|
11
|
+
body.each do |part|
|
12
|
+
request_body << part
|
13
|
+
first_chunk_encoding ||= part.encoding
|
14
|
+
end
|
15
|
+
|
16
|
+
request_body.force_encoding(first_chunk_encoding) if first_chunk_encoding
|
17
|
+
request_body
|
18
|
+
else
|
19
|
+
request_body = body
|
20
|
+
end
|
9
21
|
|
10
22
|
::WebMock::RequestSignature.new(verb, uri.to_s, {
|
11
23
|
headers: headers.to_h,
|