vcr 3.0.3 → 6.2.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.
Files changed (146) hide show
  1. checksums.yaml +5 -5
  2. data/lib/vcr/cassette/erb_renderer.rb +4 -2
  3. data/lib/vcr/cassette/http_interaction_list.rb +14 -9
  4. data/lib/vcr/cassette/migrator.rb +5 -6
  5. data/lib/vcr/cassette/persisters/file_system.rb +9 -1
  6. data/lib/vcr/cassette/serializers/compressed.rb +2 -2
  7. data/lib/vcr/cassette/serializers/json.rb +14 -8
  8. data/lib/vcr/cassette/serializers/psych.rb +10 -2
  9. data/lib/vcr/cassette/serializers/syck.rb +7 -1
  10. data/lib/vcr/cassette/serializers/yaml.rb +14 -2
  11. data/lib/vcr/cassette/serializers.rb +10 -0
  12. data/lib/vcr/cassette.rb +63 -16
  13. data/lib/vcr/configuration.rb +21 -8
  14. data/lib/vcr/deprecations.rb +0 -62
  15. data/lib/vcr/errors.rb +17 -12
  16. data/lib/vcr/library_hooks/excon.rb +8 -0
  17. data/lib/vcr/library_hooks/typhoeus.rb +91 -79
  18. data/lib/vcr/library_hooks/webmock.rb +2 -11
  19. data/lib/vcr/linked_cassette.rb +4 -4
  20. data/lib/vcr/middleware/excon.rb +1 -1
  21. data/lib/vcr/middleware/faraday.rb +29 -2
  22. data/lib/vcr/request_ignorer.rb +8 -1
  23. data/lib/vcr/request_matcher_registry.rb +3 -3
  24. data/lib/vcr/structs.rb +48 -32
  25. data/lib/vcr/test_frameworks/cucumber.rb +16 -5
  26. data/lib/vcr/test_frameworks/rspec.rb +34 -22
  27. data/lib/vcr/util/hooks.rb +1 -0
  28. data/lib/vcr/util/internet_connection.rb +15 -21
  29. data/lib/vcr/version.rb +2 -2
  30. data/lib/vcr.rb +52 -2
  31. metadata +45 -272
  32. data/features/CHANGELOG.md +0 -710
  33. data/features/CONTRIBUTING.md +0 -26
  34. data/features/LICENSE.md +0 -20
  35. data/features/README.md +0 -339
  36. data/features/Upgrade.md +0 -289
  37. data/features/about_these_examples.md +0 -18
  38. data/features/cassettes/allow_unused_http_interactions.feature +0 -100
  39. data/features/cassettes/automatic_re_recording.feature +0 -72
  40. data/features/cassettes/decompress.feature +0 -74
  41. data/features/cassettes/dynamic_erb.feature +0 -100
  42. data/features/cassettes/exclusive.feature +0 -126
  43. data/features/cassettes/format.feature +0 -411
  44. data/features/cassettes/freezing_time.feature +0 -68
  45. data/features/cassettes/naming.feature +0 -28
  46. data/features/cassettes/no_cassette.feature +0 -152
  47. data/features/cassettes/update_content_length_header.feature +0 -112
  48. data/features/configuration/allow_http_connections_when_no_cassette.feature +0 -55
  49. data/features/configuration/cassette_library_dir.feature +0 -31
  50. data/features/configuration/debug_logging.feature +0 -58
  51. data/features/configuration/default_cassette_options.feature +0 -100
  52. data/features/configuration/filter_sensitive_data.feature +0 -153
  53. data/features/configuration/hook_into.feature +0 -172
  54. data/features/configuration/ignore_request.feature +0 -192
  55. data/features/configuration/preserve_exact_body_bytes.feature +0 -108
  56. data/features/configuration/query_parser.feature +0 -84
  57. data/features/configuration/uri_parser.feature +0 -93
  58. data/features/getting_started.md +0 -82
  59. data/features/hooks/after_http_request.feature +0 -58
  60. data/features/hooks/around_http_request.feature +0 -57
  61. data/features/hooks/before_http_request.feature +0 -63
  62. data/features/hooks/before_playback.feature +0 -184
  63. data/features/hooks/before_record.feature +0 -172
  64. data/features/http_libraries/em_http_request.feature +0 -250
  65. data/features/http_libraries/net_http.feature +0 -179
  66. data/features/middleware/faraday.feature +0 -56
  67. data/features/middleware/rack.feature +0 -92
  68. data/features/record_modes/all.feature +0 -82
  69. data/features/record_modes/new_episodes.feature +0 -79
  70. data/features/record_modes/none.feature +0 -72
  71. data/features/record_modes/once.feature +0 -95
  72. data/features/request_matching/README.md +0 -30
  73. data/features/request_matching/body.feature +0 -91
  74. data/features/request_matching/body_as_json.feature +0 -90
  75. data/features/request_matching/custom_matcher.feature +0 -135
  76. data/features/request_matching/headers.feature +0 -85
  77. data/features/request_matching/host.feature +0 -95
  78. data/features/request_matching/identical_request_sequence.feature +0 -89
  79. data/features/request_matching/method.feature +0 -96
  80. data/features/request_matching/path.feature +0 -96
  81. data/features/request_matching/playback_repeats.feature +0 -98
  82. data/features/request_matching/query.feature +0 -97
  83. data/features/request_matching/uri.feature +0 -94
  84. data/features/request_matching/uri_without_param.feature +0 -101
  85. data/features/step_definitions/cli_steps.rb +0 -199
  86. data/features/support/env.rb +0 -46
  87. data/features/support/http_lib_filters.rb +0 -46
  88. data/features/test_frameworks/cucumber.feature +0 -211
  89. data/features/test_frameworks/rspec_macro.feature +0 -81
  90. data/features/test_frameworks/rspec_metadata.feature +0 -150
  91. data/features/test_frameworks/test_unit.feature +0 -49
  92. data/lib/vcr/extensions/net_http_response.rb +0 -36
  93. data/lib/vcr/library_hooks/fakeweb.rb +0 -197
  94. data/lib/vcr/library_hooks/typhoeus_0.4.rb +0 -103
  95. data/spec/acceptance/concurrency_spec.rb +0 -51
  96. data/spec/acceptance/threading_spec.rb +0 -34
  97. data/spec/fixtures/cassette_spec/1_x_cassette.yml +0 -110
  98. data/spec/fixtures/cassette_spec/empty.yml +0 -0
  99. data/spec/fixtures/cassette_spec/example.yml +0 -111
  100. data/spec/fixtures/cassette_spec/with_localhost_requests.yml +0 -111
  101. data/spec/fixtures/fake_example_responses.yml +0 -110
  102. data/spec/fixtures/match_requests_on.yml +0 -187
  103. data/spec/lib/vcr/cassette/erb_renderer_spec.rb +0 -53
  104. data/spec/lib/vcr/cassette/http_interaction_list_spec.rb +0 -295
  105. data/spec/lib/vcr/cassette/migrator_spec.rb +0 -196
  106. data/spec/lib/vcr/cassette/persisters/file_system_spec.rb +0 -75
  107. data/spec/lib/vcr/cassette/persisters_spec.rb +0 -39
  108. data/spec/lib/vcr/cassette/serializers_spec.rb +0 -182
  109. data/spec/lib/vcr/cassette_spec.rb +0 -618
  110. data/spec/lib/vcr/configuration_spec.rb +0 -326
  111. data/spec/lib/vcr/deprecations_spec.rb +0 -85
  112. data/spec/lib/vcr/errors_spec.rb +0 -178
  113. data/spec/lib/vcr/extensions/net_http_response_spec.rb +0 -86
  114. data/spec/lib/vcr/library_hooks/excon_spec.rb +0 -104
  115. data/spec/lib/vcr/library_hooks/fakeweb_spec.rb +0 -169
  116. data/spec/lib/vcr/library_hooks/faraday_spec.rb +0 -68
  117. data/spec/lib/vcr/library_hooks/typhoeus_0.4_spec.rb +0 -36
  118. data/spec/lib/vcr/library_hooks/typhoeus_spec.rb +0 -162
  119. data/spec/lib/vcr/library_hooks/webmock_spec.rb +0 -117
  120. data/spec/lib/vcr/library_hooks_spec.rb +0 -51
  121. data/spec/lib/vcr/middleware/faraday_spec.rb +0 -181
  122. data/spec/lib/vcr/middleware/rack_spec.rb +0 -115
  123. data/spec/lib/vcr/request_ignorer_spec.rb +0 -70
  124. data/spec/lib/vcr/request_matcher_registry_spec.rb +0 -345
  125. data/spec/lib/vcr/structs_spec.rb +0 -732
  126. data/spec/lib/vcr/test_frameworks/cucumber_spec.rb +0 -107
  127. data/spec/lib/vcr/test_frameworks/rspec_spec.rb +0 -94
  128. data/spec/lib/vcr/util/hooks_spec.rb +0 -158
  129. data/spec/lib/vcr/util/internet_connection_spec.rb +0 -37
  130. data/spec/lib/vcr/util/version_checker_spec.rb +0 -31
  131. data/spec/lib/vcr/version_spec.rb +0 -27
  132. data/spec/lib/vcr_spec.rb +0 -354
  133. data/spec/monkey_patches.rb +0 -186
  134. data/spec/spec_helper.rb +0 -63
  135. data/spec/support/configuration_stubbing.rb +0 -8
  136. data/spec/support/cucumber_helpers.rb +0 -39
  137. data/spec/support/fixnum_extension.rb +0 -10
  138. data/spec/support/http_library_adapters.rb +0 -289
  139. data/spec/support/limited_uri.rb +0 -21
  140. data/spec/support/ruby_interpreter.rb +0 -7
  141. data/spec/support/shared_example_groups/excon.rb +0 -63
  142. data/spec/support/shared_example_groups/hook_into_http_library.rb +0 -594
  143. data/spec/support/shared_example_groups/request_hooks.rb +0 -59
  144. data/spec/support/sinatra_app.rb +0 -86
  145. data/spec/support/vcr_localhost_server.rb +0 -76
  146. data/spec/support/vcr_stub_helpers.rb +0 -17
@@ -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
-
@@ -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,7 +0,0 @@
1
- RUBY_INTERPRETER = if RUBY_PLATFORM == 'java'
2
- :jruby
3
- elsif defined?(RUBY_ENGINE) && RUBY_ENGINE == 'rbx'
4
- :rubinius
5
- else
6
- :mri
7
- 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
-