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.
- 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
@@ -11,9 +11,9 @@ unless RUBY_PLATFORM =~ /java/
|
|
11
11
|
|
12
12
|
describe "when doing PUTs" do
|
13
13
|
it "should stub them" do
|
14
|
-
stub_request(:put, "www.example.com").with(:
|
15
|
-
http_request(:put, "http://www.example.com", :
|
16
|
-
status.
|
14
|
+
stub_request(:put, "www.example.com").with(body: "01234")
|
15
|
+
expect(http_request(:put, "http://www.example.com", body: "01234").
|
16
|
+
status).to eq("200")
|
17
17
|
end
|
18
18
|
end
|
19
19
|
end
|
@@ -30,98 +30,132 @@ unless RUBY_PLATFORM =~ /java/
|
|
30
30
|
@curl.url = "http://example.com"
|
31
31
|
end
|
32
32
|
|
33
|
+
describe 'on_debug' do
|
34
|
+
it "should call on_debug" do
|
35
|
+
stub_request(:any, "example.com").
|
36
|
+
to_return(status: 200, headers: { 'Server' => 'nginx' }, body: { hello: :world }.to_json)
|
37
|
+
|
38
|
+
test = []
|
39
|
+
|
40
|
+
@curl.on_debug do |message, operation|
|
41
|
+
test << "#{operation} -> #{message}"
|
42
|
+
end
|
43
|
+
@curl.headers['Content-Type'] = 'application/json'
|
44
|
+
@curl.http_post({ hello: :world }.to_json)
|
45
|
+
|
46
|
+
expect(test).to_not be_empty
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
33
50
|
it "should call on_success with 2xx response" do
|
34
51
|
body = "on_success fired"
|
35
|
-
stub_request(:any, "example.com").to_return(:
|
52
|
+
stub_request(:any, "example.com").to_return(body: body)
|
36
53
|
|
37
54
|
test = nil
|
38
55
|
@curl.on_success do |c|
|
39
56
|
test = c.body_str
|
40
57
|
end
|
41
58
|
@curl.http_get
|
42
|
-
test.
|
59
|
+
expect(test).to eq(body)
|
43
60
|
end
|
44
61
|
|
45
|
-
it "should call
|
62
|
+
it "should call on_missing with 4xx response" do
|
46
63
|
response_code = 403
|
47
64
|
stub_request(:any, "example.com").
|
48
|
-
to_return(:
|
65
|
+
to_return(status: [response_code, "None shall pass"])
|
49
66
|
|
50
67
|
test = nil
|
51
|
-
@curl.
|
68
|
+
@curl.on_missing do |c, code|
|
52
69
|
test = code
|
53
70
|
end
|
54
71
|
@curl.http_get
|
55
|
-
test.
|
72
|
+
expect(test).to eq(response_code)
|
56
73
|
end
|
57
74
|
|
58
75
|
it "should call on_failure with 5xx response" do
|
59
76
|
response_code = 599
|
60
77
|
stub_request(:any, "example.com").
|
61
|
-
to_return(:
|
78
|
+
to_return(status: [response_code, "Server On Fire"])
|
62
79
|
|
63
80
|
test = nil
|
64
81
|
@curl.on_failure do |c, code|
|
65
82
|
test = code
|
66
83
|
end
|
67
84
|
@curl.http_get
|
68
|
-
test.
|
85
|
+
expect(test).to eq(response_code)
|
69
86
|
end
|
70
87
|
|
71
88
|
it "should call on_body when response body is read" do
|
72
89
|
body = "on_body fired"
|
73
90
|
stub_request(:any, "example.com").
|
74
|
-
to_return(:
|
91
|
+
to_return(body: body)
|
75
92
|
|
76
93
|
test = nil
|
77
94
|
@curl.on_body do |data|
|
78
95
|
test = data
|
79
96
|
end
|
80
97
|
@curl.http_get
|
81
|
-
test.
|
98
|
+
expect(test).to eq(body)
|
99
|
+
end
|
100
|
+
|
101
|
+
it "should call on_body for each chunk with chunked response" do
|
102
|
+
stub_request(:any, "example.com").
|
103
|
+
to_return(body: ["first_chunk", "second_chunk"],
|
104
|
+
headers: {"Transfer-Encoding" => "chunked"})
|
105
|
+
|
106
|
+
test = []
|
107
|
+
@curl.on_body do |data|
|
108
|
+
test << data
|
109
|
+
end
|
110
|
+
@curl.http_get
|
111
|
+
expect(test).to eq(["first_chunk", "second_chunk"])
|
82
112
|
end
|
83
113
|
|
84
114
|
it "should call on_header when response headers are read" do
|
85
115
|
stub_request(:any, "example.com").
|
86
|
-
to_return(:
|
116
|
+
to_return(headers: {one: 1})
|
87
117
|
|
88
|
-
test =
|
118
|
+
test = []
|
89
119
|
@curl.on_header do |data|
|
90
|
-
test
|
120
|
+
test << data
|
91
121
|
end
|
92
122
|
@curl.http_get
|
93
|
-
test.
|
123
|
+
expect(test).to eq([
|
124
|
+
"HTTP/1.1 200 \r\n",
|
125
|
+
'One: 1'
|
126
|
+
])
|
94
127
|
end
|
95
128
|
|
96
129
|
it "should call on_complete when request is complete" do
|
97
130
|
body = "on_complete fired"
|
98
|
-
stub_request(:any, "example.com").to_return(:
|
131
|
+
stub_request(:any, "example.com").to_return(body: body)
|
99
132
|
|
100
133
|
test = nil
|
101
134
|
@curl.on_complete do |curl|
|
102
135
|
test = curl.body_str
|
103
136
|
end
|
104
137
|
@curl.http_get
|
105
|
-
test.
|
138
|
+
expect(test).to eq(body)
|
106
139
|
end
|
107
140
|
|
108
141
|
it "should call on_progress when portion of response body is read" do
|
109
|
-
stub_request(:any, "example.com").to_return(:
|
142
|
+
stub_request(:any, "example.com").to_return(body: "01234")
|
110
143
|
|
111
144
|
test = nil
|
112
145
|
@curl.on_progress do |*args|
|
113
|
-
args.length.
|
114
|
-
args.each {|arg| arg.is_a?(Float).
|
146
|
+
expect(args.length).to eq(4)
|
147
|
+
args.each {|arg| expect(arg.is_a?(Float)).to eq(true) }
|
115
148
|
test = true
|
116
149
|
end
|
117
150
|
@curl.http_get
|
118
|
-
test.
|
151
|
+
expect(test).to eq(true)
|
119
152
|
end
|
120
153
|
|
121
154
|
it "should call callbacks in correct order on successful request" do
|
122
155
|
stub_request(:any, "example.com")
|
123
156
|
order = []
|
124
157
|
@curl.on_success {|*args| order << :on_success }
|
158
|
+
@curl.on_missing {|*args| order << :on_missing }
|
125
159
|
@curl.on_failure {|*args| order << :on_failure }
|
126
160
|
@curl.on_header {|*args| order << :on_header }
|
127
161
|
@curl.on_body {|*args| order << :on_body }
|
@@ -129,13 +163,29 @@ unless RUBY_PLATFORM =~ /java/
|
|
129
163
|
@curl.on_progress {|*args| order << :on_progress }
|
130
164
|
@curl.http_get
|
131
165
|
|
132
|
-
order.
|
166
|
+
expect(order).to eq([:on_progress,:on_header,:on_body,:on_complete,:on_success])
|
133
167
|
end
|
134
168
|
|
135
169
|
it "should call callbacks in correct order on failed request" do
|
136
|
-
stub_request(:any, "example.com").to_return(:
|
170
|
+
stub_request(:any, "example.com").to_return(status: [500, ""])
|
171
|
+
order = []
|
172
|
+
@curl.on_success {|*args| order << :on_success }
|
173
|
+
@curl.on_missing {|*args| order << :on_missing }
|
174
|
+
@curl.on_failure {|*args| order << :on_failure }
|
175
|
+
@curl.on_header {|*args| order << :on_header }
|
176
|
+
@curl.on_body {|*args| order << :on_body }
|
177
|
+
@curl.on_complete {|*args| order << :on_complete }
|
178
|
+
@curl.on_progress {|*args| order << :on_progress }
|
179
|
+
@curl.http_get
|
180
|
+
|
181
|
+
expect(order).to eq([:on_progress,:on_header,:on_body,:on_complete,:on_failure])
|
182
|
+
end
|
183
|
+
|
184
|
+
it "should call callbacks in correct order on missing request" do
|
185
|
+
stub_request(:any, "example.com").to_return(status: [403, ""])
|
137
186
|
order = []
|
138
187
|
@curl.on_success {|*args| order << :on_success }
|
188
|
+
@curl.on_missing {|*args| order << :on_missing }
|
139
189
|
@curl.on_failure {|*args| order << :on_failure }
|
140
190
|
@curl.on_header {|*args| order << :on_header }
|
141
191
|
@curl.on_body {|*args| order << :on_body }
|
@@ -143,7 +193,7 @@ unless RUBY_PLATFORM =~ /java/
|
|
143
193
|
@curl.on_progress {|*args| order << :on_progress }
|
144
194
|
@curl.http_get
|
145
195
|
|
146
|
-
order.
|
196
|
+
expect(order).to eq([:on_progress,:on_header,:on_body,:on_complete,:on_missing])
|
147
197
|
end
|
148
198
|
end
|
149
199
|
|
@@ -158,12 +208,12 @@ unless RUBY_PLATFORM =~ /java/
|
|
158
208
|
|
159
209
|
it 'should be the same as #url even with a location header' do
|
160
210
|
stub_request(:any, 'example.com').
|
161
|
-
to_return(:
|
162
|
-
:
|
163
|
-
:
|
211
|
+
to_return(body: "abc",
|
212
|
+
status: 302,
|
213
|
+
headers: { 'Location' => 'http://www.example.com' })
|
164
214
|
|
165
215
|
@curl.http_get
|
166
|
-
@curl.last_effective_url.
|
216
|
+
expect(@curl.last_effective_url).to eq('http://example.com')
|
167
217
|
end
|
168
218
|
end
|
169
219
|
|
@@ -173,60 +223,60 @@ unless RUBY_PLATFORM =~ /java/
|
|
173
223
|
it 'should be the same as #url when no location header is present' do
|
174
224
|
stub_request(:any, "example.com")
|
175
225
|
@curl.http_get
|
176
|
-
@curl.last_effective_url.
|
226
|
+
expect(@curl.last_effective_url).to eq('http://example.com')
|
177
227
|
end
|
178
228
|
|
179
229
|
it 'should be the value of the location header when present' do
|
180
230
|
stub_request(:any, 'example.com').
|
181
|
-
to_return(:
|
231
|
+
to_return(headers: { 'Location' => 'http://www.example.com' })
|
182
232
|
stub_request(:any, 'www.example.com')
|
183
233
|
|
184
234
|
@curl.http_get
|
185
|
-
@curl.last_effective_url.
|
235
|
+
expect(@curl.last_effective_url).to eq('http://www.example.com')
|
186
236
|
end
|
187
237
|
|
188
238
|
it 'should work with more than one redirect' do
|
189
239
|
stub_request(:any, 'example.com').
|
190
|
-
to_return(:
|
240
|
+
to_return(headers: { 'Location' => 'http://www.example.com' })
|
191
241
|
stub_request(:any, 'www.example.com').
|
192
|
-
to_return(:
|
242
|
+
to_return(headers: { 'Location' => 'http://blog.example.com' })
|
193
243
|
stub_request(:any, 'blog.example.com')
|
194
244
|
|
195
245
|
@curl.http_get
|
196
|
-
@curl.last_effective_url.
|
246
|
+
expect(@curl.last_effective_url).to eq('http://blog.example.com')
|
197
247
|
end
|
198
248
|
|
199
249
|
it 'should maintain the original url' do
|
200
250
|
stub_request(:any, 'example.com').
|
201
|
-
to_return(:
|
251
|
+
to_return(headers: { 'Location' => 'http://www.example.com' })
|
202
252
|
stub_request(:any, 'www.example.com')
|
203
253
|
|
204
254
|
@curl.http_get
|
205
|
-
@curl.url.
|
255
|
+
expect(@curl.url).to eq('http://example.com')
|
206
256
|
end
|
207
257
|
|
208
258
|
it 'should have the redirected-to attrs (body, response code)' do
|
209
259
|
stub_request(:any, 'example.com').
|
210
|
-
to_return(:
|
211
|
-
:
|
212
|
-
:
|
213
|
-
stub_request(:any, 'www.example.com').to_return(:
|
260
|
+
to_return(body: 'request A',
|
261
|
+
status: 302,
|
262
|
+
headers: { 'Location' => 'http://www.example.com' })
|
263
|
+
stub_request(:any, 'www.example.com').to_return(body: 'request B')
|
214
264
|
|
215
265
|
@curl.http_get
|
216
|
-
@curl.body_str.
|
217
|
-
@curl.response_code.
|
266
|
+
expect(@curl.body_str).to eq('request B')
|
267
|
+
expect(@curl.response_code).to eq(200)
|
218
268
|
end
|
219
269
|
|
220
270
|
it 'should follow more than one redirect' do
|
221
271
|
stub_request(:any, 'example.com').
|
222
|
-
to_return(:
|
272
|
+
to_return(headers: { 'Location' => 'http://www.example.com' })
|
223
273
|
stub_request(:any, 'www.example.com').
|
224
|
-
to_return(:
|
225
|
-
stub_request(:any, 'blog.example.com').to_return(:
|
274
|
+
to_return(headers: { 'Location' => 'http://blog.example.com' })
|
275
|
+
stub_request(:any, 'blog.example.com').to_return(body: 'blog post')
|
226
276
|
|
227
277
|
@curl.http_get
|
228
|
-
@curl.url.
|
229
|
-
@curl.body_str.
|
278
|
+
expect(@curl.url).to eq('http://example.com')
|
279
|
+
expect(@curl.body_str).to eq('blog post')
|
230
280
|
end
|
231
281
|
end
|
232
282
|
end
|
@@ -242,28 +292,62 @@ unless RUBY_PLATFORM =~ /java/
|
|
242
292
|
content_type = "application/json"
|
243
293
|
|
244
294
|
stub_request(:any, 'example.com').
|
245
|
-
to_return(:
|
246
|
-
:
|
247
|
-
:
|
295
|
+
to_return(body: "abc",
|
296
|
+
status: 200,
|
297
|
+
headers: { 'Content-Type' => content_type })
|
248
298
|
|
249
299
|
@curl.http_get
|
250
|
-
@curl.content_type.
|
300
|
+
expect(@curl.content_type).to eq(content_type)
|
251
301
|
end
|
252
302
|
end
|
253
303
|
|
254
304
|
context "when response does not include Content-Type header" do
|
255
305
|
it "returns nil for content_type" do
|
256
|
-
content_type = "application/json"
|
257
306
|
|
258
307
|
stub_request(:any, 'example.com').
|
259
|
-
to_return(:
|
260
|
-
:
|
308
|
+
to_return(body: "abc",
|
309
|
+
status: 200 )
|
261
310
|
|
262
311
|
@curl.http_get
|
263
|
-
@curl.content_type.
|
312
|
+
expect(@curl.content_type).to be_nil
|
264
313
|
end
|
265
314
|
end
|
266
315
|
end
|
316
|
+
|
317
|
+
describe "#chunked_response?" do
|
318
|
+
before(:each) do
|
319
|
+
@curl = Curl::Easy.new
|
320
|
+
@curl.url = "http://example.com"
|
321
|
+
end
|
322
|
+
|
323
|
+
it "is true when Transfer-Encoding is 'chunked' and body responds to each" do
|
324
|
+
stub_request(:any, 'example.com').
|
325
|
+
to_return(body: ["abc", "def"],
|
326
|
+
status: 200,
|
327
|
+
headers: { 'Transfer-Encoding' => 'chunked' })
|
328
|
+
|
329
|
+
@curl.http_get
|
330
|
+
expect(@curl).to be_chunked_response
|
331
|
+
end
|
332
|
+
|
333
|
+
it "is false when Transfer-Encoding is not 'chunked'" do
|
334
|
+
stub_request(:any, 'example.com').
|
335
|
+
to_return(body: ["abc", "def"],
|
336
|
+
status: 200)
|
337
|
+
|
338
|
+
@curl.http_get
|
339
|
+
expect(@curl).not_to be_chunked_response
|
340
|
+
end
|
341
|
+
|
342
|
+
it "is false when Transfer-Encoding is 'chunked' but body does not respond to each" do
|
343
|
+
stub_request(:any, 'example.com').
|
344
|
+
to_return(body: "abc",
|
345
|
+
status: 200)
|
346
|
+
|
347
|
+
@curl.http_get
|
348
|
+
expect(@curl).not_to be_chunked_response
|
349
|
+
end
|
350
|
+
end
|
267
351
|
end
|
268
352
|
|
269
353
|
describe "Webmock with Curb" do
|
@@ -272,12 +356,54 @@ unless RUBY_PLATFORM =~ /java/
|
|
272
356
|
include CurbSpecHelper::DynamicHttp
|
273
357
|
|
274
358
|
it "should work with uppercase arguments" do
|
275
|
-
stub_request(:get, "www.example.com").to_return(:
|
359
|
+
stub_request(:get, "www.example.com").to_return(body: "abc")
|
276
360
|
|
277
361
|
c = Curl::Easy.new
|
278
362
|
c.url = "http://www.example.com"
|
279
363
|
c.http(:GET)
|
280
|
-
c.body_str.
|
364
|
+
expect(c.body_str).to eq("abc")
|
365
|
+
end
|
366
|
+
|
367
|
+
it "should alias body to body_str" do
|
368
|
+
stub_request(:get, "www.example.com").to_return(body: "abc")
|
369
|
+
|
370
|
+
c = Curl::Easy.new
|
371
|
+
c.url = "http://www.example.com"
|
372
|
+
c.http(:GET)
|
373
|
+
expect(c.body).to eq("abc")
|
374
|
+
end
|
375
|
+
|
376
|
+
it "supports array headers passed to Curl::Easy" do
|
377
|
+
stub_request(:get, "www.example.com").with(headers: {'X-One' => '1'}).to_return(body: "abc")
|
378
|
+
|
379
|
+
c = Curl::Easy.new
|
380
|
+
c.url = "http://www.example.com"
|
381
|
+
c.headers = ["X-One: 1"]
|
382
|
+
c.http(:GET)
|
383
|
+
expect(c.body).to eq("abc")
|
384
|
+
end
|
385
|
+
|
386
|
+
describe 'match request body' do
|
387
|
+
it 'for post' do
|
388
|
+
stub_request(:post, "www.example.com").with(body: 'foo=nhe').to_return(body: "abc")
|
389
|
+
|
390
|
+
response = Curl.post("http://www.example.com", {foo: :nhe})
|
391
|
+
expect(response.body_str).to eq("abc")
|
392
|
+
end
|
393
|
+
|
394
|
+
it 'for patch' do
|
395
|
+
stub_request(:patch, "www.example.com").with(body: 'foo=nhe').to_return(body: "abc")
|
396
|
+
|
397
|
+
response = Curl.patch("http://www.example.com", {foo: :nhe})
|
398
|
+
expect(response.body_str).to eq("abc")
|
399
|
+
end
|
400
|
+
|
401
|
+
it 'for put' do
|
402
|
+
stub_request(:put, "www.example.com").with(body: 'foo=nhe').to_return(body: "abc")
|
403
|
+
|
404
|
+
response = Curl.put("http://www.example.com", {foo: :nhe})
|
405
|
+
expect(response.body_str).to eq("abc")
|
406
|
+
end
|
281
407
|
end
|
282
408
|
end
|
283
409
|
|
@@ -285,39 +411,50 @@ unless RUBY_PLATFORM =~ /java/
|
|
285
411
|
it_should_behave_like "Curb"
|
286
412
|
include CurbSpecHelper::NamedHttp
|
287
413
|
|
414
|
+
it "should reset @webmock_method after each call" do
|
415
|
+
stub_request(:post, "www.example.com").with(body: "01234")
|
416
|
+
c = Curl::Easy.new
|
417
|
+
c.url = "http://www.example.com"
|
418
|
+
c.post_body = "01234"
|
419
|
+
c.http_post
|
420
|
+
expect {
|
421
|
+
c.perform
|
422
|
+
}.to raise_error(WebMock::NetConnectNotAllowedError, %r(Real HTTP connections are disabled. Unregistered request: GET http://www.example.com))
|
423
|
+
end
|
424
|
+
|
288
425
|
it "should work with blank arguments for post" do
|
289
|
-
stub_request(:post, "www.example.com").with(:
|
426
|
+
stub_request(:post, "www.example.com").with(body: "01234")
|
290
427
|
c = Curl::Easy.new
|
291
428
|
c.url = "http://www.example.com"
|
292
429
|
c.post_body = "01234"
|
293
430
|
c.http_post
|
294
|
-
c.response_code.
|
431
|
+
expect(c.response_code).to eq(200)
|
295
432
|
end
|
296
433
|
|
297
434
|
it "should work with several body arguments for post using the class method" do
|
298
|
-
stub_request(:post, "www.example.com").with(:user
|
435
|
+
stub_request(:post, "www.example.com").with(body: {user: {first_name: 'Bartosz', last_name: 'Blimke'}})
|
299
436
|
c = Curl::Easy.http_post "http://www.example.com", 'user[first_name]=Bartosz', 'user[last_name]=Blimke'
|
300
|
-
c.response_code.
|
437
|
+
expect(c.response_code).to eq(200)
|
301
438
|
end
|
302
439
|
|
303
440
|
it "should work with blank arguments for put" do
|
304
|
-
stub_request(:put, "www.example.com").with(:
|
441
|
+
stub_request(:put, "www.example.com").with(body: "01234")
|
305
442
|
c = Curl::Easy.new
|
306
443
|
c.url = "http://www.example.com"
|
307
444
|
c.put_data = "01234"
|
308
445
|
c.http_put
|
309
|
-
c.response_code.
|
446
|
+
expect(c.response_code).to eq(200)
|
310
447
|
end
|
311
448
|
|
312
449
|
it "should work with multiple arguments for post" do
|
313
|
-
data = { :
|
450
|
+
data = { name: "john", address: "111 example ave" }
|
314
451
|
|
315
|
-
stub_request(:post, "www.example.com").with(:
|
452
|
+
stub_request(:post, "www.example.com").with(body: data)
|
316
453
|
c = Curl::Easy.new
|
317
454
|
c.url = "http://www.example.com"
|
318
455
|
c.http_post Curl::PostField.content('name', data[:name]), Curl::PostField.content('address', data[:address])
|
319
456
|
|
320
|
-
c.response_code.
|
457
|
+
expect(c.response_code).to eq(200)
|
321
458
|
end
|
322
459
|
|
323
460
|
end
|
@@ -336,5 +473,27 @@ unless RUBY_PLATFORM =~ /java/
|
|
336
473
|
it_should_behave_like "Curb"
|
337
474
|
include CurbSpecHelper::ClassPerform
|
338
475
|
end
|
476
|
+
|
477
|
+
describe "using #reset" do
|
478
|
+
before do
|
479
|
+
@curl = Curl::Easy.new
|
480
|
+
@curl.url = "http://example.com"
|
481
|
+
stub_request(:any, "example.com").
|
482
|
+
to_return(body: "abc",
|
483
|
+
headers: { "Content-Type" => "application/json" })
|
484
|
+
@curl.http_get
|
485
|
+
end
|
486
|
+
|
487
|
+
it "should clear all memoized response fields" do
|
488
|
+
@curl.reset
|
489
|
+
expect(@curl).to have_attributes(
|
490
|
+
body_str: nil,
|
491
|
+
content_type: nil,
|
492
|
+
header_str: nil,
|
493
|
+
last_effective_url: nil,
|
494
|
+
response_code: 0,
|
495
|
+
)
|
496
|
+
end
|
497
|
+
end
|
339
498
|
end
|
340
499
|
end
|
@@ -21,18 +21,21 @@ module CurbSpecHelper
|
|
21
21
|
end
|
22
22
|
|
23
23
|
OpenStruct.new(
|
24
|
-
:
|
25
|
-
:
|
26
|
-
:
|
27
|
-
:
|
24
|
+
body: curl.body_str,
|
25
|
+
headers: WebMock::Util::Headers.normalize_headers(response_headers),
|
26
|
+
status: curl.response_code.to_s,
|
27
|
+
message: status
|
28
28
|
)
|
29
29
|
end
|
30
30
|
|
31
31
|
def setup_request(uri, curl, options={})
|
32
32
|
curl ||= Curl::Easy.new
|
33
|
-
curl.url = uri.
|
34
|
-
|
35
|
-
|
33
|
+
curl.url = uri.to_s
|
34
|
+
if options[:basic_auth]
|
35
|
+
curl.http_auth_types = :basic
|
36
|
+
curl.username = options[:basic_auth][0]
|
37
|
+
curl.password = options[:basic_auth][1]
|
38
|
+
end
|
36
39
|
curl.timeout = 30
|
37
40
|
curl.connect_timeout = 30
|
38
41
|
|
@@ -66,7 +69,7 @@ module CurbSpecHelper
|
|
66
69
|
curl.put_data = body
|
67
70
|
end
|
68
71
|
|
69
|
-
curl.http(method)
|
72
|
+
curl.http(method.to_s.upcase)
|
70
73
|
curl
|
71
74
|
end
|
72
75
|
end
|