vcr 3.0.3 → 4.0.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 +4 -4
- data/lib/vcr.rb +18 -1
- data/lib/vcr/cassette.rb +11 -3
- data/lib/vcr/cassette/persisters/file_system.rb +1 -1
- data/lib/vcr/configuration.rb +3 -5
- data/lib/vcr/deprecations.rb +0 -62
- data/lib/vcr/errors.rb +16 -0
- data/lib/vcr/library_hooks/typhoeus.rb +37 -8
- data/lib/vcr/middleware/faraday.rb +5 -1
- data/lib/vcr/structs.rb +1 -1
- data/lib/vcr/util/hooks.rb +1 -0
- data/lib/vcr/version.rb +1 -1
- metadata +9 -249
- data/features/CHANGELOG.md +0 -710
- data/features/CONTRIBUTING.md +0 -26
- data/features/LICENSE.md +0 -20
- data/features/README.md +0 -339
- data/features/Upgrade.md +0 -289
- data/features/about_these_examples.md +0 -18
- data/features/cassettes/allow_unused_http_interactions.feature +0 -100
- data/features/cassettes/automatic_re_recording.feature +0 -72
- data/features/cassettes/decompress.feature +0 -74
- data/features/cassettes/dynamic_erb.feature +0 -100
- data/features/cassettes/exclusive.feature +0 -126
- data/features/cassettes/format.feature +0 -411
- data/features/cassettes/freezing_time.feature +0 -68
- data/features/cassettes/naming.feature +0 -28
- data/features/cassettes/no_cassette.feature +0 -152
- data/features/cassettes/update_content_length_header.feature +0 -112
- data/features/configuration/allow_http_connections_when_no_cassette.feature +0 -55
- data/features/configuration/cassette_library_dir.feature +0 -31
- data/features/configuration/debug_logging.feature +0 -58
- data/features/configuration/default_cassette_options.feature +0 -100
- data/features/configuration/filter_sensitive_data.feature +0 -153
- data/features/configuration/hook_into.feature +0 -172
- data/features/configuration/ignore_request.feature +0 -192
- data/features/configuration/preserve_exact_body_bytes.feature +0 -108
- data/features/configuration/query_parser.feature +0 -84
- data/features/configuration/uri_parser.feature +0 -93
- data/features/getting_started.md +0 -82
- data/features/hooks/after_http_request.feature +0 -58
- data/features/hooks/around_http_request.feature +0 -57
- data/features/hooks/before_http_request.feature +0 -63
- data/features/hooks/before_playback.feature +0 -184
- data/features/hooks/before_record.feature +0 -172
- data/features/http_libraries/em_http_request.feature +0 -250
- data/features/http_libraries/net_http.feature +0 -179
- data/features/middleware/faraday.feature +0 -56
- data/features/middleware/rack.feature +0 -92
- data/features/record_modes/all.feature +0 -82
- data/features/record_modes/new_episodes.feature +0 -79
- data/features/record_modes/none.feature +0 -72
- data/features/record_modes/once.feature +0 -95
- data/features/request_matching/README.md +0 -30
- data/features/request_matching/body.feature +0 -91
- data/features/request_matching/body_as_json.feature +0 -90
- data/features/request_matching/custom_matcher.feature +0 -135
- data/features/request_matching/headers.feature +0 -85
- data/features/request_matching/host.feature +0 -95
- data/features/request_matching/identical_request_sequence.feature +0 -89
- data/features/request_matching/method.feature +0 -96
- data/features/request_matching/path.feature +0 -96
- data/features/request_matching/playback_repeats.feature +0 -98
- data/features/request_matching/query.feature +0 -97
- data/features/request_matching/uri.feature +0 -94
- data/features/request_matching/uri_without_param.feature +0 -101
- data/features/step_definitions/cli_steps.rb +0 -199
- data/features/support/env.rb +0 -46
- data/features/support/http_lib_filters.rb +0 -46
- data/features/test_frameworks/cucumber.feature +0 -211
- data/features/test_frameworks/rspec_macro.feature +0 -81
- data/features/test_frameworks/rspec_metadata.feature +0 -150
- data/features/test_frameworks/test_unit.feature +0 -49
- data/lib/vcr/extensions/net_http_response.rb +0 -36
- data/lib/vcr/library_hooks/fakeweb.rb +0 -197
- data/spec/acceptance/concurrency_spec.rb +0 -51
- data/spec/acceptance/threading_spec.rb +0 -34
- data/spec/fixtures/cassette_spec/1_x_cassette.yml +0 -110
- data/spec/fixtures/cassette_spec/empty.yml +0 -0
- data/spec/fixtures/cassette_spec/example.yml +0 -111
- data/spec/fixtures/cassette_spec/with_localhost_requests.yml +0 -111
- data/spec/fixtures/fake_example_responses.yml +0 -110
- data/spec/fixtures/match_requests_on.yml +0 -187
- data/spec/lib/vcr/cassette/erb_renderer_spec.rb +0 -53
- data/spec/lib/vcr/cassette/http_interaction_list_spec.rb +0 -295
- data/spec/lib/vcr/cassette/migrator_spec.rb +0 -196
- data/spec/lib/vcr/cassette/persisters/file_system_spec.rb +0 -75
- data/spec/lib/vcr/cassette/persisters_spec.rb +0 -39
- data/spec/lib/vcr/cassette/serializers_spec.rb +0 -182
- data/spec/lib/vcr/cassette_spec.rb +0 -618
- data/spec/lib/vcr/configuration_spec.rb +0 -326
- data/spec/lib/vcr/deprecations_spec.rb +0 -85
- data/spec/lib/vcr/errors_spec.rb +0 -178
- data/spec/lib/vcr/extensions/net_http_response_spec.rb +0 -86
- data/spec/lib/vcr/library_hooks/excon_spec.rb +0 -104
- data/spec/lib/vcr/library_hooks/fakeweb_spec.rb +0 -169
- data/spec/lib/vcr/library_hooks/faraday_spec.rb +0 -68
- data/spec/lib/vcr/library_hooks/typhoeus_0.4_spec.rb +0 -36
- data/spec/lib/vcr/library_hooks/typhoeus_spec.rb +0 -162
- data/spec/lib/vcr/library_hooks/webmock_spec.rb +0 -117
- data/spec/lib/vcr/library_hooks_spec.rb +0 -51
- data/spec/lib/vcr/middleware/faraday_spec.rb +0 -181
- data/spec/lib/vcr/middleware/rack_spec.rb +0 -115
- data/spec/lib/vcr/request_ignorer_spec.rb +0 -70
- data/spec/lib/vcr/request_matcher_registry_spec.rb +0 -345
- data/spec/lib/vcr/structs_spec.rb +0 -732
- data/spec/lib/vcr/test_frameworks/cucumber_spec.rb +0 -107
- data/spec/lib/vcr/test_frameworks/rspec_spec.rb +0 -94
- data/spec/lib/vcr/util/hooks_spec.rb +0 -158
- data/spec/lib/vcr/util/internet_connection_spec.rb +0 -37
- data/spec/lib/vcr/util/version_checker_spec.rb +0 -31
- data/spec/lib/vcr/version_spec.rb +0 -27
- data/spec/lib/vcr_spec.rb +0 -354
- data/spec/monkey_patches.rb +0 -186
- data/spec/spec_helper.rb +0 -63
- data/spec/support/configuration_stubbing.rb +0 -8
- data/spec/support/cucumber_helpers.rb +0 -39
- data/spec/support/fixnum_extension.rb +0 -10
- data/spec/support/http_library_adapters.rb +0 -289
- data/spec/support/limited_uri.rb +0 -21
- data/spec/support/ruby_interpreter.rb +0 -7
- data/spec/support/shared_example_groups/excon.rb +0 -63
- data/spec/support/shared_example_groups/hook_into_http_library.rb +0 -594
- data/spec/support/shared_example_groups/request_hooks.rb +0 -59
- data/spec/support/sinatra_app.rb +0 -86
- data/spec/support/vcr_localhost_server.rb +0 -76
- data/spec/support/vcr_stub_helpers.rb +0 -17
data/spec/spec_helper.rb
DELETED
@@ -1,63 +0,0 @@
|
|
1
|
-
require "codeclimate-test-reporter"
|
2
|
-
CodeClimate::TestReporter.start
|
3
|
-
|
4
|
-
require "pry"
|
5
|
-
require "rspec"
|
6
|
-
require "vcr"
|
7
|
-
require "date"
|
8
|
-
require "forwardable"
|
9
|
-
require "uri"
|
10
|
-
require "vcr/util/internet_connection"
|
11
|
-
require_relative "support/fixnum_extension"
|
12
|
-
require_relative "support/limited_uri"
|
13
|
-
require_relative "support/ruby_interpreter"
|
14
|
-
require_relative "support/shared_example_groups/hook_into_http_library"
|
15
|
-
require_relative "support/shared_example_groups/request_hooks"
|
16
|
-
require_relative "support/vcr_stub_helpers"
|
17
|
-
require_relative "support/vcr_localhost_server"
|
18
|
-
require_relative "support/sinatra_app"
|
19
|
-
require_relative "monkey_patches"
|
20
|
-
require_relative "support/http_library_adapters"
|
21
|
-
|
22
|
-
module VCR
|
23
|
-
SPEC_ROOT = File.dirname(File.expand_path('.', __FILE__))
|
24
|
-
|
25
|
-
def reset!(hook = :fakeweb)
|
26
|
-
instance_variables.each do |ivar|
|
27
|
-
instance_variable_set(ivar, nil)
|
28
|
-
end
|
29
|
-
initialize_ivars
|
30
|
-
configuration.hook_into hook if hook
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
RSpec.configure do |config|
|
35
|
-
tmp_dir = File.expand_path('../../tmp/cassette_library_dir', __FILE__)
|
36
|
-
config.before(:each) do |example|
|
37
|
-
unless example.metadata[:skip_vcr_reset]
|
38
|
-
VCR.reset!
|
39
|
-
VCR.configuration.cassette_library_dir = tmp_dir
|
40
|
-
VCR.configuration.uri_parser = LimitedURI
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
config.after(:each) do
|
45
|
-
FileUtils.rm_rf tmp_dir
|
46
|
-
end
|
47
|
-
|
48
|
-
config.before(:all, :disable_warnings => true) do
|
49
|
-
@orig_std_err = $stderr
|
50
|
-
$stderr = StringIO.new
|
51
|
-
end
|
52
|
-
|
53
|
-
config.after(:all, :disable_warnings => true) do
|
54
|
-
$stderr = @orig_std_err
|
55
|
-
end
|
56
|
-
|
57
|
-
config.filter_run :focus => true
|
58
|
-
config.run_all_when_everything_filtered = true
|
59
|
-
|
60
|
-
config.alias_it_should_behave_like_to :it_performs, 'it performs'
|
61
|
-
end
|
62
|
-
|
63
|
-
VCR::SinatraApp.boot
|
@@ -1,39 +0,0 @@
|
|
1
|
-
require "rubygems"
|
2
|
-
require "vcr"
|
3
|
-
require "support/fixnum_extension"
|
4
|
-
|
5
|
-
module Gem
|
6
|
-
def self.win_platform?() false end
|
7
|
-
end unless defined?(Gem)
|
8
|
-
|
9
|
-
# pretend we're always on the internet (so that we don't have an
|
10
|
-
# internet connection dependency for our cukes)
|
11
|
-
VCR::InternetConnection.class_eval do
|
12
|
-
def available?; true; end
|
13
|
-
end
|
14
|
-
|
15
|
-
if ENV['DATE_STRING']
|
16
|
-
require 'timecop'
|
17
|
-
Timecop.travel(Date.parse(ENV['DATE_STRING']))
|
18
|
-
end
|
19
|
-
|
20
|
-
def include_http_adapter_for(lib)
|
21
|
-
require((lib =~ /faraday/) ? 'faraday' : lib)
|
22
|
-
require 'typhoeus' if lib.include?('typhoeus') # for faraday-typhoeus
|
23
|
-
require 'support/http_library_adapters'
|
24
|
-
include HTTP_LIBRARY_ADAPTERS[lib]
|
25
|
-
end
|
26
|
-
|
27
|
-
def response_body_for(*args)
|
28
|
-
get_body_string(make_http_request(*args))
|
29
|
-
end
|
30
|
-
|
31
|
-
def start_sinatra_app(&block)
|
32
|
-
require 'sinatra/base'
|
33
|
-
require 'support/vcr_localhost_server'
|
34
|
-
klass = Class.new(Sinatra::Base)
|
35
|
-
klass.disable :protection
|
36
|
-
klass.class_eval(&block)
|
37
|
-
|
38
|
-
VCR::LocalhostServer.new(klass.new)
|
39
|
-
end
|
@@ -1,289 +0,0 @@
|
|
1
|
-
module HeaderDowncaser
|
2
|
-
def downcase_headers(headers)
|
3
|
-
{}.tap do |downcased|
|
4
|
-
headers.each do |k, v|
|
5
|
-
downcased[k.downcase] = v
|
6
|
-
end
|
7
|
-
end
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
HTTP_LIBRARY_ADAPTERS = {}
|
12
|
-
|
13
|
-
HTTP_LIBRARY_ADAPTERS['net/http'] = Module.new do
|
14
|
-
include HeaderDowncaser
|
15
|
-
|
16
|
-
def self.http_library_name; 'Net::HTTP'; end
|
17
|
-
|
18
|
-
def get_body_string(response); response.body; end
|
19
|
-
alias get_body_object get_body_string
|
20
|
-
|
21
|
-
def get_header(header_key, response)
|
22
|
-
response.get_fields(header_key)
|
23
|
-
end
|
24
|
-
|
25
|
-
def make_http_request(method, url, body = nil, headers = {})
|
26
|
-
uri = URI.parse(url)
|
27
|
-
http = Net::HTTP.new(uri.host, uri.port)
|
28
|
-
|
29
|
-
if uri.scheme == "https"
|
30
|
-
http.use_ssl = true
|
31
|
-
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
32
|
-
end
|
33
|
-
|
34
|
-
http.send_request(method.to_s.upcase, uri.request_uri, body, headers)
|
35
|
-
end
|
36
|
-
|
37
|
-
DEFAULT_REQUEST_HEADERS = { "Accept"=>["*/*"] }
|
38
|
-
DEFAULT_REQUEST_HEADERS['User-Agent'] = ["Ruby"] if RUBY_VERSION.to_f > 1.8
|
39
|
-
DEFAULT_REQUEST_HEADERS['Accept-Encoding'] = ["gzip;q=1.0,deflate;q=0.6,identity;q=0.3"] if RUBY_VERSION.to_f > 1.9
|
40
|
-
|
41
|
-
def normalize_request_headers(headers)
|
42
|
-
defined?(super) ? super :
|
43
|
-
downcase_headers(headers.merge(DEFAULT_REQUEST_HEADERS))
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
HTTP_LIBRARY_ADAPTERS['patron'] = Module.new do
|
48
|
-
def self.http_library_name; 'Patron'; end
|
49
|
-
|
50
|
-
def get_body_string(response); response.body; end
|
51
|
-
alias get_body_object get_body_string
|
52
|
-
|
53
|
-
def get_header(header_key, response)
|
54
|
-
response.headers[header_key]
|
55
|
-
end
|
56
|
-
|
57
|
-
def make_http_request(method, url, body = nil, headers = {})
|
58
|
-
Patron::Session.new.request(method, url, headers, :data => body || '')
|
59
|
-
end
|
60
|
-
|
61
|
-
def normalize_request_headers(headers)
|
62
|
-
headers.merge('Expect' => [''])
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
HTTP_LIBRARY_ADAPTERS['httpclient'] = Module.new do
|
67
|
-
def self.http_library_name; 'HTTP Client'; end
|
68
|
-
|
69
|
-
def get_body_string(response)
|
70
|
-
body = response.body
|
71
|
-
string = body.is_a?(String) ? body : body.content
|
72
|
-
string.respond_to?(:read) ? string.read : string
|
73
|
-
end
|
74
|
-
|
75
|
-
def get_body_object(response)
|
76
|
-
response.body
|
77
|
-
end
|
78
|
-
|
79
|
-
def get_header(header_key, response)
|
80
|
-
response.header[header_key]
|
81
|
-
end
|
82
|
-
|
83
|
-
def make_http_request(method, url, body = nil, headers = {})
|
84
|
-
HTTPClient.new.request(method, url, nil, body, headers)
|
85
|
-
end
|
86
|
-
|
87
|
-
def normalize_request_headers(headers)
|
88
|
-
headers.merge({
|
89
|
-
'Accept' => ["*/*"],
|
90
|
-
'User-Agent' => ["HTTPClient/1.0 (#{HTTPClient::VERSION}, ruby #{RUBY_VERSION} (#{RUBY_RELEASE_DATE}))"],
|
91
|
-
'Date' => [Time.now.httpdate]
|
92
|
-
})
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
HTTP_LIBRARY_ADAPTERS['em-http-request'] = Module.new do
|
97
|
-
def self.http_library_name; 'EM HTTP Request'; end
|
98
|
-
|
99
|
-
def get_body_string(response)
|
100
|
-
response.response
|
101
|
-
end
|
102
|
-
alias get_body_object get_body_string
|
103
|
-
|
104
|
-
def get_header(header_key, response)
|
105
|
-
values = response.response_header[header_key.upcase.gsub('-', '_')]
|
106
|
-
values.is_a?(Array) ? values : values.split(', ')
|
107
|
-
end
|
108
|
-
|
109
|
-
def make_http_request(method, url, body = nil, headers = {})
|
110
|
-
http = nil
|
111
|
-
EventMachine.run do
|
112
|
-
http = EventMachine::HttpRequest.new(url).send(method, :body => body, :head => headers)
|
113
|
-
http.callback { EventMachine.stop }
|
114
|
-
end
|
115
|
-
http
|
116
|
-
end
|
117
|
-
|
118
|
-
def normalize_request_headers(headers)
|
119
|
-
headers
|
120
|
-
end
|
121
|
-
end
|
122
|
-
|
123
|
-
HTTP_LIBRARY_ADAPTERS['curb'] = Module.new do
|
124
|
-
def self.http_library_name; "Curb"; end
|
125
|
-
|
126
|
-
def get_body_string(response)
|
127
|
-
response.body_str
|
128
|
-
end
|
129
|
-
alias get_body_object get_body_string
|
130
|
-
|
131
|
-
def get_header(header_key, response)
|
132
|
-
headers = response.header_str.split("\r\n")[1..-1]
|
133
|
-
value = nil
|
134
|
-
headers.each do |h|
|
135
|
-
next unless h =~ /^#{Regexp.escape(header_key)}: (.*)$/
|
136
|
-
new_value = $1.split(', ')
|
137
|
-
value = value ? Array(value) + Array(new_value) : new_value
|
138
|
-
end
|
139
|
-
value
|
140
|
-
end
|
141
|
-
|
142
|
-
def make_http_request(method, url, body = nil, headers = {})
|
143
|
-
Curl::Easy.new(url) do |c|
|
144
|
-
c.headers = headers
|
145
|
-
|
146
|
-
if [:post, :put].include?(method)
|
147
|
-
c.send("http_#{method}", body)
|
148
|
-
else
|
149
|
-
c.send("http_#{method}")
|
150
|
-
end
|
151
|
-
end
|
152
|
-
end
|
153
|
-
|
154
|
-
def normalize_request_headers(headers)
|
155
|
-
headers
|
156
|
-
end
|
157
|
-
end
|
158
|
-
|
159
|
-
HTTP_LIBRARY_ADAPTERS['typhoeus'] = Module.new do
|
160
|
-
def self.http_library_name; "Typhoeus"; end
|
161
|
-
|
162
|
-
def get_body_string(response)
|
163
|
-
response.body
|
164
|
-
end
|
165
|
-
alias get_body_object get_body_string
|
166
|
-
|
167
|
-
def get_header(header_key, response)
|
168
|
-
# Due to https://github.com/typhoeus/typhoeus/commit/256c95473d5d40d7ec2f5db603687323ddd73689
|
169
|
-
# headers are now downcased.
|
170
|
-
# ...except when they're not. I'm not 100% why (I haven't had time to dig into it yet)
|
171
|
-
# but in some situations the headers aren't downcased. I think it has to do with playback; VCR
|
172
|
-
# isn't sending the headers in downcased to typhoeus. It gets complicated with the interaction
|
173
|
-
# w/ WebMock, and the fact that webmock normalizes headers in a different fashion.
|
174
|
-
#
|
175
|
-
# For now this hack works.
|
176
|
-
response.headers.fetch(header_key.downcase) { response.headers[header_key] }
|
177
|
-
end
|
178
|
-
|
179
|
-
def make_http_request(method, url, body = nil, headers = {})
|
180
|
-
request = Typhoeus::Request.new(url, :method => method, :body => body, :headers => headers)
|
181
|
-
request.run
|
182
|
-
request.response
|
183
|
-
end
|
184
|
-
|
185
|
-
def normalize_request_headers(headers)
|
186
|
-
headers.merge("User-Agent"=>["Typhoeus - https://github.com/typhoeus/typhoeus"])
|
187
|
-
end
|
188
|
-
end
|
189
|
-
|
190
|
-
HTTP_LIBRARY_ADAPTERS['typhoeus 0.4'] = Module.new do
|
191
|
-
def self.http_library_name; "Typhoeus"; end
|
192
|
-
|
193
|
-
def get_body_string(response)
|
194
|
-
response.body
|
195
|
-
end
|
196
|
-
alias get_body_object get_body_string
|
197
|
-
|
198
|
-
def get_header(header_key, response)
|
199
|
-
response.headers_hash[header_key]
|
200
|
-
end
|
201
|
-
|
202
|
-
def make_http_request(method, url, body = nil, headers = {})
|
203
|
-
Typhoeus::Request.send(method, url, :body => body, :headers => headers)
|
204
|
-
end
|
205
|
-
|
206
|
-
def normalize_request_headers(headers)
|
207
|
-
headers
|
208
|
-
end
|
209
|
-
end
|
210
|
-
|
211
|
-
HTTP_LIBRARY_ADAPTERS['excon'] = Module.new do
|
212
|
-
def self.http_library_name; "Excon"; end
|
213
|
-
|
214
|
-
def get_body_string(response)
|
215
|
-
response.body
|
216
|
-
end
|
217
|
-
alias get_body_object get_body_string
|
218
|
-
|
219
|
-
def get_header(header_key, response)
|
220
|
-
response.headers[header_key]
|
221
|
-
end
|
222
|
-
|
223
|
-
def make_http_request(method, url, body = nil, headers = {})
|
224
|
-
# There are multiple ways to use Excon but this is how fog (the main user of excon) uses it:
|
225
|
-
# https://github.com/fog/fog/blob/v1.1.1/lib/fog/aws/rds.rb#L139-147
|
226
|
-
Excon.new(url).request(:method => method.to_s.upcase, :body => body, :headers => headers)
|
227
|
-
end
|
228
|
-
|
229
|
-
def normalize_request_headers(headers)
|
230
|
-
headers.merge('User-Agent' => [Excon::USER_AGENT])
|
231
|
-
end
|
232
|
-
end
|
233
|
-
|
234
|
-
%w[ net_http typhoeus patron ].each do |_faraday_adapter|
|
235
|
-
if _faraday_adapter == 'typhoeus' &&
|
236
|
-
defined?(::Typhoeus::VERSION) &&
|
237
|
-
::Typhoeus::VERSION.to_f >= 0.5
|
238
|
-
require 'typhoeus/adapters/faraday'
|
239
|
-
end
|
240
|
-
|
241
|
-
HTTP_LIBRARY_ADAPTERS["faraday (w/ #{_faraday_adapter})"] = Module.new do
|
242
|
-
class << self; self; end.class_eval do
|
243
|
-
define_method(:http_library_name) do
|
244
|
-
"Faraday (#{_faraday_adapter})"
|
245
|
-
end
|
246
|
-
end
|
247
|
-
|
248
|
-
define_method(:faraday_adapter) { _faraday_adapter.to_sym }
|
249
|
-
|
250
|
-
def get_body_string(response)
|
251
|
-
response.body
|
252
|
-
end
|
253
|
-
alias get_body_object get_body_string
|
254
|
-
|
255
|
-
def get_header(header_key, response)
|
256
|
-
value = response.headers[header_key]
|
257
|
-
value.split(', ') if value
|
258
|
-
end
|
259
|
-
|
260
|
-
def make_http_request(method, url, body = nil, headers = {})
|
261
|
-
url_root, url_rest = split_url(url)
|
262
|
-
|
263
|
-
faraday_connection(url_root).send(method) do |req|
|
264
|
-
req.url url_rest
|
265
|
-
headers.each { |k, v| req[k] = v }
|
266
|
-
req.body = body if body
|
267
|
-
end
|
268
|
-
end
|
269
|
-
|
270
|
-
def split_url(url)
|
271
|
-
uri = URI.parse(url)
|
272
|
-
url_root = "#{uri.scheme}://#{uri.host}:#{uri.port}"
|
273
|
-
rest = url.sub(url_root, '')
|
274
|
-
|
275
|
-
[url_root, rest]
|
276
|
-
end
|
277
|
-
|
278
|
-
def faraday_connection(url_root)
|
279
|
-
Faraday::Connection.new(:url => url_root) do |builder|
|
280
|
-
builder.adapter faraday_adapter
|
281
|
-
end
|
282
|
-
end
|
283
|
-
|
284
|
-
def normalize_request_headers(headers)
|
285
|
-
headers.merge("User-Agent" => ["Faraday v#{Faraday::VERSION}"])
|
286
|
-
end
|
287
|
-
end
|
288
|
-
end
|
289
|
-
|
data/spec/support/limited_uri.rb
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
class LimitedURI
|
2
|
-
extend Forwardable
|
3
|
-
|
4
|
-
def_delegators :@uri, :scheme, :host, :port, :port=, :path, :query, :query=, :to_s
|
5
|
-
|
6
|
-
def initialize(uri)
|
7
|
-
@uri = uri
|
8
|
-
end
|
9
|
-
|
10
|
-
def ==(other)
|
11
|
-
to_s == other.to_s
|
12
|
-
end
|
13
|
-
|
14
|
-
def self.parse(uri)
|
15
|
-
return uri if uri.is_a? LimitedURI
|
16
|
-
return new(uri) if uri.is_a? URI
|
17
|
-
return new(URI.parse(uri)) if uri.is_a? String
|
18
|
-
|
19
|
-
raise URI::InvalidURIError
|
20
|
-
end
|
21
|
-
end
|
@@ -1,63 +0,0 @@
|
|
1
|
-
shared_examples "Excon streaming" do
|
2
|
-
context "when Excon's streaming API is used" do
|
3
|
-
def make_request_to(path)
|
4
|
-
chunks = []
|
5
|
-
|
6
|
-
Excon.get "http://localhost:#{VCR::SinatraApp.port}#{path}", :response_block => lambda { |chunk, remaining_bytes, total_bytes|
|
7
|
-
chunks << chunk
|
8
|
-
}
|
9
|
-
|
10
|
-
chunks.join
|
11
|
-
end
|
12
|
-
|
13
|
-
it 'properly records and plays back the response' do
|
14
|
-
allow(VCR).to receive(:real_http_connections_allowed?).and_return(true)
|
15
|
-
recorded, played_back = [1, 2].map do
|
16
|
-
make_request_to('/foo')
|
17
|
-
end
|
18
|
-
|
19
|
-
expect(recorded).to eq(played_back)
|
20
|
-
expect(recorded).to eq("FOO!")
|
21
|
-
end
|
22
|
-
|
23
|
-
it 'properly records and plays back the response for unexpected status' do
|
24
|
-
allow(VCR).to receive(:real_http_connections_allowed?).and_return(true)
|
25
|
-
recorded, played_back = [1, 2].map do
|
26
|
-
chunks = []
|
27
|
-
|
28
|
-
VCR.use_cassette('excon_streaming_error', :record => :once) do
|
29
|
-
begin
|
30
|
-
Excon.get "http://localhost:#{VCR::SinatraApp.port}/404_not_200", :expects => 200, :response_block => lambda { |chunk, remaining_bytes, total_bytes|
|
31
|
-
chunks << chunk
|
32
|
-
}
|
33
|
-
rescue Excon::Errors::Error => e
|
34
|
-
chunks << e.response.body
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
chunks.join
|
39
|
-
end
|
40
|
-
|
41
|
-
expect(recorded).to eq(played_back)
|
42
|
-
expect(recorded).to eq('404 not 200')
|
43
|
-
end
|
44
|
-
|
45
|
-
context "when a cassette is played back and appended to" do
|
46
|
-
it 'does not allow Excon to mutate the response body in the cassette' do
|
47
|
-
VCR.use_cassette('excon_streaming', :record => :new_episodes) do
|
48
|
-
expect(make_request_to('/')).to eq('GET to root')
|
49
|
-
end
|
50
|
-
|
51
|
-
VCR.use_cassette('excon_streaming', :record => :new_episodes) do
|
52
|
-
expect(make_request_to('/')).to eq('GET to root')
|
53
|
-
expect(make_request_to('/foo')).to eq('FOO!') # so it will save to disk again
|
54
|
-
end
|
55
|
-
|
56
|
-
VCR.use_cassette('excon_streaming', :record => :new_episodes) do
|
57
|
-
expect(make_request_to('/')).to eq('GET to root')
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|