ultra-pure-gem 0.0.1
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/ultra-pure-gem.gemspec +12 -0
- data/webmock-3.26.2/CHANGELOG.md +2148 -0
- data/webmock-3.26.2/LICENSE +20 -0
- data/webmock-3.26.2/README.md +1229 -0
- data/webmock-3.26.2/lib/webmock/api.rb +111 -0
- data/webmock-3.26.2/lib/webmock/assertion_failure.rb +13 -0
- data/webmock-3.26.2/lib/webmock/callback_registry.rb +37 -0
- data/webmock-3.26.2/lib/webmock/config.rb +20 -0
- data/webmock-3.26.2/lib/webmock/cucumber.rb +12 -0
- data/webmock-3.26.2/lib/webmock/deprecation.rb +11 -0
- data/webmock-3.26.2/lib/webmock/errors.rb +19 -0
- data/webmock-3.26.2/lib/webmock/http_lib_adapters/async_http_client_adapter.rb +228 -0
- data/webmock-3.26.2/lib/webmock/http_lib_adapters/curb_adapter.rb +354 -0
- data/webmock-3.26.2/lib/webmock/http_lib_adapters/em_http_request_adapter.rb +239 -0
- data/webmock-3.26.2/lib/webmock/http_lib_adapters/excon_adapter.rb +167 -0
- data/webmock-3.26.2/lib/webmock/http_lib_adapters/http_lib_adapter.rb +9 -0
- data/webmock-3.26.2/lib/webmock/http_lib_adapters/http_lib_adapter_registry.rb +21 -0
- data/webmock-3.26.2/lib/webmock/http_lib_adapters/http_rb/client.rb +17 -0
- data/webmock-3.26.2/lib/webmock/http_lib_adapters/http_rb/request.rb +28 -0
- data/webmock-3.26.2/lib/webmock/http_lib_adapters/http_rb/response.rb +95 -0
- data/webmock-3.26.2/lib/webmock/http_lib_adapters/http_rb/streamer.rb +44 -0
- data/webmock-3.26.2/lib/webmock/http_lib_adapters/http_rb/webmock.rb +77 -0
- data/webmock-3.26.2/lib/webmock/http_lib_adapters/http_rb_adapter.rb +39 -0
- data/webmock-3.26.2/lib/webmock/http_lib_adapters/httpclient_adapter.rb +260 -0
- data/webmock-3.26.2/lib/webmock/http_lib_adapters/manticore_adapter.rb +147 -0
- data/webmock-3.26.2/lib/webmock/http_lib_adapters/net_http.rb +310 -0
- data/webmock-3.26.2/lib/webmock/http_lib_adapters/net_http_response.rb +36 -0
- data/webmock-3.26.2/lib/webmock/http_lib_adapters/patron_adapter.rb +132 -0
- data/webmock-3.26.2/lib/webmock/http_lib_adapters/typhoeus_hydra_adapter.rb +190 -0
- data/webmock-3.26.2/lib/webmock/matchers/any_arg_matcher.rb +15 -0
- data/webmock-3.26.2/lib/webmock/matchers/hash_argument_matcher.rb +23 -0
- data/webmock-3.26.2/lib/webmock/matchers/hash_excluding_matcher.rb +17 -0
- data/webmock-3.26.2/lib/webmock/matchers/hash_including_matcher.rb +19 -0
- data/webmock-3.26.2/lib/webmock/minitest.rb +43 -0
- data/webmock-3.26.2/lib/webmock/rack_response.rb +73 -0
- data/webmock-3.26.2/lib/webmock/request_body_diff.rb +66 -0
- data/webmock-3.26.2/lib/webmock/request_execution_verifier.rb +79 -0
- data/webmock-3.26.2/lib/webmock/request_pattern.rb +428 -0
- data/webmock-3.26.2/lib/webmock/request_registry.rb +37 -0
- data/webmock-3.26.2/lib/webmock/request_signature.rb +56 -0
- data/webmock-3.26.2/lib/webmock/request_signature_snippet.rb +63 -0
- data/webmock-3.26.2/lib/webmock/request_stub.rb +134 -0
- data/webmock-3.26.2/lib/webmock/response.rb +161 -0
- data/webmock-3.26.2/lib/webmock/responses_sequence.rb +42 -0
- data/webmock-3.26.2/lib/webmock/rspec/matchers/request_pattern_matcher.rb +80 -0
- data/webmock-3.26.2/lib/webmock/rspec/matchers/webmock_matcher.rb +69 -0
- data/webmock-3.26.2/lib/webmock/rspec/matchers.rb +29 -0
- data/webmock-3.26.2/lib/webmock/rspec.rb +44 -0
- data/webmock-3.26.2/lib/webmock/stub_registry.rb +84 -0
- data/webmock-3.26.2/lib/webmock/stub_request_snippet.rb +40 -0
- data/webmock-3.26.2/lib/webmock/test_unit.rb +22 -0
- data/webmock-3.26.2/lib/webmock/util/hash_counter.rb +45 -0
- data/webmock-3.26.2/lib/webmock/util/hash_keys_stringifier.rb +27 -0
- data/webmock-3.26.2/lib/webmock/util/hash_validator.rb +19 -0
- data/webmock-3.26.2/lib/webmock/util/headers.rb +77 -0
- data/webmock-3.26.2/lib/webmock/util/parsers/json.rb +72 -0
- data/webmock-3.26.2/lib/webmock/util/parsers/parse_error.rb +7 -0
- data/webmock-3.26.2/lib/webmock/util/parsers/xml.rb +16 -0
- data/webmock-3.26.2/lib/webmock/util/query_mapper.rb +283 -0
- data/webmock-3.26.2/lib/webmock/util/uri.rb +113 -0
- data/webmock-3.26.2/lib/webmock/util/values_stringifier.rb +22 -0
- data/webmock-3.26.2/lib/webmock/util/version_checker.rb +113 -0
- data/webmock-3.26.2/lib/webmock/version.rb +5 -0
- data/webmock-3.26.2/lib/webmock/webmock.rb +175 -0
- data/webmock-3.26.2/lib/webmock.rb +61 -0
- metadata +106 -0
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module WebMock
|
|
4
|
+
module API
|
|
5
|
+
extend self
|
|
6
|
+
|
|
7
|
+
def stub_request(method, uri)
|
|
8
|
+
WebMock::StubRegistry.instance.
|
|
9
|
+
register_request_stub(WebMock::RequestStub.new(method, uri))
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
alias_method :stub_http_request, :stub_request
|
|
13
|
+
|
|
14
|
+
def a_request(method, uri)
|
|
15
|
+
WebMock::RequestPattern.new(method, uri)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
class << self
|
|
19
|
+
alias :request :a_request
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def assert_requested(*args, &block)
|
|
23
|
+
if not args[0].is_a?(WebMock::RequestStub)
|
|
24
|
+
args = convert_uri_method_and_options_to_request_and_options(args[0], args[1], args[2], &block)
|
|
25
|
+
elsif block
|
|
26
|
+
raise ArgumentError, "assert_requested with a stub object, doesn't accept blocks"
|
|
27
|
+
end
|
|
28
|
+
assert_request_requested(*args)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def assert_not_requested(*args, &block)
|
|
32
|
+
if not args[0].is_a?(WebMock::RequestStub)
|
|
33
|
+
args = convert_uri_method_and_options_to_request_and_options(args[0], args[1], args[2], &block)
|
|
34
|
+
elsif block
|
|
35
|
+
raise ArgumentError, "assert_not_requested with a stub object, doesn't accept blocks"
|
|
36
|
+
end
|
|
37
|
+
assert_request_not_requested(*args)
|
|
38
|
+
end
|
|
39
|
+
alias refute_requested assert_not_requested
|
|
40
|
+
|
|
41
|
+
# Similar to RSpec::Mocks::ArgumentMatchers#hash_including()
|
|
42
|
+
#
|
|
43
|
+
# Matches a hash that includes the specified key(s) or key/value pairs.
|
|
44
|
+
# Ignores any additional keys.
|
|
45
|
+
#
|
|
46
|
+
# @example
|
|
47
|
+
#
|
|
48
|
+
# object.should_receive(:message).with(hash_including(:key => val))
|
|
49
|
+
# object.should_receive(:message).with(hash_including(:key))
|
|
50
|
+
# object.should_receive(:message).with(hash_including(:key, :key2 => val2))
|
|
51
|
+
def hash_including(*args)
|
|
52
|
+
if defined?(super)
|
|
53
|
+
super
|
|
54
|
+
else
|
|
55
|
+
WebMock::Matchers::HashIncludingMatcher.new(anythingize_lonely_keys(*args))
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def hash_excluding(*args)
|
|
60
|
+
if defined?(super)
|
|
61
|
+
super
|
|
62
|
+
else
|
|
63
|
+
WebMock::Matchers::HashExcludingMatcher.new(anythingize_lonely_keys(*args))
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def remove_request_stub(stub)
|
|
68
|
+
WebMock::StubRegistry.instance.remove_request_stub(stub)
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def reset_executed_requests!
|
|
72
|
+
WebMock::RequestRegistry.instance.reset!
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
private
|
|
76
|
+
|
|
77
|
+
def convert_uri_method_and_options_to_request_and_options(method, uri, options, &block)
|
|
78
|
+
options ||= {}
|
|
79
|
+
options_for_pattern = options.dup
|
|
80
|
+
[:times, :at_least_times, :at_most_times].each { |key| options_for_pattern.delete(key) }
|
|
81
|
+
request = WebMock::RequestPattern.new(method, uri, options_for_pattern)
|
|
82
|
+
request = request.with(&block) if block
|
|
83
|
+
[request, options]
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
def assert_request_requested(request, options = {})
|
|
87
|
+
times = options.delete(:times)
|
|
88
|
+
at_least_times = options.delete(:at_least_times)
|
|
89
|
+
at_most_times = options.delete(:at_most_times)
|
|
90
|
+
times = 1 if times.nil? && at_least_times.nil? && at_most_times.nil?
|
|
91
|
+
verifier = WebMock::RequestExecutionVerifier.new(request, times, at_least_times, at_most_times)
|
|
92
|
+
WebMock::AssertionFailure.failure(verifier.failure_message) unless verifier.matches?
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
def assert_request_not_requested(request, options = {})
|
|
96
|
+
times = options.delete(:times)
|
|
97
|
+
at_least_times = options.delete(:at_least_times)
|
|
98
|
+
at_most_times = options.delete(:at_most_times)
|
|
99
|
+
verifier = WebMock::RequestExecutionVerifier.new(request, times, at_least_times, at_most_times)
|
|
100
|
+
WebMock::AssertionFailure.failure(verifier.failure_message_when_negated) unless verifier.does_not_match?
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
#this is a based on RSpec::Mocks::ArgumentMatchers#anythingize_lonely_keys
|
|
104
|
+
def anythingize_lonely_keys(*args)
|
|
105
|
+
hash = args.last.class == Hash ? args.delete_at(-1) : {}
|
|
106
|
+
args.each { | arg | hash[arg] = WebMock::Matchers::AnyArgMatcher.new(nil) }
|
|
107
|
+
hash
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
end
|
|
111
|
+
end
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module WebMock
|
|
4
|
+
class CallbackRegistry
|
|
5
|
+
@@callbacks = []
|
|
6
|
+
|
|
7
|
+
def self.add_callback(options, block)
|
|
8
|
+
@@callbacks << {options: options, block: block}
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def self.callbacks
|
|
12
|
+
@@callbacks
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def self.invoke_callbacks(options, request_signature, response)
|
|
16
|
+
return if @@callbacks.empty?
|
|
17
|
+
CallbackRegistry.callbacks.each do |callback|
|
|
18
|
+
except = callback[:options][:except]
|
|
19
|
+
real_only = callback[:options][:real_requests_only]
|
|
20
|
+
unless except && except.include?(options[:lib])
|
|
21
|
+
if !real_only || options[:real_request]
|
|
22
|
+
callback[:block].call(request_signature, response)
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def self.reset
|
|
29
|
+
@@callbacks = []
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def self.any_callbacks?
|
|
33
|
+
!@@callbacks.empty?
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
end
|
|
37
|
+
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module WebMock
|
|
4
|
+
class Config
|
|
5
|
+
include Singleton
|
|
6
|
+
|
|
7
|
+
def initialize
|
|
8
|
+
@show_stubbing_instructions = true
|
|
9
|
+
@show_body_diff = true
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
attr_accessor :allow_net_connect
|
|
13
|
+
attr_accessor :allow_localhost
|
|
14
|
+
attr_accessor :allow
|
|
15
|
+
attr_accessor :net_http_connect_on_start
|
|
16
|
+
attr_accessor :show_stubbing_instructions
|
|
17
|
+
attr_accessor :query_values_notation
|
|
18
|
+
attr_accessor :show_body_diff
|
|
19
|
+
end
|
|
20
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module WebMock
|
|
4
|
+
|
|
5
|
+
class NetConnectNotAllowedError < Exception
|
|
6
|
+
def initialize(request_signature)
|
|
7
|
+
request_signature_snippet = RequestSignatureSnippet.new(request_signature)
|
|
8
|
+
text = [
|
|
9
|
+
"Real HTTP connections are disabled. Unregistered request: #{request_signature}",
|
|
10
|
+
request_signature_snippet.stubbing_instructions,
|
|
11
|
+
request_signature_snippet.request_stubs,
|
|
12
|
+
"="*60
|
|
13
|
+
].compact.join("\n\n")
|
|
14
|
+
super(text)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
end
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
begin
|
|
4
|
+
require 'async'
|
|
5
|
+
require 'async/http'
|
|
6
|
+
rescue LoadError
|
|
7
|
+
# async-http not found
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
if defined?(Async::HTTP)
|
|
11
|
+
module WebMock
|
|
12
|
+
module HttpLibAdapters
|
|
13
|
+
class AsyncHttpClientAdapter < HttpLibAdapter
|
|
14
|
+
adapter_for :async_http_client
|
|
15
|
+
|
|
16
|
+
OriginalAsyncHttpClient = Async::HTTP::Client unless const_defined?(:OriginalAsyncHttpClient)
|
|
17
|
+
|
|
18
|
+
class << self
|
|
19
|
+
def enable!
|
|
20
|
+
Async::HTTP.send(:remove_const, :Client)
|
|
21
|
+
Async::HTTP.send(:const_set, :Client, Async::HTTP::WebMockClientWrapper)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def disable!
|
|
25
|
+
Async::HTTP.send(:remove_const, :Client)
|
|
26
|
+
Async::HTTP.send(:const_set, :Client, OriginalAsyncHttpClient)
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
module Async
|
|
34
|
+
module HTTP
|
|
35
|
+
class WebMockClientWrapper < Client
|
|
36
|
+
def initialize(
|
|
37
|
+
endpoint,
|
|
38
|
+
protocol: endpoint.protocol,
|
|
39
|
+
scheme: endpoint.scheme,
|
|
40
|
+
authority: endpoint.authority,
|
|
41
|
+
**options
|
|
42
|
+
)
|
|
43
|
+
webmock_endpoint = WebMockEndpoint.new(scheme, authority, protocol)
|
|
44
|
+
|
|
45
|
+
@network_client = WebMockClient.new(endpoint, **options)
|
|
46
|
+
@webmock_client = WebMockClient.new(webmock_endpoint, **options)
|
|
47
|
+
|
|
48
|
+
@endpoint = endpoint
|
|
49
|
+
@scheme = scheme
|
|
50
|
+
@authority = authority
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def call(request)
|
|
54
|
+
request.scheme ||= self.scheme
|
|
55
|
+
request.authority ||= self.authority
|
|
56
|
+
|
|
57
|
+
request_signature = build_request_signature(request)
|
|
58
|
+
WebMock::RequestRegistry.instance.requested_signatures.put(request_signature)
|
|
59
|
+
webmock_response = WebMock::StubRegistry.instance.response_for_request(request_signature)
|
|
60
|
+
net_connect_allowed = WebMock.net_connect_allowed?(request_signature.uri)
|
|
61
|
+
real_request = false
|
|
62
|
+
|
|
63
|
+
if webmock_response
|
|
64
|
+
webmock_response.raise_error_if_any
|
|
65
|
+
raise Async::TimeoutError, 'WebMock timeout error' if webmock_response.should_timeout
|
|
66
|
+
WebMockApplication.add_webmock_response(request, webmock_response)
|
|
67
|
+
response = @webmock_client.call(request)
|
|
68
|
+
elsif net_connect_allowed
|
|
69
|
+
response = @network_client.call(request)
|
|
70
|
+
real_request = true
|
|
71
|
+
else
|
|
72
|
+
raise WebMock::NetConnectNotAllowedError.new(request_signature) unless webmock_response
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
if WebMock::CallbackRegistry.any_callbacks?
|
|
76
|
+
webmock_response ||= build_webmock_response(response)
|
|
77
|
+
WebMock::CallbackRegistry.invoke_callbacks(
|
|
78
|
+
{
|
|
79
|
+
lib: :async_http_client,
|
|
80
|
+
real_request: real_request
|
|
81
|
+
},
|
|
82
|
+
request_signature,
|
|
83
|
+
webmock_response
|
|
84
|
+
)
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
response
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
def close
|
|
91
|
+
@network_client.close
|
|
92
|
+
@webmock_client.close
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
private
|
|
96
|
+
|
|
97
|
+
def build_request_signature(request)
|
|
98
|
+
body = request.read
|
|
99
|
+
request.body = ::Protocol::HTTP::Body::Buffered.wrap(body)
|
|
100
|
+
WebMock::RequestSignature.new(
|
|
101
|
+
request.method.downcase.to_sym,
|
|
102
|
+
"#{request.scheme}://#{request.authority}#{request.path}",
|
|
103
|
+
headers: request.headers.to_h,
|
|
104
|
+
body: body
|
|
105
|
+
)
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
def build_webmock_response(response)
|
|
109
|
+
body = response.read
|
|
110
|
+
response.body = ::Protocol::HTTP::Body::Buffered.wrap(body)
|
|
111
|
+
|
|
112
|
+
webmock_response = WebMock::Response.new
|
|
113
|
+
webmock_response.status = [
|
|
114
|
+
response.status,
|
|
115
|
+
::Protocol::HTTP1::Reason::DESCRIPTIONS[response.status]
|
|
116
|
+
]
|
|
117
|
+
webmock_response.headers = build_webmock_response_headers(response)
|
|
118
|
+
webmock_response.body = body
|
|
119
|
+
webmock_response
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
def build_webmock_response_headers(response)
|
|
123
|
+
response.headers.each.each_with_object({}) do |(k, v), o|
|
|
124
|
+
o[k] ||= []
|
|
125
|
+
o[k] << v
|
|
126
|
+
end
|
|
127
|
+
end
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
class WebMockClient < Client
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
class WebMockEndpoint
|
|
134
|
+
def initialize(scheme, authority, protocol)
|
|
135
|
+
@scheme = scheme
|
|
136
|
+
@authority = authority
|
|
137
|
+
@protocol = protocol
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
attr :scheme, :authority, :protocol
|
|
141
|
+
|
|
142
|
+
def connect
|
|
143
|
+
server_socket, client_socket = create_connected_sockets
|
|
144
|
+
Async(transient: true) do
|
|
145
|
+
accept_socket(server_socket)
|
|
146
|
+
end
|
|
147
|
+
client_socket
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
def inspect
|
|
151
|
+
"\#<#{self.class}> #{scheme}://#{authority} protocol=#{protocol}"
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
private
|
|
155
|
+
|
|
156
|
+
def socket_class
|
|
157
|
+
defined?(Async::IO::Socket) ? Async::IO::Socket : Socket
|
|
158
|
+
end
|
|
159
|
+
|
|
160
|
+
def create_connected_sockets
|
|
161
|
+
pair = begin
|
|
162
|
+
socket_class.pair(Socket::AF_UNIX, Socket::SOCK_STREAM)
|
|
163
|
+
rescue Errno::EAFNOSUPPORT
|
|
164
|
+
socket_class.pair(Socket::AF_INET, Socket::SOCK_STREAM)
|
|
165
|
+
end
|
|
166
|
+
pair.tap do |sockets|
|
|
167
|
+
sockets.each do |socket|
|
|
168
|
+
socket.instance_variable_set :@alpn_protocol, nil
|
|
169
|
+
socket.instance_eval do
|
|
170
|
+
def alpn_protocol
|
|
171
|
+
nil # means HTTP11 will be used for HTTPS
|
|
172
|
+
end
|
|
173
|
+
end
|
|
174
|
+
end
|
|
175
|
+
end
|
|
176
|
+
end
|
|
177
|
+
|
|
178
|
+
def accept_socket(socket)
|
|
179
|
+
server = Async::HTTP::Server.new(WebMockApplication, self)
|
|
180
|
+
server.accept(socket, socket.remote_address)
|
|
181
|
+
end
|
|
182
|
+
end
|
|
183
|
+
|
|
184
|
+
module WebMockApplication
|
|
185
|
+
WEBMOCK_REQUEST_ID_HEADER = 'x-webmock-request-id'.freeze
|
|
186
|
+
|
|
187
|
+
class << self
|
|
188
|
+
def call(request)
|
|
189
|
+
request.read
|
|
190
|
+
webmock_response = get_webmock_response(request)
|
|
191
|
+
build_response(webmock_response)
|
|
192
|
+
end
|
|
193
|
+
|
|
194
|
+
def add_webmock_response(request, webmock_response)
|
|
195
|
+
webmock_request_id = request.object_id.to_s
|
|
196
|
+
request.headers.add(WEBMOCK_REQUEST_ID_HEADER, webmock_request_id)
|
|
197
|
+
webmock_responses[webmock_request_id] = webmock_response
|
|
198
|
+
end
|
|
199
|
+
|
|
200
|
+
def get_webmock_response(request)
|
|
201
|
+
webmock_request_id = request.headers[WEBMOCK_REQUEST_ID_HEADER][0]
|
|
202
|
+
webmock_responses.fetch(webmock_request_id)
|
|
203
|
+
end
|
|
204
|
+
|
|
205
|
+
private
|
|
206
|
+
|
|
207
|
+
def webmock_responses
|
|
208
|
+
@webmock_responses ||= {}
|
|
209
|
+
end
|
|
210
|
+
|
|
211
|
+
def build_response(webmock_response)
|
|
212
|
+
headers = (webmock_response.headers || {}).each_with_object([]) do |(k, value), o|
|
|
213
|
+
Array(value).each do |v|
|
|
214
|
+
o.push [k, v] unless k.downcase == 'content-length' # async-http appends the exact content-length automatically
|
|
215
|
+
end
|
|
216
|
+
end
|
|
217
|
+
|
|
218
|
+
::Protocol::HTTP::Response[
|
|
219
|
+
webmock_response.status[0],
|
|
220
|
+
headers,
|
|
221
|
+
webmock_response.body
|
|
222
|
+
]
|
|
223
|
+
end
|
|
224
|
+
end
|
|
225
|
+
end
|
|
226
|
+
end
|
|
227
|
+
end
|
|
228
|
+
end
|