vcr 6.1.0 → 6.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0230f475b5c666e17c97d0b81695860d18a54c40d07dccfb82ab63098fc60084
4
- data.tar.gz: b79ad4ff6425ef66da8810b75f9cdc787d656c97cb5d60acf31c9ba09a4b6a5d
3
+ metadata.gz: 902881c25780fa44253365c8f5fd0bb260510d7f754287d74a70275abc2dabce
4
+ data.tar.gz: fe52ddaa831a711b7415c350205a2662e833de2c4a6d58b8b6539170645bd218
5
5
  SHA512:
6
- metadata.gz: 22d462bea8b4048575d82db89ecc36327be825267d76f69fa366ca98894b691210b6e859f4ab7d7acaf5fef537749b010ea166dcb09af642677bf402d6aaf855
7
- data.tar.gz: 9f2a224345cabd78d03c0ac5f687b6261c7e1e34fe64c24dca7c4c46057de6122ec74d58c11ff3e3aefb8cc848efda899441c65c3d7dd0bdad86fbcccda9163d
6
+ metadata.gz: f79ffb02f15e691a1266c3421043a5ee95f3bd35715687137f139b291c490ee87a93351e0526faa0f29c73deba80ba41740f87d0fc9d50793a6b6d4101c7b116
7
+ data.tar.gz: 3e9276ffc9e2a2ae07f4a11054dcb484a324dc18e28a4badaa06df7454db36cfdbfbf38b95aec40c01a15a40cde56fb6cd9868780e50994fc2f554caf86e209a
data/lib/vcr/cassette.rb CHANGED
@@ -46,6 +46,9 @@ module VCR
46
46
  # @return [Boolean, nil] Should outdated interactions be recorded back to file
47
47
  attr_reader :clean_outdated_http_interactions
48
48
 
49
+ # @return [Boolean] Should unused requests be dropped from the cassette?
50
+ attr_reader :drop_unused_requests
51
+
49
52
  # @return [Array<Symbol>] If set, {VCR::Configuration#before_record} and
50
53
  # {VCR::Configuration#before_playback} hooks with a corresponding tag will apply.
51
54
  attr_reader :tags
@@ -176,7 +179,8 @@ module VCR
176
179
  :record, :record_on_error, :erb, :match_requests_on, :re_record_interval, :tag, :tags,
177
180
  :update_content_length_header, :allow_playback_repeats, :allow_unused_http_interactions,
178
181
  :exclusive, :serialize_with, :preserve_exact_body_bytes, :decode_compressed_response,
179
- :recompress_response, :persist_with, :persister_options, :clean_outdated_http_interactions
182
+ :recompress_response, :persist_with, :persister_options, :clean_outdated_http_interactions,
183
+ :drop_unused_requests
180
184
  ]
181
185
 
182
186
  if invalid_options.size > 0
@@ -186,7 +190,7 @@ module VCR
186
190
 
187
191
  def extract_options
188
192
  [:record_on_error, :erb, :match_requests_on, :re_record_interval, :clean_outdated_http_interactions,
189
- :allow_playback_repeats, :allow_unused_http_interactions, :exclusive].each do |name|
193
+ :allow_playback_repeats, :allow_unused_http_interactions, :exclusive, :drop_unused_requests].each do |name|
190
194
  instance_variable_set("@#{name}", @options[name])
191
195
  end
192
196
 
@@ -259,6 +263,10 @@ module VCR
259
263
  record_mode == :all
260
264
  end
261
265
 
266
+ def should_remove_unused_interactions?
267
+ @drop_unused_requests
268
+ end
269
+
262
270
  def should_assert_no_unused_interactions?
263
271
  !(@allow_unused_http_interactions || $!)
264
272
  end
@@ -277,7 +285,11 @@ module VCR
277
285
  end
278
286
  end
279
287
 
280
- up_to_date_interactions(old_interactions) + new_recorded_interactions
288
+ if should_remove_unused_interactions?
289
+ new_recorded_interactions
290
+ else
291
+ up_to_date_interactions(old_interactions) + new_recorded_interactions
292
+ end
281
293
  end
282
294
 
283
295
  def up_to_date_interactions(interactions)
