webmock 2.0.3 → 2.1.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 +10 -0
- data/Gemfile +2 -7
- data/README.md +54 -53
- data/Rakefile +1 -1
- data/lib/webmock/callback_registry.rb +1 -1
- data/lib/webmock/http_lib_adapters/curb_adapter.rb +68 -6
- data/lib/webmock/http_lib_adapters/em_http_request_adapter.rb +4 -4
- data/lib/webmock/http_lib_adapters/excon_adapter.rb +9 -9
- data/lib/webmock/http_lib_adapters/http_rb/request.rb +2 -2
- data/lib/webmock/http_lib_adapters/http_rb/response.rb +5 -5
- data/lib/webmock/http_lib_adapters/http_rb/webmock.rb +3 -3
- data/lib/webmock/http_lib_adapters/httpclient_adapter.rb +5 -5
- data/lib/webmock/http_lib_adapters/manticore_adapter.rb +7 -7
- data/lib/webmock/http_lib_adapters/net_http.rb +3 -3
- data/lib/webmock/http_lib_adapters/patron_adapter.rb +4 -4
- data/lib/webmock/http_lib_adapters/typhoeus_hydra_adapter.rb +14 -14
- data/lib/webmock/matchers/hash_including_matcher.rb +1 -1
- data/lib/webmock/rack_response.rb +3 -3
- data/lib/webmock/request_pattern.rb +8 -8
- data/lib/webmock/request_stub.rb +5 -5
- data/lib/webmock/util/uri.rb +2 -2
- data/lib/webmock/version.rb +1 -1
- data/minitest/webmock_spec.rb +3 -3
- data/spec/acceptance/curb/curb_spec.rb +64 -47
- data/spec/acceptance/curb/curb_spec_helper.rb +4 -4
- data/spec/acceptance/em_http_request/em_http_request_spec.rb +32 -32
- data/spec/acceptance/em_http_request/em_http_request_spec_helper.rb +9 -9
- data/spec/acceptance/excon/excon_spec.rb +14 -14
- data/spec/acceptance/excon/excon_spec_helper.rb +6 -6
- data/spec/acceptance/http_rb/http_rb_spec.rb +1 -1
- data/spec/acceptance/http_rb/http_rb_spec_helper.rb +7 -7
- data/spec/acceptance/httpclient/httpclient_spec.rb +20 -20
- data/spec/acceptance/httpclient/httpclient_spec_helper.rb +5 -5
- data/spec/acceptance/manticore/manticore_spec.rb +11 -11
- data/spec/acceptance/manticore/manticore_spec_helper.rb +3 -3
- data/spec/acceptance/net_http/net_http_shared.rb +4 -4
- data/spec/acceptance/net_http/net_http_spec.rb +25 -25
- data/spec/acceptance/net_http/net_http_spec_helper.rb +4 -4
- data/spec/acceptance/net_http/real_net_http_spec.rb +1 -1
- data/spec/acceptance/patron/patron_spec.rb +10 -10
- data/spec/acceptance/patron/patron_spec_helper.rb +5 -5
- data/spec/acceptance/shared/allowing_and_disabling_net_connect.rb +36 -36
- data/spec/acceptance/shared/callbacks.rb +11 -11
- data/spec/acceptance/shared/complex_cross_concern_behaviors.rb +5 -5
- data/spec/acceptance/shared/enabling_and_disabling_webmock.rb +4 -4
- data/spec/acceptance/shared/precedence_of_stubs.rb +4 -4
- data/spec/acceptance/shared/request_expectations.rb +90 -90
- data/spec/acceptance/shared/returning_declared_responses.rb +49 -49
- data/spec/acceptance/shared/stubbing_requests.rb +78 -78
- data/spec/acceptance/typhoeus/typhoeus_hydra_spec.rb +11 -11
- data/spec/acceptance/typhoeus/typhoeus_hydra_spec_helper.rb +8 -8
- data/spec/spec_helper.rb +6 -3
- data/spec/support/webmock_server.rb +1 -1
- data/spec/unit/api_spec.rb +2 -2
- data/spec/unit/errors_spec.rb +3 -3
- data/spec/unit/matchers/hash_including_matcher_spec.rb +16 -16
- data/spec/unit/rack_response_spec.rb +2 -2
- data/spec/unit/request_body_diff_spec.rb +1 -1
- data/spec/unit/request_execution_verifier_spec.rb +1 -1
- data/spec/unit/request_pattern_spec.rb +115 -115
- data/spec/unit/request_signature_snippet_spec.rb +2 -2
- data/spec/unit/request_signature_spec.rb +16 -16
- data/spec/unit/request_stub_spec.rb +20 -20
- data/spec/unit/response_spec.rb +28 -28
- data/spec/unit/stub_registry_spec.rb +10 -10
- data/spec/unit/stub_request_snippet_spec.rb +6 -6
- data/spec/unit/util/hash_keys_stringifier_spec.rb +4 -4
- data/spec/unit/util/query_mapper_spec.rb +2 -2
- data/spec/unit/util/uri_spec.rb +1 -1
- data/test/http_request.rb +3 -3
- data/test/shared_test.rb +6 -6
- data/webmock.gemspec +4 -2
- metadata +32 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e5ecaf79b30d292fbfa32412eb165fc1c2202e3c
|
4
|
+
data.tar.gz: 14f612738af09ebfd6ec02688da87e748d2886e3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8784b972e18a3906ea6ce8a359bcdc9ea88fbc386753791770ef21d550b985dbcbe60e5758ccd330b840d49ef9b126b41389ac8b6a32062478ffb6a215817142
|
7
|
+
data.tar.gz: 0f35a48a6a7e3705a35b6ab546e45805dfb268448f959cbf4b99ebf0f9d65e1d05c7f96a8b13cdb6c83c8909bac0fd2f6eb82ecfa833c8b3d5d20ca1f1bacd69
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,15 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## 2.1.0
|
4
|
+
|
5
|
+
* Added support for `on_debug` callback in Curb.
|
6
|
+
|
7
|
+
Thanks to [Pavel Jurašek](https://github.com/pavel-jurasek-bcgdv-com)
|
8
|
+
|
9
|
+
* Added support for PATCH requests using Curb.
|
10
|
+
|
11
|
+
Thanks to [Pavel Jurašek](https://github.com/pavel-jurasek-bcgdv-com)
|
12
|
+
|
3
13
|
## 2.0.3
|
4
14
|
|
5
15
|
* Handling headers passed as an Array to Curl::Easy
|
data/Gemfile
CHANGED
@@ -2,13 +2,8 @@ source 'http://rubygems.org/'
|
|
2
2
|
|
3
3
|
gemspec
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
end
|
8
|
-
|
9
|
-
group :test do
|
10
|
-
gem 'minitest_tu_shim', '1.3.2'
|
11
|
-
end
|
5
|
+
gem 'rake'
|
6
|
+
gem 'curb', github: 'pavel-jurasek-bcgdv-com/curb', platforms: :ruby
|
12
7
|
|
13
8
|
platforms :jruby do
|
14
9
|
gem 'jruby-openssl'
|
data/README.md
CHANGED
@@ -116,7 +116,7 @@ Net::HTTP.get("www.example.com", "/") # ===> Success
|
|
116
116
|
|
117
117
|
```ruby
|
118
118
|
stub_request(:post, "www.example.com").
|
119
|
-
with(:
|
119
|
+
with(body: "abc", headers: { 'Content-Length' => 3 })
|
120
120
|
|
121
121
|
uri = URI.parse("http://www.example.com/")
|
122
122
|
req = Net::HTTP::Post.new(uri.path)
|
@@ -131,8 +131,8 @@ end # ===> Success
|
|
131
131
|
|
132
132
|
```ruby
|
133
133
|
stub_request(:post, "www.example.com").
|
134
|
-
with(:
|
135
|
-
to_return(:
|
134
|
+
with(body: /^.*world$/, headers: {"Content-Type" => /image\/.+/}).
|
135
|
+
to_return(body: "abc")
|
136
136
|
|
137
137
|
uri = URI.parse('http://www.example.com/')
|
138
138
|
req = Net::HTTP::Post.new(uri.path)
|
@@ -147,23 +147,23 @@ end # ===> Success
|
|
147
147
|
|
148
148
|
```ruby
|
149
149
|
stub_request(:post, "www.example.com").
|
150
|
-
with(:
|
150
|
+
with(body: {data: {a: '1', b: 'five'}})
|
151
151
|
|
152
152
|
RestClient.post('www.example.com', "data[a]=1&data[b]=five",
|
153
|
-
:
|
153
|
+
content_type: 'application/x-www-form-urlencoded') # ===> Success
|
154
154
|
|
155
155
|
RestClient.post('www.example.com', '{"data":{"a":"1","b":"five"}}',
|
156
|
-
:
|
156
|
+
content_type: 'application/json') # ===> Success
|
157
157
|
|
158
158
|
RestClient.post('www.example.com', '<data a="1" b="five" />',
|
159
|
-
:
|
159
|
+
content_type: 'application/xml') # ===> Success
|
160
160
|
```
|
161
161
|
|
162
162
|
### Matching request body against partial hash.
|
163
163
|
|
164
164
|
```ruby
|
165
165
|
stub_request(:post, "www.example.com").
|
166
|
-
with(:
|
166
|
+
with(body: hash_including({data: {a: '1', b: 'five'}}))
|
167
167
|
|
168
168
|
RestClient.post('www.example.com', "data[a]=1&data[b]=five&x=1",
|
169
169
|
:content_type => 'application/x-www-form-urlencoded') # ===> Success
|
@@ -173,7 +173,7 @@ RestClient.post('www.example.com', "data[a]=1&data[b]=five&x=1",
|
|
173
173
|
|
174
174
|
```ruby
|
175
175
|
stub_request(:any, "www.example.com").
|
176
|
-
with(:
|
176
|
+
with(headers:{ 'Header-Name' => 'Header-Value' })
|
177
177
|
|
178
178
|
uri = URI.parse('http://www.example.com/')
|
179
179
|
req = Net::HTTP::Post.new(uri.path)
|
@@ -188,7 +188,7 @@ end # ===> Success
|
|
188
188
|
|
189
189
|
```ruby
|
190
190
|
stub_request(:get, 'www.example.com').
|
191
|
-
with(:
|
191
|
+
with(headers: {'Accept' => ['image/jpeg', 'image/png'] })
|
192
192
|
|
193
193
|
req = Net::HTTP::Get.new("/")
|
194
194
|
req['Accept'] = ['image/png']
|
@@ -259,7 +259,7 @@ Net::HTTP.get('www.example.com',
|
|
259
259
|
### Matching query params using hash
|
260
260
|
|
261
261
|
```ruby
|
262
|
-
stub_request(:get, "www.example.com").with(:
|
262
|
+
stub_request(:get, "www.example.com").with(query: {"a" => ["b", "c"]})
|
263
263
|
|
264
264
|
RestClient.get("http://www.example.com/?a[]=b&a[]=c") # ===> Success
|
265
265
|
```
|
@@ -268,7 +268,7 @@ RestClient.get("http://www.example.com/?a[]=b&a[]=c") # ===> Success
|
|
268
268
|
|
269
269
|
```ruby
|
270
270
|
stub_request(:get, "www.example.com").
|
271
|
-
with(:
|
271
|
+
with(query: hash_including({"a" => ["b", "c"]}))
|
272
272
|
|
273
273
|
RestClient.get("http://www.example.com/?a[]=b&a[]=c&x=1") # ===> Success
|
274
274
|
```
|
@@ -277,8 +277,8 @@ RestClient.get("http://www.example.com/?a[]=b&a[]=c&x=1") # ===> Success
|
|
277
277
|
|
278
278
|
```ruby
|
279
279
|
stub_request(:any, "www.example.com").
|
280
|
-
to_return(:
|
281
|
-
:
|
280
|
+
to_return(body: "abc", status: 200,
|
281
|
+
headers: { 'Content-Length' => 3 })
|
282
282
|
|
283
283
|
Net::HTTP.get("www.example.com", '/') # ===> "abc"
|
284
284
|
```
|
@@ -289,7 +289,7 @@ Net::HTTP.get("www.example.com", '/') # ===> "abc"
|
|
289
289
|
File.open('/tmp/response_body.txt', 'w') { |f| f.puts 'abc' }
|
290
290
|
|
291
291
|
stub_request(:any, "www.example.com").
|
292
|
-
to_return(:
|
292
|
+
to_return(body: File.new('/tmp/response_body.txt'), status: 200)
|
293
293
|
|
294
294
|
Net::HTTP.get('www.example.com', '/') # ===> "abc\n"
|
295
295
|
```
|
@@ -298,7 +298,7 @@ Net::HTTP.get('www.example.com', '/') # ===> "abc\n"
|
|
298
298
|
|
299
299
|
```ruby
|
300
300
|
stub_request(:any, "www.example.com").
|
301
|
-
to_return(:
|
301
|
+
to_return(status: [500, "Internal Server Error"])
|
302
302
|
|
303
303
|
req = Net::HTTP::Get.new("/")
|
304
304
|
Net::HTTP.start("www.example.com") { |http| http.request(req) }.
|
@@ -331,7 +331,7 @@ stub_request(:get, "www.example.com").to_return(raw_response_file.read)
|
|
331
331
|
|
332
332
|
```ruby
|
333
333
|
stub_request(:any, 'www.example.net').
|
334
|
-
to_return { |request| {:
|
334
|
+
to_return { |request| {body: request.body} }
|
335
335
|
|
336
336
|
RestClient.post('www.example.net', 'abc') # ===> "abc\n"
|
337
337
|
```
|
@@ -340,7 +340,7 @@ RestClient.post('www.example.net', 'abc') # ===> "abc\n"
|
|
340
340
|
|
341
341
|
```ruby
|
342
342
|
stub_request(:any, 'www.example.net').
|
343
|
-
to_return(lambda { |request| {:
|
343
|
+
to_return(lambda { |request| {body: request.body} })
|
344
344
|
|
345
345
|
RestClient.post('www.example.net', 'abc') # ===> "abc\n"
|
346
346
|
```
|
@@ -357,7 +357,7 @@ stub_request(:get, "www.example.com").
|
|
357
357
|
|
358
358
|
```ruby
|
359
359
|
stub_request(:any, 'www.example.net').
|
360
|
-
to_return(:
|
360
|
+
to_return(body: lambda { |request| request.body })
|
361
361
|
|
362
362
|
RestClient.post('www.example.net', 'abc') # ===> "abc\n"
|
363
363
|
```
|
@@ -410,7 +410,7 @@ RestClient.post('www.example.net', 'abc') # ===> RestClient::RequestTimeout
|
|
410
410
|
|
411
411
|
```ruby
|
412
412
|
stub_request(:get, "www.example.com").
|
413
|
-
to_return({:
|
413
|
+
to_return({body: "abc"}, {body: "def"})
|
414
414
|
Net::HTTP.get('www.example.com', '/') # ===> "abc\n"
|
415
415
|
Net::HTTP.get('www.example.com', '/') # ===> "def\n"
|
416
416
|
|
@@ -423,8 +423,8 @@ Net::HTTP.get('www.example.com', '/') # ===> "def\n"
|
|
423
423
|
|
424
424
|
```ruby
|
425
425
|
stub_request(:get, "www.example.com").
|
426
|
-
to_return({:
|
427
|
-
to_return({:
|
426
|
+
to_return({body: "abc"}).then. #then() is just a syntactic sugar
|
427
|
+
to_return({body: "def"}).then.
|
428
428
|
to_raise(MyException)
|
429
429
|
|
430
430
|
Net::HTTP.get('www.example.com', '/') # ===> "abc\n"
|
@@ -436,8 +436,8 @@ Net::HTTP.get('www.example.com', '/') # ===> MyException raised
|
|
436
436
|
|
437
437
|
```ruby
|
438
438
|
stub_request(:get, "www.example.com").
|
439
|
-
to_return({:
|
440
|
-
to_return({:
|
439
|
+
to_return({body: "abc"}).times(2).then.
|
440
|
+
to_return({body: "def"})
|
441
441
|
|
442
442
|
Net::HTTP.get('www.example.com', '/') # ===> "abc\n"
|
443
443
|
Net::HTTP.get('www.example.com', '/') # ===> "abc\n"
|
@@ -456,7 +456,7 @@ remove_request_stub(stub_get)
|
|
456
456
|
```ruby
|
457
457
|
WebMock.allow_net_connect!
|
458
458
|
|
459
|
-
stub_request(:any, "www.example.com").to_return(:
|
459
|
+
stub_request(:any, "www.example.com").to_return(body: "abc")
|
460
460
|
|
461
461
|
Net::HTTP.get('www.example.com', '/') # ===> "abc"
|
462
462
|
|
@@ -470,7 +470,7 @@ Net::HTTP.get('www.something.com', '/') # ===> Failure
|
|
470
470
|
### External requests can be disabled while allowing localhost
|
471
471
|
|
472
472
|
```ruby
|
473
|
-
WebMock.disable_net_connect!(:
|
473
|
+
WebMock.disable_net_connect!(allow_localhost: true)
|
474
474
|
|
475
475
|
Net::HTTP.get('www.something.com', '/') # ===> Failure
|
476
476
|
|
@@ -484,7 +484,7 @@ Allowed requests can be specified in a number of ways.
|
|
484
484
|
With a `String` specifying a host name:
|
485
485
|
|
486
486
|
```ruby
|
487
|
-
WebMock.disable_net_connect!(:
|
487
|
+
WebMock.disable_net_connect!(allow: 'www.example.org')
|
488
488
|
|
489
489
|
RestClient.get('www.something.com', '/') # ===> Failure
|
490
490
|
RestClient.get('www.example.org', '/') # ===> Allowed
|
@@ -494,7 +494,7 @@ RestClient.get('www.example.org:8080', '/') # ===> Allowed
|
|
494
494
|
With a `String` specifying a host name and a port:
|
495
495
|
|
496
496
|
```ruby
|
497
|
-
WebMock.disable_net_connect!(:
|
497
|
+
WebMock.disable_net_connect!(allow: 'www.example.org:8080')
|
498
498
|
|
499
499
|
RestClient.get('www.something.com', '/') # ===> Failure
|
500
500
|
RestClient.get('www.example.org', '/') # ===> Failure
|
@@ -504,7 +504,7 @@ RestClient.get('www.example.org:8080', '/') # ===> Allowed
|
|
504
504
|
With a `Regexp` matching the URI:
|
505
505
|
|
506
506
|
```ruby
|
507
|
-
WebMock.disable_net_connect!(:
|
507
|
+
WebMock.disable_net_connect!(allow: %r{ample.org/foo})
|
508
508
|
|
509
509
|
RestClient.get('www.example.org', '/foo/bar') # ===> Allowed
|
510
510
|
RestClient.get('sample.org', '/foo') # ===> Allowed
|
@@ -518,7 +518,7 @@ blacklist = ['google.com', 'facebook.com', 'apple.com']
|
|
518
518
|
allowed_sites = lambda{|uri|
|
519
519
|
blacklist.none?{|site| uri.host.include?(site) }
|
520
520
|
}
|
521
|
-
WebMock.disable_net_connect!(:
|
521
|
+
WebMock.disable_net_connect!(allow: allowed_sites)
|
522
522
|
|
523
523
|
RestClient.get('www.example.org', '/') # ===> Allowed
|
524
524
|
RestClient.get('www.facebook.com', '/') # ===> Failure
|
@@ -528,7 +528,7 @@ RestClient.get('apple.com', '/') # ===> Failure
|
|
528
528
|
With an `Array` of any of the above:
|
529
529
|
|
530
530
|
```ruby
|
531
|
-
WebMock.disable_net_connect!(:
|
531
|
+
WebMock.disable_net_connect!(allow: [
|
532
532
|
lambda{|uri| uri.host.length % 2 == 0 },
|
533
533
|
/ample.org/,
|
534
534
|
'bbc.co.uk',
|
@@ -556,7 +556,7 @@ To workaround this issue, WebMock offers `:net_http_connect_on_start` option,
|
|
556
556
|
which can be passed to `WebMock.allow_net_connect!` and `WebMock.disable_net_connect!` methods, i.e.
|
557
557
|
|
558
558
|
```ruby
|
559
|
-
WebMock.allow_net_connect!(:
|
559
|
+
WebMock.allow_net_connect!(net_http_connect_on_start: true)
|
560
560
|
```
|
561
561
|
|
562
562
|
This forces WebMock Net::HTTP adapter to always connect on `Net::HTTP.start`.
|
@@ -579,13 +579,13 @@ res = Net::HTTP.start(uri.host, uri.port) do |http|
|
|
579
579
|
end
|
580
580
|
|
581
581
|
assert_requested :post, "http://www.example.com",
|
582
|
-
:
|
583
|
-
:
|
582
|
+
headers: {'Content-Length' => 3}, body: "abc",
|
583
|
+
times: 1 # ===> Success
|
584
584
|
|
585
585
|
assert_not_requested :get, "http://www.something.com" # ===> Success
|
586
586
|
|
587
587
|
assert_requested(:post, "http://www.example.com",
|
588
|
-
:
|
588
|
+
times: 1) { |req| req.body == "abc" }
|
589
589
|
```
|
590
590
|
|
591
591
|
### Expecting real (not stubbed) requests
|
@@ -618,7 +618,7 @@ assert_not_requested(stub_post)
|
|
618
618
|
require 'webmock/rspec'
|
619
619
|
|
620
620
|
expect(WebMock).to have_requested(:get, "www.example.com").
|
621
|
-
with(:
|
621
|
+
with(body: "abc", headers: {'Content-Length' => 3}).twice
|
622
622
|
|
623
623
|
expect(WebMock).not_to have_requested(:get, "www.something.com")
|
624
624
|
|
@@ -628,21 +628,21 @@ expect(WebMock).to have_requested(:post, "www.example.com").
|
|
628
628
|
# Why? See this comment https://github.com/bblimke/webmock/issues/174#issuecomment-34908908
|
629
629
|
|
630
630
|
expect(WebMock).to have_requested(:get, "www.example.com").
|
631
|
-
with(:
|
631
|
+
with(query: {"a" => ["b", "c"]})
|
632
632
|
|
633
633
|
expect(WebMock).to have_requested(:get, "www.example.com").
|
634
|
-
with(:
|
634
|
+
with(query: hash_including({"a" => ["b", "c"]}))
|
635
635
|
|
636
636
|
expect(WebMock).to have_requested(:get, "www.example.com").
|
637
|
-
with(:
|
638
|
-
:
|
637
|
+
with(body: {"a" => ["b", "c"]},
|
638
|
+
headers: {'Content-Type' => 'application/json'})
|
639
639
|
```
|
640
640
|
|
641
641
|
### Setting expectations in RSpec with `a_request`
|
642
642
|
|
643
643
|
```ruby
|
644
644
|
expect(a_request(:post, "www.example.com").
|
645
|
-
with(:
|
645
|
+
with(body: "abc", headers: {'Content-Length' => 3})).
|
646
646
|
to have_been_made.once
|
647
647
|
|
648
648
|
expect(a_request(:post, "www.something.com")).to have_been_made.times(3)
|
@@ -661,15 +661,15 @@ expect(a_request(:any, "www.example.com")).not_to have_been_made
|
|
661
661
|
expect(a_request(:post, "www.example.com").with { |req| req.body == "abc" }).
|
662
662
|
to have_been_made
|
663
663
|
|
664
|
-
expect(a_request(:get, "www.example.com").with(:
|
664
|
+
expect(a_request(:get, "www.example.com").with(query: {"a" => ["b", "c"]})).
|
665
665
|
to have_been_made
|
666
666
|
|
667
667
|
expect(a_request(:get, "www.example.com").
|
668
|
-
with(:
|
668
|
+
with(query: hash_including({"a" => ["b", "c"]}))).to have_been_made
|
669
669
|
|
670
670
|
expect(a_request(:post, "www.example.com").
|
671
|
-
with(:
|
672
|
-
:
|
671
|
+
with(body: {"a" => ["b", "c"]},
|
672
|
+
headers: {'Content-Type' => 'application/json'})).to have_been_made
|
673
673
|
```
|
674
674
|
|
675
675
|
### Setting expectations in RSpec on the stub
|
@@ -703,13 +703,13 @@ assert_not_requested :get, "www.example.com" # ===> Success
|
|
703
703
|
WebMock.disable!
|
704
704
|
|
705
705
|
# Disable WebMock for all libs except Net::HTTP
|
706
|
-
WebMock.disable!(:
|
706
|
+
WebMock.disable!(except: [:net_http])
|
707
707
|
|
708
708
|
# Enable WebMock (all adapters)
|
709
709
|
WebMock.enable!
|
710
710
|
|
711
711
|
# Enable WebMock for all libs except Patron
|
712
|
-
WebMock.enable!(:
|
712
|
+
WebMock.enable!(except: [:patron])
|
713
713
|
```
|
714
714
|
|
715
715
|
## Matching requests
|
@@ -727,8 +727,8 @@ An executed request matches stubbed request if it passes following criteria:
|
|
727
727
|
Always the last declared stub matching the request will be applied i.e:
|
728
728
|
|
729
729
|
```ruby
|
730
|
-
stub_request(:get, "www.example.com").to_return(:
|
731
|
-
stub_request(:get, "www.example.com").to_return(:
|
730
|
+
stub_request(:get, "www.example.com").to_return(body: "abc")
|
731
|
+
stub_request(:get, "www.example.com").to_return(body: "def")
|
732
732
|
|
733
733
|
Net::HTTP.get('www.example.com', '/') # ====> "def"
|
734
734
|
```
|
@@ -810,9 +810,9 @@ i.e stubbed headers: `nil`, requested: `{ 'Header1' => 'Value1', 'Header2' => 'V
|
|
810
810
|
WebMock normalises headers and treats all forms of same headers as equal:
|
811
811
|
i.e the following two sets of headers are equal:
|
812
812
|
|
813
|
-
`{ "Header1" => "value1", :
|
813
|
+
`{ "Header1" => "value1", content_length: 123, X_CuStOm_hEAder: :value }`
|
814
814
|
|
815
|
-
`{ :
|
815
|
+
`{ header1: "value1", "Content-Length" => 123, "x-cuSTOM-HeAder" => "value" }`
|
816
816
|
|
817
817
|
## Recording real requests and responses and replaying them later
|
818
818
|
|
@@ -831,8 +831,8 @@ end
|
|
831
831
|
#### invoke callbacks for real requests only and except requests made with Patron
|
832
832
|
|
833
833
|
```ruby
|
834
|
-
WebMock.after_request(:
|
835
|
-
:
|
834
|
+
WebMock.after_request(except: [:patron],
|
835
|
+
real_requests_only: true) do |req_signature, response|
|
836
836
|
puts "Request #{req_signature} was made and #{response} was returned"
|
837
837
|
end
|
838
838
|
```
|
@@ -1020,6 +1020,7 @@ People who submitted patches and new features or suggested improvements. Many th
|
|
1020
1020
|
* Jonathan Schatz
|
1021
1021
|
* Jose Luis Honorato
|
1022
1022
|
* Aaron Kromer
|
1023
|
+
* Pavel Jurašek
|
1023
1024
|
|
1024
1025
|
For a full list of contributors you can visit the
|
1025
1026
|
[contributors](https://github.com/bblimke/webmock/contributors) page.
|
data/Rakefile
CHANGED
@@ -62,7 +62,7 @@ if defined?(Curl)
|
|
62
62
|
if webmock_response = WebMock::StubRegistry.instance.response_for_request(request_signature)
|
63
63
|
build_curb_response(webmock_response)
|
64
64
|
WebMock::CallbackRegistry.invoke_callbacks(
|
65
|
-
{:
|
65
|
+
{lib: :curb}, request_signature, webmock_response)
|
66
66
|
invoke_curb_callbacks
|
67
67
|
true
|
68
68
|
elsif WebMock.net_connect_allowed?(request_signature.uri)
|
@@ -70,7 +70,7 @@ if defined?(Curl)
|
|
70
70
|
if WebMock::CallbackRegistry.any_callbacks?
|
71
71
|
webmock_response = build_webmock_response
|
72
72
|
WebMock::CallbackRegistry.invoke_callbacks(
|
73
|
-
{:
|
73
|
+
{lib: :curb, real_request: true}, request_signature,
|
74
74
|
webmock_response)
|
75
75
|
end
|
76
76
|
res
|
@@ -85,20 +85,45 @@ if defined?(Curl)
|
|
85
85
|
uri = WebMock::Util::URI.heuristic_parse(self.url)
|
86
86
|
uri.path = uri.normalized_path.gsub("[^:]//","/")
|
87
87
|
|
88
|
+
headers = headers_as_hash(self.headers).merge(basic_auth_headers)
|
89
|
+
|
88
90
|
request_body = case method
|
89
91
|
when :post
|
90
92
|
self.post_body || @post_body
|
91
93
|
when :put
|
92
94
|
@put_data
|
95
|
+
when :patch
|
96
|
+
@patch_data
|
93
97
|
else
|
94
98
|
nil
|
95
99
|
end
|
96
100
|
|
101
|
+
if defined?( @on_debug )
|
102
|
+
@on_debug.call("Trying 127.0.0.1...\r\n", 0)
|
103
|
+
@on_debug.call('Connected to ' + uri.hostname + "\r\n", 0)
|
104
|
+
@debug_method = method.upcase
|
105
|
+
@debug_path = uri.path
|
106
|
+
@debug_host = uri.hostname
|
107
|
+
http_request = ["#{@debug_method} #{@debug_path} HTTP/1.1"]
|
108
|
+
http_request << "Host: #{uri.hostname}"
|
109
|
+
headers.each do |name, value|
|
110
|
+
http_request << "#{name}: #{value}"
|
111
|
+
end
|
112
|
+
@on_debug.call(http_request.join("\r\n") + "\r\n\r\n", 2)
|
113
|
+
if request_body
|
114
|
+
@on_debug.call(request_body + "\r\n", 4)
|
115
|
+
@on_debug.call(
|
116
|
+
"upload completely sent off: #{request_body.bytesize}"\
|
117
|
+
" out of #{request_body.bytesize} bytes\r\n", 0
|
118
|
+
)
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
97
122
|
request_signature = WebMock::RequestSignature.new(
|
98
123
|
method,
|
99
124
|
uri.to_s,
|
100
|
-
:
|
101
|
-
:
|
125
|
+
body: request_body,
|
126
|
+
headers: headers
|
102
127
|
)
|
103
128
|
request_signature
|
104
129
|
end
|
@@ -131,10 +156,16 @@ if defined?(Curl)
|
|
131
156
|
@response_code = webmock_response.status[0]
|
132
157
|
|
133
158
|
@header_str = "HTTP/1.1 #{webmock_response.status[0]} #{webmock_response.status[1]}\r\n"
|
159
|
+
|
160
|
+
@on_debug.call(@header_str, 1) if defined?( @on_debug )
|
161
|
+
|
134
162
|
if webmock_response.headers
|
135
163
|
@header_str << webmock_response.headers.map do |k,v|
|
136
|
-
"#{k}: #{v.is_a?(Array) ? v.join(", ") : v}"
|
164
|
+
header = "#{k}: #{v.is_a?(Array) ? v.join(", ") : v}"
|
165
|
+
@on_debug.call(header + "\r\n", 1) if defined?( @on_debug )
|
166
|
+
header
|
137
167
|
end.join("\r\n")
|
168
|
+
@on_debug.call("\r\n", 1) if defined?( @on_debug )
|
138
169
|
|
139
170
|
location = webmock_response.headers['Location']
|
140
171
|
if self.follow_location? && location
|
@@ -192,6 +223,16 @@ if defined?(Curl)
|
|
192
223
|
status, headers =
|
193
224
|
WebMock::HttpLibAdapters::CurbAdapter.parse_header_string(self.header_str)
|
194
225
|
|
226
|
+
if defined?( @on_debug )
|
227
|
+
http_response = ["HTTP/1.0 #{@debug_method} #{@debug_path}"]
|
228
|
+
headers.each do |name, value|
|
229
|
+
http_response << "#{name}: #{value}"
|
230
|
+
end
|
231
|
+
http_response << self.body_str
|
232
|
+
@on_debug.call(http_response.join("\r\n") + "\r\n", 3)
|
233
|
+
@on_debug.call("Connection #0 to host #{@debug_host} left intact\r\n", 0)
|
234
|
+
end
|
235
|
+
|
195
236
|
webmock_response = WebMock::Response.new
|
196
237
|
webmock_response.status = [self.response_code, status]
|
197
238
|
webmock_response.body = self.body_str
|
@@ -222,6 +263,13 @@ if defined?(Curl)
|
|
222
263
|
end
|
223
264
|
alias put http_put
|
224
265
|
|
266
|
+
def http_patch data = nil
|
267
|
+
@webmock_method = :patch
|
268
|
+
@patch_data = data if data
|
269
|
+
super
|
270
|
+
end
|
271
|
+
alias patch http_patch
|
272
|
+
|
225
273
|
def http_post *data
|
226
274
|
@webmock_method = :post
|
227
275
|
@post_body = data.join('&') if data && !data.empty?
|
@@ -240,6 +288,12 @@ if defined?(Curl)
|
|
240
288
|
super
|
241
289
|
end
|
242
290
|
|
291
|
+
def patch_data= data
|
292
|
+
@webmock_method = :patch
|
293
|
+
@patch_data = data
|
294
|
+
super
|
295
|
+
end
|
296
|
+
|
243
297
|
def post_body= data
|
244
298
|
@webmock_method = :post
|
245
299
|
super
|
@@ -255,6 +309,14 @@ if defined?(Curl)
|
|
255
309
|
super
|
256
310
|
end
|
257
311
|
|
312
|
+
def verbose=(verbose)
|
313
|
+
@verbose = verbose
|
314
|
+
end
|
315
|
+
|
316
|
+
def verbose?
|
317
|
+
@verbose ||= false
|
318
|
+
end
|
319
|
+
|
258
320
|
def body_str
|
259
321
|
@body_str ||= super
|
260
322
|
end
|
@@ -277,7 +339,7 @@ if defined?(Curl)
|
|
277
339
|
@content_type ||= super
|
278
340
|
end
|
279
341
|
|
280
|
-
%w[ success failure missing header body complete progress ].each do |callback|
|
342
|
+
%w[ success failure missing header body complete progress debug ].each do |callback|
|
281
343
|
class_eval <<-METHOD, __FILE__, __LINE__
|
282
344
|
def on_#{callback} &block
|
283
345
|
@on_#{callback} = block
|