webmock 1.8.6 → 3.14.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.github/workflows/CI.yml +37 -0
- data/.gitignore +6 -0
- data/CHANGELOG.md +1198 -0
- data/Gemfile +3 -15
- data/README.md +761 -305
- data/Rakefile +13 -40
- data/lib/webmock/api.rb +63 -17
- data/lib/webmock/callback_registry.rb +1 -1
- data/lib/webmock/config.rb +8 -0
- data/lib/webmock/cucumber.rb +2 -0
- data/lib/webmock/errors.rb +8 -24
- data/lib/webmock/http_lib_adapters/async_http_client_adapter.rb +216 -0
- data/lib/webmock/http_lib_adapters/curb_adapter.rb +148 -84
- data/lib/webmock/http_lib_adapters/em_http_request_adapter.rb +224 -4
- data/lib/webmock/http_lib_adapters/excon_adapter.rb +104 -34
- data/lib/webmock/http_lib_adapters/http_rb/client.rb +17 -0
- data/lib/webmock/http_lib_adapters/http_rb/request.rb +16 -0
- data/lib/webmock/http_lib_adapters/http_rb/response.rb +64 -0
- data/lib/webmock/http_lib_adapters/http_rb/streamer.rb +29 -0
- data/lib/webmock/http_lib_adapters/http_rb/webmock.rb +68 -0
- data/lib/webmock/http_lib_adapters/http_rb_adapter.rb +37 -0
- data/lib/webmock/http_lib_adapters/httpclient_adapter.rb +152 -86
- data/lib/webmock/http_lib_adapters/manticore_adapter.rb +145 -0
- data/lib/webmock/http_lib_adapters/net_http.rb +155 -46
- data/lib/webmock/http_lib_adapters/net_http_response.rb +1 -1
- data/lib/webmock/http_lib_adapters/patron_adapter.rb +16 -15
- data/lib/webmock/http_lib_adapters/typhoeus_hydra_adapter.rb +76 -82
- data/lib/webmock/matchers/any_arg_matcher.rb +13 -0
- data/lib/webmock/matchers/hash_argument_matcher.rb +21 -0
- data/lib/webmock/matchers/hash_excluding_matcher.rb +15 -0
- data/lib/webmock/matchers/hash_including_matcher.rb +4 -12
- data/lib/webmock/minitest.rb +29 -3
- data/lib/webmock/rack_response.rb +14 -7
- data/lib/webmock/request_body_diff.rb +64 -0
- data/lib/webmock/request_execution_verifier.rb +38 -17
- data/lib/webmock/request_pattern.rb +158 -38
- data/lib/webmock/request_registry.rb +3 -3
- data/lib/webmock/request_signature.rb +7 -3
- data/lib/webmock/request_signature_snippet.rb +61 -0
- data/lib/webmock/request_stub.rb +9 -6
- data/lib/webmock/response.rb +30 -15
- data/lib/webmock/rspec/matchers/request_pattern_matcher.rb +38 -2
- data/lib/webmock/rspec/matchers/webmock_matcher.rb +23 -2
- data/lib/webmock/rspec/matchers.rb +0 -1
- data/lib/webmock/rspec.rb +11 -2
- data/lib/webmock/stub_registry.rb +31 -10
- data/lib/webmock/stub_request_snippet.rb +14 -6
- data/lib/webmock/test_unit.rb +4 -4
- data/lib/webmock/util/hash_counter.rb +20 -6
- data/lib/webmock/util/hash_keys_stringifier.rb +5 -3
- data/lib/webmock/util/hash_validator.rb +17 -0
- data/lib/webmock/util/headers.rb +23 -2
- data/lib/webmock/util/json.rb +20 -7
- data/lib/webmock/util/query_mapper.rb +281 -0
- data/lib/webmock/util/uri.rb +29 -19
- data/lib/webmock/util/values_stringifier.rb +20 -0
- data/lib/webmock/util/version_checker.rb +40 -2
- data/lib/webmock/version.rb +1 -1
- data/lib/webmock/webmock.rb +56 -17
- data/lib/webmock.rb +56 -46
- data/minitest/test_helper.rb +8 -3
- data/minitest/test_webmock.rb +4 -1
- data/minitest/webmock_spec.rb +16 -6
- data/spec/acceptance/async_http_client/async_http_client_spec.rb +375 -0
- data/spec/acceptance/async_http_client/async_http_client_spec_helper.rb +73 -0
- data/spec/acceptance/curb/curb_spec.rb +227 -68
- data/spec/acceptance/curb/curb_spec_helper.rb +11 -8
- data/spec/acceptance/em_http_request/em_http_request_spec.rb +322 -28
- data/spec/acceptance/em_http_request/em_http_request_spec_helper.rb +15 -10
- data/spec/acceptance/excon/excon_spec.rb +66 -4
- data/spec/acceptance/excon/excon_spec_helper.rb +21 -7
- data/spec/acceptance/http_rb/http_rb_spec.rb +93 -0
- data/spec/acceptance/http_rb/http_rb_spec_helper.rb +54 -0
- data/spec/acceptance/httpclient/httpclient_spec.rb +152 -11
- data/spec/acceptance/httpclient/httpclient_spec_helper.rb +25 -16
- data/spec/acceptance/manticore/manticore_spec.rb +107 -0
- data/spec/acceptance/manticore/manticore_spec_helper.rb +35 -0
- data/spec/acceptance/net_http/net_http_shared.rb +52 -24
- data/spec/acceptance/net_http/net_http_spec.rb +164 -50
- data/spec/acceptance/net_http/net_http_spec_helper.rb +19 -10
- data/spec/acceptance/net_http/real_net_http_spec.rb +1 -1
- data/spec/acceptance/patron/patron_spec.rb +29 -40
- data/spec/acceptance/patron/patron_spec_helper.rb +15 -11
- data/spec/acceptance/shared/allowing_and_disabling_net_connect.rb +229 -58
- data/spec/acceptance/shared/callbacks.rb +32 -30
- data/spec/acceptance/shared/complex_cross_concern_behaviors.rb +20 -5
- data/spec/acceptance/shared/enabling_and_disabling_webmock.rb +14 -14
- data/spec/acceptance/shared/precedence_of_stubs.rb +6 -6
- data/spec/acceptance/shared/request_expectations.rb +560 -296
- data/spec/acceptance/shared/returning_declared_responses.rb +180 -138
- data/spec/acceptance/shared/stubbing_requests.rb +385 -154
- data/spec/acceptance/typhoeus/typhoeus_hydra_spec.rb +78 -17
- data/spec/acceptance/typhoeus/typhoeus_hydra_spec_helper.rb +19 -15
- data/spec/acceptance/webmock_shared.rb +2 -2
- data/spec/fixtures/test.txt +1 -0
- data/spec/quality_spec.rb +27 -3
- data/spec/spec_helper.rb +11 -20
- data/spec/support/failures.rb +9 -0
- data/spec/support/my_rack_app.rb +8 -3
- data/spec/support/network_connection.rb +7 -13
- data/spec/support/webmock_server.rb +8 -3
- data/spec/unit/api_spec.rb +175 -0
- data/spec/unit/errors_spec.rb +116 -19
- data/spec/unit/http_lib_adapters/http_lib_adapter_registry_spec.rb +1 -1
- data/spec/unit/http_lib_adapters/http_lib_adapter_spec.rb +2 -2
- data/spec/unit/matchers/hash_excluding_matcher_spec.rb +61 -0
- data/spec/unit/matchers/hash_including_matcher_spec.rb +87 -0
- data/spec/unit/rack_response_spec.rb +54 -16
- data/spec/unit/request_body_diff_spec.rb +90 -0
- data/spec/unit/request_execution_verifier_spec.rb +147 -39
- data/spec/unit/request_pattern_spec.rb +462 -198
- data/spec/unit/request_registry_spec.rb +29 -9
- data/spec/unit/request_signature_snippet_spec.rb +89 -0
- data/spec/unit/request_signature_spec.rb +91 -49
- data/spec/unit/request_stub_spec.rb +71 -70
- data/spec/unit/response_spec.rb +100 -81
- data/spec/unit/stub_registry_spec.rb +37 -20
- data/spec/unit/stub_request_snippet_spec.rb +51 -31
- data/spec/unit/util/hash_counter_spec.rb +6 -6
- data/spec/unit/util/hash_keys_stringifier_spec.rb +4 -4
- data/spec/unit/util/headers_spec.rb +4 -4
- data/spec/unit/util/json_spec.rb +29 -3
- data/spec/unit/util/query_mapper_spec.rb +157 -0
- data/spec/unit/util/uri_spec.rb +150 -36
- data/spec/unit/util/version_checker_spec.rb +15 -9
- data/spec/unit/webmock_spec.rb +57 -4
- data/test/http_request.rb +3 -3
- data/test/shared_test.rb +45 -13
- data/test/test_helper.rb +1 -1
- data/test/test_webmock.rb +6 -0
- data/webmock.gemspec +30 -11
- metadata +308 -199
- data/.rvmrc +0 -1
- data/.travis.yml +0 -11
- data/Guardfile +0 -24
- data/lib/webmock/http_lib_adapters/em_http_request/em_http_request_0_x.rb +0 -151
- data/lib/webmock/http_lib_adapters/em_http_request/em_http_request_1_x.rb +0 -210
@@ -3,96 +3,204 @@ require 'spec_helper'
|
|
3
3
|
describe WebMock::RequestExecutionVerifier do
|
4
4
|
before(:each) do
|
5
5
|
@verifier = WebMock::RequestExecutionVerifier.new
|
6
|
-
@request_pattern =
|
6
|
+
@request_pattern = double(WebMock::RequestPattern, to_s: "www.example.com")
|
7
7
|
@verifier.request_pattern = @request_pattern
|
8
|
-
WebMock::RequestRegistry.instance.
|
8
|
+
allow(WebMock::RequestRegistry.instance).to receive(:to_s).and_return("executed requests")
|
9
9
|
@executed_requests_info = "\n\nThe following requests were made:\n\nexecuted requests\n" + "="*60
|
10
10
|
end
|
11
11
|
|
12
|
+
describe "description" do
|
13
|
+
|
14
|
+
it "reports the description" do
|
15
|
+
@verifier.expected_times_executed = 2
|
16
|
+
expect(@verifier.description).to eq "request www.example.com 2 times"
|
17
|
+
end
|
18
|
+
|
19
|
+
it "reports description correctly when expectation is 1 time" do
|
20
|
+
@verifier.expected_times_executed = 1
|
21
|
+
expect(@verifier.description).to eq "request www.example.com 1 time"
|
22
|
+
end
|
23
|
+
|
24
|
+
context "at_least_times_executed is set" do
|
25
|
+
it "reports description correctly when expectation at least 2 times" do
|
26
|
+
@verifier.at_least_times_executed = 2
|
27
|
+
expect(@verifier.description).to eq "request www.example.com at least 2 times"
|
28
|
+
end
|
29
|
+
|
30
|
+
it "reports description correctly when expectation is at least 3 times" do
|
31
|
+
@verifier.at_least_times_executed = 3
|
32
|
+
expect(@verifier.description).to eq "request www.example.com at least 3 times"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
context "at_most_times_executed is set" do
|
37
|
+
it "reports description correctly when expectation is at most 2 times" do
|
38
|
+
@verifier.at_most_times_executed = 2
|
39
|
+
expect(@verifier.description).to eq "request www.example.com at most 2 times"
|
40
|
+
end
|
41
|
+
|
42
|
+
it "reports description correctly when expectation is at most 1 time" do
|
43
|
+
@verifier.at_most_times_executed = 1
|
44
|
+
expect(@verifier.description).to eq "request www.example.com at most 1 time"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
12
49
|
|
13
50
|
describe "failure message" do
|
14
51
|
|
15
|
-
it "
|
52
|
+
it "reports the failure message" do
|
16
53
|
@verifier.times_executed = 0
|
17
54
|
@verifier.expected_times_executed = 2
|
18
55
|
expected_text = "The request www.example.com was expected to execute 2 times but it executed 0 times"
|
19
|
-
expected_text
|
20
|
-
@verifier.failure_message.
|
56
|
+
expected_text += @executed_requests_info
|
57
|
+
expect(@verifier.failure_message).to eq(expected_text)
|
21
58
|
end
|
22
59
|
|
23
|
-
it "
|
60
|
+
it "reports failure message correctly when executed times is one" do
|
24
61
|
@verifier.times_executed = 1
|
25
62
|
@verifier.expected_times_executed = 1
|
26
63
|
expected_text = "The request www.example.com was expected to execute 1 time but it executed 1 time"
|
27
|
-
expected_text
|
28
|
-
@verifier.failure_message.
|
64
|
+
expected_text += @executed_requests_info
|
65
|
+
expect(@verifier.failure_message).to eq(expected_text)
|
66
|
+
end
|
67
|
+
|
68
|
+
context "at_least_times_executed is set" do
|
69
|
+
it "reports failure message correctly when executed times is one" do
|
70
|
+
@verifier.times_executed = 1
|
71
|
+
@verifier.at_least_times_executed = 2
|
72
|
+
expected_text = "The request www.example.com was expected to execute at least 2 times but it executed 1 time"
|
73
|
+
expected_text += @executed_requests_info
|
74
|
+
expect(@verifier.failure_message).to eq(expected_text)
|
75
|
+
end
|
76
|
+
|
77
|
+
it "reports failure message correctly when executed times is two" do
|
78
|
+
@verifier.times_executed = 2
|
79
|
+
@verifier.at_least_times_executed = 3
|
80
|
+
expected_text = "The request www.example.com was expected to execute at least 3 times but it executed 2 times"
|
81
|
+
expected_text += @executed_requests_info
|
82
|
+
expect(@verifier.failure_message).to eq(expected_text)
|
83
|
+
end
|
29
84
|
end
|
30
85
|
|
86
|
+
context "at_most_times_executed is set" do
|
87
|
+
it "reports failure message correctly when executed times is three" do
|
88
|
+
@verifier.times_executed = 3
|
89
|
+
@verifier.at_most_times_executed = 2
|
90
|
+
expected_text = "The request www.example.com was expected to execute at most 2 times but it executed 3 times"
|
91
|
+
expected_text += @executed_requests_info
|
92
|
+
expect(@verifier.failure_message).to eq(expected_text)
|
93
|
+
end
|
94
|
+
|
95
|
+
it "reports failure message correctly when executed times is two" do
|
96
|
+
@verifier.times_executed = 2
|
97
|
+
@verifier.at_most_times_executed = 1
|
98
|
+
expected_text = "The request www.example.com was expected to execute at most 1 time but it executed 2 times"
|
99
|
+
expected_text += @executed_requests_info
|
100
|
+
expect(@verifier.failure_message).to eq(expected_text)
|
101
|
+
end
|
102
|
+
end
|
31
103
|
end
|
32
104
|
|
33
105
|
describe "negative failure message" do
|
34
106
|
|
35
|
-
it "
|
107
|
+
it "reports failure message if it executed number of times specified" do
|
36
108
|
@verifier.times_executed = 2
|
37
109
|
@verifier.expected_times_executed = 2
|
38
110
|
expected_text = "The request www.example.com was not expected to execute 2 times but it executed 2 times"
|
39
|
-
expected_text
|
40
|
-
@verifier.
|
111
|
+
expected_text += @executed_requests_info
|
112
|
+
expect(@verifier.failure_message_when_negated).to eq(expected_text)
|
41
113
|
end
|
42
114
|
|
43
|
-
it "
|
115
|
+
it "reports failure message when not expected request but it executed" do
|
44
116
|
@verifier.times_executed = 1
|
45
|
-
expected_text = "The request www.example.com was expected to execute
|
46
|
-
expected_text
|
47
|
-
@verifier.
|
117
|
+
expected_text = "The request www.example.com was not expected to execute but it executed 1 time"
|
118
|
+
expected_text += @executed_requests_info
|
119
|
+
expect(@verifier.failure_message_when_negated).to eq(expected_text)
|
120
|
+
end
|
121
|
+
|
122
|
+
context "at_least_times_executed is set" do
|
123
|
+
it "reports failure message correctly when executed times is one" do
|
124
|
+
@verifier.times_executed = 3
|
125
|
+
@verifier.at_least_times_executed = 2
|
126
|
+
expected_text = "The request www.example.com was not expected to execute at least 2 times but it executed 3 times"
|
127
|
+
expected_text += @executed_requests_info
|
128
|
+
expect(@verifier.failure_message_when_negated).to eq(expected_text)
|
129
|
+
end
|
130
|
+
|
131
|
+
it "reports failure message correctly when executed times is two" do
|
132
|
+
@verifier.times_executed = 2
|
133
|
+
@verifier.at_least_times_executed = 2
|
134
|
+
expected_text = "The request www.example.com was not expected to execute at least 2 times but it executed 2 times"
|
135
|
+
expected_text += @executed_requests_info
|
136
|
+
expect(@verifier.failure_message_when_negated).to eq(expected_text)
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
context "at_most_times_executed is set" do
|
141
|
+
it "reports failure message correctly when executed times is three" do
|
142
|
+
@verifier.times_executed = 2
|
143
|
+
@verifier.at_most_times_executed = 3
|
144
|
+
expected_text = "The request www.example.com was not expected to execute at most 3 times but it executed 2 times"
|
145
|
+
expected_text += @executed_requests_info
|
146
|
+
expect(@verifier.failure_message_when_negated).to eq(expected_text)
|
147
|
+
end
|
148
|
+
|
149
|
+
it "reports failure message correctly when executed times is one" do
|
150
|
+
@verifier.times_executed = 1
|
151
|
+
@verifier.at_most_times_executed = 2
|
152
|
+
expected_text = "The request www.example.com was not expected to execute at most 2 times but it executed 1 time"
|
153
|
+
expected_text += @executed_requests_info
|
154
|
+
expect(@verifier.failure_message_when_negated).to eq(expected_text)
|
155
|
+
end
|
48
156
|
end
|
49
157
|
|
50
158
|
end
|
51
159
|
|
52
160
|
describe "matches?" do
|
53
161
|
|
54
|
-
it "
|
55
|
-
WebMock::RequestRegistry.instance.
|
56
|
-
|
162
|
+
it "succeeds if request was executed expected number of times" do
|
163
|
+
expect(WebMock::RequestRegistry.instance).
|
164
|
+
to receive(:times_executed).with(@request_pattern).and_return(10)
|
57
165
|
@verifier.expected_times_executed = 10
|
58
|
-
@verifier.matches
|
166
|
+
expect(@verifier.matches?).to be_truthy
|
59
167
|
end
|
60
168
|
|
61
|
-
it "
|
62
|
-
WebMock::RequestRegistry.instance.
|
63
|
-
|
169
|
+
it "fails if request was not executed expected number of times" do
|
170
|
+
expect(WebMock::RequestRegistry.instance).
|
171
|
+
to receive(:times_executed).with(@request_pattern).and_return(10)
|
64
172
|
@verifier.expected_times_executed = 5
|
65
|
-
@verifier.matches
|
173
|
+
expect(@verifier.matches?).to be_falsey
|
66
174
|
end
|
67
175
|
|
68
176
|
end
|
69
177
|
|
70
178
|
describe "does_not_match?" do
|
71
179
|
|
72
|
-
it "
|
73
|
-
WebMock::RequestRegistry.instance.
|
74
|
-
|
180
|
+
it "fails if request executed expected number of times" do
|
181
|
+
expect(WebMock::RequestRegistry.instance).
|
182
|
+
to receive(:times_executed).with(@request_pattern).and_return(10)
|
75
183
|
@verifier.expected_times_executed = 10
|
76
|
-
@verifier.does_not_match
|
184
|
+
expect(@verifier.does_not_match?).to be_falsey
|
77
185
|
end
|
78
186
|
|
79
|
-
it "
|
80
|
-
WebMock::RequestRegistry.instance.
|
81
|
-
|
82
|
-
@verifier.does_not_match
|
187
|
+
it "succeeds if request was not executed at all and expected number of times was not set" do
|
188
|
+
expect(WebMock::RequestRegistry.instance).
|
189
|
+
to receive(:times_executed).with(@request_pattern).and_return(0)
|
190
|
+
expect(@verifier.does_not_match?).to be_truthy
|
83
191
|
end
|
84
192
|
|
85
|
-
it "
|
86
|
-
WebMock::RequestRegistry.instance.
|
87
|
-
|
88
|
-
@verifier.does_not_match
|
193
|
+
it "fails if request was executed and expected number of times was not set" do
|
194
|
+
expect(WebMock::RequestRegistry.instance).
|
195
|
+
to receive(:times_executed).with(@request_pattern).and_return(1)
|
196
|
+
expect(@verifier.does_not_match?).to be_falsey
|
89
197
|
end
|
90
198
|
|
91
|
-
it "
|
92
|
-
WebMock::RequestRegistry.instance.
|
93
|
-
|
199
|
+
it "succeeds if request was not executed expected number of times" do
|
200
|
+
expect(WebMock::RequestRegistry.instance).
|
201
|
+
to receive(:times_executed).with(@request_pattern).and_return(10)
|
94
202
|
@verifier.expected_times_executed = 5
|
95
|
-
@verifier.does_not_match
|
203
|
+
expect(@verifier.does_not_match?).to be_truthy
|
96
204
|
end
|
97
205
|
|
98
206
|
end
|