webmock 1.8.6 → 3.14.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.
Files changed (138) hide show
  1. checksums.yaml +7 -0
  2. data/.github/workflows/CI.yml +37 -0
  3. data/.gitignore +6 -0
  4. data/CHANGELOG.md +1198 -0
  5. data/Gemfile +3 -15
  6. data/README.md +761 -305
  7. data/Rakefile +13 -40
  8. data/lib/webmock/api.rb +63 -17
  9. data/lib/webmock/callback_registry.rb +1 -1
  10. data/lib/webmock/config.rb +8 -0
  11. data/lib/webmock/cucumber.rb +2 -0
  12. data/lib/webmock/errors.rb +8 -24
  13. data/lib/webmock/http_lib_adapters/async_http_client_adapter.rb +216 -0
  14. data/lib/webmock/http_lib_adapters/curb_adapter.rb +148 -84
  15. data/lib/webmock/http_lib_adapters/em_http_request_adapter.rb +224 -4
  16. data/lib/webmock/http_lib_adapters/excon_adapter.rb +104 -34
  17. data/lib/webmock/http_lib_adapters/http_rb/client.rb +17 -0
  18. data/lib/webmock/http_lib_adapters/http_rb/request.rb +16 -0
  19. data/lib/webmock/http_lib_adapters/http_rb/response.rb +64 -0
  20. data/lib/webmock/http_lib_adapters/http_rb/streamer.rb +29 -0
  21. data/lib/webmock/http_lib_adapters/http_rb/webmock.rb +68 -0
  22. data/lib/webmock/http_lib_adapters/http_rb_adapter.rb +37 -0
  23. data/lib/webmock/http_lib_adapters/httpclient_adapter.rb +152 -86
  24. data/lib/webmock/http_lib_adapters/manticore_adapter.rb +145 -0
  25. data/lib/webmock/http_lib_adapters/net_http.rb +155 -46
  26. data/lib/webmock/http_lib_adapters/net_http_response.rb +1 -1
  27. data/lib/webmock/http_lib_adapters/patron_adapter.rb +16 -15
  28. data/lib/webmock/http_lib_adapters/typhoeus_hydra_adapter.rb +76 -82
  29. data/lib/webmock/matchers/any_arg_matcher.rb +13 -0
  30. data/lib/webmock/matchers/hash_argument_matcher.rb +21 -0
  31. data/lib/webmock/matchers/hash_excluding_matcher.rb +15 -0
  32. data/lib/webmock/matchers/hash_including_matcher.rb +4 -12
  33. data/lib/webmock/minitest.rb +29 -3
  34. data/lib/webmock/rack_response.rb +14 -7
  35. data/lib/webmock/request_body_diff.rb +64 -0
  36. data/lib/webmock/request_execution_verifier.rb +38 -17
  37. data/lib/webmock/request_pattern.rb +158 -38
  38. data/lib/webmock/request_registry.rb +3 -3
  39. data/lib/webmock/request_signature.rb +7 -3
  40. data/lib/webmock/request_signature_snippet.rb +61 -0
  41. data/lib/webmock/request_stub.rb +9 -6
  42. data/lib/webmock/response.rb +30 -15
  43. data/lib/webmock/rspec/matchers/request_pattern_matcher.rb +38 -2
  44. data/lib/webmock/rspec/matchers/webmock_matcher.rb +23 -2
  45. data/lib/webmock/rspec/matchers.rb +0 -1
  46. data/lib/webmock/rspec.rb +11 -2
  47. data/lib/webmock/stub_registry.rb +31 -10
  48. data/lib/webmock/stub_request_snippet.rb +14 -6
  49. data/lib/webmock/test_unit.rb +4 -4
  50. data/lib/webmock/util/hash_counter.rb +20 -6
  51. data/lib/webmock/util/hash_keys_stringifier.rb +5 -3
  52. data/lib/webmock/util/hash_validator.rb +17 -0
  53. data/lib/webmock/util/headers.rb +23 -2
  54. data/lib/webmock/util/json.rb +20 -7
  55. data/lib/webmock/util/query_mapper.rb +281 -0
  56. data/lib/webmock/util/uri.rb +29 -19
  57. data/lib/webmock/util/values_stringifier.rb +20 -0
  58. data/lib/webmock/util/version_checker.rb +40 -2
  59. data/lib/webmock/version.rb +1 -1
  60. data/lib/webmock/webmock.rb +56 -17
  61. data/lib/webmock.rb +56 -46
  62. data/minitest/test_helper.rb +8 -3
  63. data/minitest/test_webmock.rb +4 -1
  64. data/minitest/webmock_spec.rb +16 -6
  65. data/spec/acceptance/async_http_client/async_http_client_spec.rb +375 -0
  66. data/spec/acceptance/async_http_client/async_http_client_spec_helper.rb +73 -0
  67. data/spec/acceptance/curb/curb_spec.rb +227 -68
  68. data/spec/acceptance/curb/curb_spec_helper.rb +11 -8
  69. data/spec/acceptance/em_http_request/em_http_request_spec.rb +322 -28
  70. data/spec/acceptance/em_http_request/em_http_request_spec_helper.rb +15 -10
  71. data/spec/acceptance/excon/excon_spec.rb +66 -4
  72. data/spec/acceptance/excon/excon_spec_helper.rb +21 -7
  73. data/spec/acceptance/http_rb/http_rb_spec.rb +93 -0
  74. data/spec/acceptance/http_rb/http_rb_spec_helper.rb +54 -0
  75. data/spec/acceptance/httpclient/httpclient_spec.rb +152 -11
  76. data/spec/acceptance/httpclient/httpclient_spec_helper.rb +25 -16
  77. data/spec/acceptance/manticore/manticore_spec.rb +107 -0
  78. data/spec/acceptance/manticore/manticore_spec_helper.rb +35 -0
  79. data/spec/acceptance/net_http/net_http_shared.rb +52 -24
  80. data/spec/acceptance/net_http/net_http_spec.rb +164 -50
  81. data/spec/acceptance/net_http/net_http_spec_helper.rb +19 -10
  82. data/spec/acceptance/net_http/real_net_http_spec.rb +1 -1
  83. data/spec/acceptance/patron/patron_spec.rb +29 -40
  84. data/spec/acceptance/patron/patron_spec_helper.rb +15 -11
  85. data/spec/acceptance/shared/allowing_and_disabling_net_connect.rb +229 -58
  86. data/spec/acceptance/shared/callbacks.rb +32 -30
  87. data/spec/acceptance/shared/complex_cross_concern_behaviors.rb +20 -5
  88. data/spec/acceptance/shared/enabling_and_disabling_webmock.rb +14 -14
  89. data/spec/acceptance/shared/precedence_of_stubs.rb +6 -6
  90. data/spec/acceptance/shared/request_expectations.rb +560 -296
  91. data/spec/acceptance/shared/returning_declared_responses.rb +180 -138
  92. data/spec/acceptance/shared/stubbing_requests.rb +385 -154
  93. data/spec/acceptance/typhoeus/typhoeus_hydra_spec.rb +78 -17
  94. data/spec/acceptance/typhoeus/typhoeus_hydra_spec_helper.rb +19 -15
  95. data/spec/acceptance/webmock_shared.rb +2 -2
  96. data/spec/fixtures/test.txt +1 -0
  97. data/spec/quality_spec.rb +27 -3
  98. data/spec/spec_helper.rb +11 -20
  99. data/spec/support/failures.rb +9 -0
  100. data/spec/support/my_rack_app.rb +8 -3
  101. data/spec/support/network_connection.rb +7 -13
  102. data/spec/support/webmock_server.rb +8 -3
  103. data/spec/unit/api_spec.rb +175 -0
  104. data/spec/unit/errors_spec.rb +116 -19
  105. data/spec/unit/http_lib_adapters/http_lib_adapter_registry_spec.rb +1 -1
  106. data/spec/unit/http_lib_adapters/http_lib_adapter_spec.rb +2 -2
  107. data/spec/unit/matchers/hash_excluding_matcher_spec.rb +61 -0
  108. data/spec/unit/matchers/hash_including_matcher_spec.rb +87 -0
  109. data/spec/unit/rack_response_spec.rb +54 -16
  110. data/spec/unit/request_body_diff_spec.rb +90 -0
  111. data/spec/unit/request_execution_verifier_spec.rb +147 -39
  112. data/spec/unit/request_pattern_spec.rb +462 -198
  113. data/spec/unit/request_registry_spec.rb +29 -9
  114. data/spec/unit/request_signature_snippet_spec.rb +89 -0
  115. data/spec/unit/request_signature_spec.rb +91 -49
  116. data/spec/unit/request_stub_spec.rb +71 -70
  117. data/spec/unit/response_spec.rb +100 -81
  118. data/spec/unit/stub_registry_spec.rb +37 -20
  119. data/spec/unit/stub_request_snippet_spec.rb +51 -31
  120. data/spec/unit/util/hash_counter_spec.rb +6 -6
  121. data/spec/unit/util/hash_keys_stringifier_spec.rb +4 -4
  122. data/spec/unit/util/headers_spec.rb +4 -4
  123. data/spec/unit/util/json_spec.rb +29 -3
  124. data/spec/unit/util/query_mapper_spec.rb +157 -0
  125. data/spec/unit/util/uri_spec.rb +150 -36
  126. data/spec/unit/util/version_checker_spec.rb +15 -9
  127. data/spec/unit/webmock_spec.rb +57 -4
  128. data/test/http_request.rb +3 -3
  129. data/test/shared_test.rb +45 -13
  130. data/test/test_helper.rb +1 -1
  131. data/test/test_webmock.rb +6 -0
  132. data/webmock.gemspec +30 -11
  133. metadata +308 -199
  134. data/.rvmrc +0 -1
  135. data/.travis.yml +0 -11
  136. data/Guardfile +0 -24
  137. data/lib/webmock/http_lib_adapters/em_http_request/em_http_request_0_x.rb +0 -151
  138. 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 = mock(WebMock::RequestPattern, :to_s => "www.example.com")