@@ -495,6 +495,7 @@ module VCR
495
495
  :record_on_error => true,
496
496
  :match_requests_on => RequestMatcherRegistry::DEFAULT_MATCHERS,
497
497
  :allow_unused_http_interactions => true,
498
+ :drop_unused_requests => false,
498
499
  :serialize_with => :yaml,
499
500
  :persist_with => :file_system,
500
501
  :persister_options => {}
@@ -45,9 +45,11 @@ module VCR
45
45
  end
46
46
 
47
47
  def handle
48
- # Faraday must be exlusive here in case another library hook is being used.
48
+ # Faraday must be exclusive here in case another library hook is being used.
49
49
  # We don't want double recording/double playback.
50
50
  VCR.library_hooks.exclusive_hook = :faraday
51
+ collect_chunks if env.request.stream_response?
52
+
51
53
  super
52
54
  ensure
53
55
  response = defined?(@vcr_response) ? @vcr_response : nil
@@ -103,6 +105,7 @@ module VCR
103
105
  @vcr_response = stubbed_response
104
106
 
105
107
  faraday_response = ::Faraday::Response.new
108
+ env.request.on_data.call(stubbed_response.body, stubbed_response.body.length) if env.request.stream_response?
106
109
  faraday_response.finish(env)
107
110
  env[:response] = faraday_response
108
111
  end
@@ -111,6 +114,7 @@ module VCR
111
114
  @has_on_complete_hook = true
112
115
  response = app.call(env)
113
116
  response.on_complete do
117
+ restore_body_from_chunks(env.request) if env.request.stream_response?
114
118
  @vcr_response = response_for(response)
115
119
  VCR.record_http_interaction(VCR::HTTPInteraction.new(vcr_request, @vcr_response))
116
120
  invoke_after_request_hook(@vcr_response) if delay_finishing?
@@ -121,6 +125,20 @@ module VCR
121
125
  super
122
126
  VCR.library_hooks.exclusive_hook = nil
123
127
  end
128
+
129
+ def collect_chunks
130
+ caller_on_data = env.request.on_data
131
+ chunks = ''
132
+ env.request.on_data = Proc.new do |chunk, overall_received_bytes|
133
+ chunks += chunk
134
+ env.request.instance_variable_set(:@chunked_body, chunks)
135
+ caller_on_data.call(chunk, overall_received_bytes)
136
+ end
137
+ end
138
+
139
+ def restore_body_from_chunks(request)
140
+ env[:body] = request.instance_variable_get(:@chunked_body)
141
+ end
124
142
  end
125
143
  end
126
144
  end
data/lib/vcr/version.rb CHANGED
@@ -10,7 +10,7 @@ module VCR
10
10
  # * `parts` [Array<Integer>] List of the version parts.
11
11
  def version
12
12
  @version ||= begin
13
- string = +'6.1.0'
13
+ string = +'6.2.0'
14
14
 
15
15
  def string.parts
16
16
  split('.').map { |p| p.to_i }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vcr
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.1.0
4
+ version: 6.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Myron Marston
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2022-03-13 00:00:00.000000000 Z
13
+ date: 2023-06-26 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: bundler
@@ -365,7 +365,7 @@ files:
365
365
  - lib/vcr/util/variable_args_block_caller.rb
366
366
  - lib/vcr/util/version_checker.rb
367
367
  - lib/vcr/version.rb
368
- homepage: https://relishapp.com/vcr/vcr/docs
368
+ homepage: https://benoittgt.github.io/vcr
369
369
  licenses:
370
370
  - Hippocratic-2.1
371
371
  - MIT
@@ -378,14 +378,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
378
378
  requirements:
379
379
  - - ">="
380
380
  - !ruby/object:Gem::Version
381
- version: '2.6'
381
+ version: '2.7'
382
382
  required_rubygems_version: !ruby/object:Gem::Requirement
383
383
  requirements:
384
384
  - - ">="
385
385
  - !ruby/object:Gem::Version
386
386
  version: '0'
387
387
  requirements: []
388
- rubygems_version: 3.2.7
388
+ rubygems_version: 3.4.14
389
389
  signing_key:
390
390
  specification_version: 4
391
391
  summary: Record your test suite's HTTP interactions and replay them during future