webmock 3.9.4 → 3.11.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +38 -0
- data/README.md +5 -0
- data/lib/webmock/http_lib_adapters/async_http_client_adapter.rb +2 -2
- data/lib/webmock/http_lib_adapters/http_rb/client.rb +4 -1
- data/lib/webmock/http_lib_adapters/manticore_adapter.rb +8 -1
- data/lib/webmock/stub_registry.rb +11 -6
- data/lib/webmock/test_unit.rb +1 -3
- data/lib/webmock/version.rb +1 -1
- data/lib/webmock/webmock.rb +2 -2
- data/spec/acceptance/manticore/manticore_spec.rb +32 -0
- data/spec/acceptance/shared/stubbing_requests.rb +17 -0
- data/test/test_webmock.rb +6 -0
- data/webmock.gemspec +1 -0
- metadata +19 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6784322094783787fdf1a995a18c703ef70e0dccf59cbc8ad69cf086b11feb7b
|
4
|
+
data.tar.gz: e2e0fc45a8e44efdcfbfd777a733790b6d1762311f62762065e602c281daff09
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 277b355a34e07d6bf1c97692fe3c64c54518b16705fc9a6135b1b2000d0cd9e72256e88858e4b4c345cac9cda5d8edf2163f94e69ace05bbc6e75986eae0794d
|
7
|
+
data.tar.gz: ba7f43ee30745e58fa57d7030bce1bde7c334b719707642eadcce8963c0e52b88932913ed2a3115b59b6e3477830c87f9646961b7c5bdd95a95086ff733833c8
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,43 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
# 3.11.2
|
4
|
+
|
5
|
+
* Fix for Manticore streaming mode
|
6
|
+
|
7
|
+
Thanks to [Oleksiy Kovyrin](https://github.com/kovyrin)
|
8
|
+
|
9
|
+
# 3.11.1
|
10
|
+
|
11
|
+
* Compatibility with async-http 0.54+
|
12
|
+
|
13
|
+
Thanks to [Jun Jiang](https://github.com/jasl)
|
14
|
+
|
15
|
+
# 3.11.0
|
16
|
+
|
17
|
+
* Added support for `features` in http.rb adapter.
|
18
|
+
|
19
|
+
Thanks to [Carl (ce07c3)](https://github.com/ce07c3)
|
20
|
+
|
21
|
+
# 3.10.0
|
22
|
+
|
23
|
+
* Added option to global stubs to have lower priority than local stubs.
|
24
|
+
|
25
|
+
WebMock.globally_stub_request(:after_local_stubs) do
|
26
|
+
{ body: "global stub body" }
|
27
|
+
end
|
28
|
+
|
29
|
+
stub_request(:get, "www.example.com").to_return(body: 'non-global stub body')
|
30
|
+
|
31
|
+
expect(http_request(:get, "http://www.example.com/").body).to eq("non-global stub body")
|
32
|
+
|
33
|
+
Thanks to [Marek Kasztelnik](https://github.com/mkasztelnik)
|
34
|
+
|
35
|
+
# 3.9.5
|
36
|
+
|
37
|
+
* Prevent overwriting `teardown` method in Test::Unit
|
38
|
+
|
39
|
+
Thanks to [Jesse Bowes](https://github.com/jessebs)
|
40
|
+
|
3
41
|
# 3.9.4
|
4
42
|
|
5
43
|
* More intuitive error message when stubbed response body was provided as Hash
|
data/README.md
CHANGED
@@ -1149,6 +1149,11 @@ People who submitted patches and new features or suggested improvements. Many th
|
|
1149
1149
|
* Ryan Kerr
|
1150
1150
|
* Adam Harwood
|
1151
1151
|
* Ben Koshy
|
1152
|
+
* Jesse Bowes
|
1153
|
+
* Marek Kasztelnik
|
1154
|
+
* ce07c3
|
1155
|
+
* Jun Jiang
|
1156
|
+
* Oleksiy Kovyrin
|
1152
1157
|
|
1153
1158
|
For a full list of contributors you can visit the
|
1154
1159
|
[contributors](https://github.com/bblimke/webmock/contributors) page.
|
@@ -40,8 +40,8 @@ if defined?(Async::HTTP)
|
|
40
40
|
)
|
41
41
|
webmock_endpoint = WebMockEndpoint.new(scheme, authority, protocol)
|
42
42
|
|
43
|
-
@network_client = WebMockClient.new(endpoint,
|
44
|
-
@webmock_client = WebMockClient.new(webmock_endpoint,
|
43
|
+
@network_client = WebMockClient.new(endpoint, **options)
|
44
|
+
@webmock_client = WebMockClient.new(webmock_endpoint, **options)
|
45
45
|
|
46
46
|
@scheme = scheme
|
47
47
|
@authority = authority
|
@@ -4,7 +4,10 @@ module HTTP
|
|
4
4
|
|
5
5
|
def perform(request, options)
|
6
6
|
return __perform__(request, options) unless webmock_enabled?
|
7
|
-
|
7
|
+
|
8
|
+
response = WebMockPerform.new(request) { __perform__(request, options) }.exec
|
9
|
+
options.features.each { |_name, feature| response = feature.wrap_response(response) }
|
10
|
+
response
|
8
11
|
end
|
9
12
|
|
10
13
|
def webmock_enabled?
|
@@ -127,8 +127,15 @@ if defined?(Manticore)
|
|
127
127
|
def generate_webmock_response(manticore_response)
|
128
128
|
webmock_response = WebMock::Response.new
|
129
129
|
webmock_response.status = [manticore_response.code, manticore_response.message]
|
130
|
-
webmock_response.body = manticore_response.body
|
131
130
|
webmock_response.headers = manticore_response.headers
|
131
|
+
|
132
|
+
# The attempt to read the body could fail if manticore is used in a streaming mode
|
133
|
+
webmock_response.body = begin
|
134
|
+
manticore_response.body
|
135
|
+
rescue ::Manticore::StreamClosedException
|
136
|
+
nil
|
137
|
+
end
|
138
|
+
|
132
139
|
webmock_response
|
133
140
|
end
|
134
141
|
end
|
@@ -10,14 +10,18 @@ module WebMock
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def global_stubs
|
13
|
-
@global_stubs ||= []
|
13
|
+
@global_stubs ||= Hash.new { |h, k| h[k] = [] }
|
14
14
|
end
|
15
15
|
|
16
16
|
def reset!
|
17
17
|
self.request_stubs = []
|
18
18
|
end
|
19
19
|
|
20
|
-
def register_global_stub(&block)
|
20
|
+
def register_global_stub(order = :before_local_stubs, &block)
|
21
|
+
unless %i[before_local_stubs after_local_stubs].include?(order)
|
22
|
+
raise ArgumentError.new("Wrong order. Use :before_local_stubs or :after_local_stubs")
|
23
|
+
end
|
24
|
+
|
21
25
|
# This hash contains the responses returned by the block,
|
22
26
|
# keyed by the exact request (using the object_id).
|
23
27
|
# That way, there's no race condition in case #to_return
|
@@ -38,7 +42,7 @@ module WebMock
|
|
38
42
|
response_lock.synchronize { responses.delete(request.object_id) }
|
39
43
|
})
|
40
44
|
|
41
|
-
global_stubs.push stub
|
45
|
+
global_stubs[order].push stub
|
42
46
|
end
|
43
47
|
|
44
48
|
def register_request_stub(stub)
|
@@ -64,9 +68,10 @@ module WebMock
|
|
64
68
|
private
|
65
69
|
|
66
70
|
def request_stub_for(request_signature)
|
67
|
-
(global_stubs + request_stubs
|
68
|
-
registered_request_stub
|
69
|
-
|
71
|
+
(global_stubs[:before_local_stubs] + request_stubs + global_stubs[:after_local_stubs])
|
72
|
+
.detect { |registered_request_stub|
|
73
|
+
registered_request_stub.request_pattern.matches?(request_signature)
|
74
|
+
}
|
70
75
|
end
|
71
76
|
|
72
77
|
def evaluate_response_for_request(response, request_signature)
|
data/lib/webmock/test_unit.rb
CHANGED
@@ -8,12 +8,10 @@ module Test
|
|
8
8
|
class TestCase
|
9
9
|
include WebMock::API
|
10
10
|
|
11
|
-
|
11
|
+
teardown
|
12
12
|
def teardown_with_webmock
|
13
|
-
teardown_without_webmock
|
14
13
|
WebMock.reset!
|
15
14
|
end
|
16
|
-
alias_method :teardown, :teardown_with_webmock
|
17
15
|
|
18
16
|
end
|
19
17
|
end
|
data/lib/webmock/version.rb
CHANGED
data/lib/webmock/webmock.rb
CHANGED
@@ -140,8 +140,8 @@ module WebMock
|
|
140
140
|
puts WebMock::RequestExecutionVerifier.executed_requests_message
|
141
141
|
end
|
142
142
|
|
143
|
-
def self.globally_stub_request(&block)
|
144
|
-
WebMock::StubRegistry.instance.register_global_stub(&block)
|
143
|
+
def self.globally_stub_request(order = :before_local_stubs, &block)
|
144
|
+
WebMock::StubRegistry.instance.register_global_stub(order, &block)
|
145
145
|
end
|
146
146
|
|
147
147
|
%w(
|
@@ -70,6 +70,38 @@ if RUBY_PLATFORM =~ /java/
|
|
70
70
|
expect(failure_handler).to have_received(:call)
|
71
71
|
end
|
72
72
|
end
|
73
|
+
|
74
|
+
context 'when used in a streaming mode' do
|
75
|
+
let(:webmock_server_url) {"http://#{WebMockServer.instance.host_with_port}/"}
|
76
|
+
let(:result_chunks) { [] }
|
77
|
+
|
78
|
+
def manticore_streaming_get
|
79
|
+
Manticore.get(webmock_server_url).tap do |req|
|
80
|
+
req.on_success do |response|
|
81
|
+
response.body do |chunk|
|
82
|
+
result_chunks << chunk
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
context 'when connections are allowed' do
|
89
|
+
it 'works' do
|
90
|
+
WebMock.allow_net_connect!
|
91
|
+
expect { manticore_streaming_get.call }.to_not raise_error
|
92
|
+
expect(result_chunks).to_not be_empty
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
context 'when stubbed' do
|
97
|
+
it 'works' do
|
98
|
+
stub_body = 'hello!'
|
99
|
+
stub_request(:get, webmock_server_url).to_return(body: stub_body)
|
100
|
+
expect { manticore_streaming_get.call }.to_not raise_error
|
101
|
+
expect(result_chunks).to eq [stub_body]
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
73
105
|
end
|
74
106
|
end
|
75
107
|
end
|
@@ -593,6 +593,23 @@ shared_examples_for "stubbing requests" do |*adapter_info|
|
|
593
593
|
end
|
594
594
|
end
|
595
595
|
end
|
596
|
+
|
597
|
+
context "when global stub should be invoked last" do
|
598
|
+
before do
|
599
|
+
WebMock.globally_stub_request(:after_local_stubs) do
|
600
|
+
{ body: "global stub body" }
|
601
|
+
end
|
602
|
+
end
|
603
|
+
|
604
|
+
it "uses global stub when non-global stub is not defined" do
|
605
|
+
expect(http_request(:get, "http://www.example.com/").body).to eq("global stub body")
|
606
|
+
end
|
607
|
+
|
608
|
+
it "uses non-global stub first" do
|
609
|
+
stub_request(:get, "www.example.com").to_return(body: 'non-global stub body')
|
610
|
+
expect(http_request(:get, "http://www.example.com/").body).to eq("non-global stub body")
|
611
|
+
end
|
612
|
+
end
|
596
613
|
end
|
597
614
|
|
598
615
|
describe "when stubbing request with a block evaluated on request" do
|
data/test/test_webmock.rb
CHANGED
@@ -3,4 +3,10 @@ require File.expand_path(File.dirname(__FILE__) + '/shared_test')
|
|
3
3
|
|
4
4
|
class TestWebMock < Test::Unit::TestCase
|
5
5
|
include SharedTest
|
6
|
+
|
7
|
+
def teardown
|
8
|
+
# Ensure global Test::Unit teardown was called
|
9
|
+
assert_empty WebMock::RequestRegistry.instance.requested_signatures.hash
|
10
|
+
assert_empty WebMock::StubRegistry.instance.request_stubs
|
11
|
+
end
|
6
12
|
end
|
data/webmock.gemspec
CHANGED
@@ -45,6 +45,7 @@ Gem::Specification.new do |s|
|
|
45
45
|
s.add_development_dependency 'minitest', '>= 5.0.0'
|
46
46
|
s.add_development_dependency 'test-unit', '>= 3.0.0'
|
47
47
|
s.add_development_dependency 'rdoc', '> 3.5.0'
|
48
|
+
s.add_development_dependency 'webrick'
|
48
49
|
|
49
50
|
s.files = `git ls-files`.split("\n")
|
50
51
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: webmock
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.11.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bartosz Blimke
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-01-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: addressable
|
@@ -254,6 +254,20 @@ dependencies:
|
|
254
254
|
- - ">"
|
255
255
|
- !ruby/object:Gem::Version
|
256
256
|
version: 3.5.0
|
257
|
+
- !ruby/object:Gem::Dependency
|
258
|
+
name: webrick
|
259
|
+
requirement: !ruby/object:Gem::Requirement
|
260
|
+
requirements:
|
261
|
+
- - ">="
|
262
|
+
- !ruby/object:Gem::Version
|
263
|
+
version: '0'
|
264
|
+
type: :development
|
265
|
+
prerelease: false
|
266
|
+
version_requirements: !ruby/object:Gem::Requirement
|
267
|
+
requirements:
|
268
|
+
- - ">="
|
269
|
+
- !ruby/object:Gem::Version
|
270
|
+
version: '0'
|
257
271
|
description: WebMock allows stubbing HTTP requests and setting expectations on HTTP
|
258
272
|
requests.
|
259
273
|
email:
|
@@ -407,9 +421,9 @@ licenses:
|
|
407
421
|
- MIT
|
408
422
|
metadata:
|
409
423
|
bug_tracker_uri: https://github.com/bblimke/webmock/issues
|
410
|
-
changelog_uri: https://github.com/bblimke/webmock/blob/v3.
|
411
|
-
documentation_uri: https://www.rubydoc.info/gems/webmock/3.
|
412
|
-
source_code_uri: https://github.com/bblimke/webmock/tree/v3.
|
424
|
+
changelog_uri: https://github.com/bblimke/webmock/blob/v3.11.2/CHANGELOG.md
|
425
|
+
documentation_uri: https://www.rubydoc.info/gems/webmock/3.11.2
|
426
|
+
source_code_uri: https://github.com/bblimke/webmock/tree/v3.11.2
|
413
427
|
wiki_uri: https://github.com/bblimke/webmock/wiki
|
414
428
|
post_install_message:
|
415
429
|
rdoc_options: []
|