6
+ @request_pattern = double(WebMock::RequestPattern, to_s: "www.example.com")
7
7
  @verifier.request_pattern = @request_pattern
8
- WebMock::RequestRegistry.instance.stub(:to_s).and_return("executed requests")
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 "should report failure message" do
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 << @executed_requests_info
20
- @verifier.failure_message.should == expected_text
56
+ expected_text += @executed_requests_info
57
+ expect(@verifier.failure_message).to eq(expected_text)
21
58
  end
22
59
 
23
- it "should report failure message correctly when executed times is one" do
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 << @executed_requests_info
28
- @verifier.failure_message.should == expected_text
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 "should report failure message if it executed number of times specified" do
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 << @executed_requests_info
40
- @verifier.negative_failure_message.should == expected_text
111
+ expected_text += @executed_requests_info
112
+ expect(@verifier.failure_message_when_negated).to eq(expected_text)
41
113
  end
42
114
 
43
- it "should report failure message when not expected request but it executed" do
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 0 times but it executed 1 time"
46
- expected_text << @executed_requests_info
47
- @verifier.negative_failure_message.should == expected_text
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 "should succeed if request was executed expected number of times" do
55
- WebMock::RequestRegistry.instance.
56
- should_receive(:times_executed).with(@request_pattern).and_return(10)
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?.should be_true
166
+ expect(@verifier.matches?).to be_truthy
59
167
  end
60
168
 
61
- it "should fail if request was not executed expected number of times" do
62
- WebMock::RequestRegistry.instance.
63
- should_receive(:times_executed).with(@request_pattern).and_return(10)
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?.should be_false
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 "should fail if request executed expected number of times" do
73
- WebMock::RequestRegistry.instance.
74
- should_receive(:times_executed).with(@request_pattern).and_return(10)
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?.should be_false
184
+ expect(@verifier.does_not_match?).to be_falsey
77
185
  end
78
186
 
79
- it "should succeed if request was not executed at all and expected number of times was not set" do
80
- WebMock::RequestRegistry.instance.
81
- should_receive(:times_executed).with(@request_pattern).and_return(0)
82
- @verifier.does_not_match?.should be_true
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 "should fail if request was executed and expected number of times was not set" do
86
- WebMock::RequestRegistry.instance.
87
- should_receive(:times_executed).with(@request_pattern).and_return(1)
88
- @verifier.does_not_match?.should be_false
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 "should succeed if request was not executed expected number of times" do
92
- WebMock::RequestRegistry.instance.
93
- should_receive(:times_executed).with(@request_pattern).and_return(10)
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?.should be_true
203
+ expect(@verifier.does_not_match?).to be_truthy
96
204
  end
97
205
 
98
206
  end