vcr 5.0.0 → 5.1.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: fb0121a881f4d4b1ac0f68b5078f5674f137e07a4a0580b70a438f920c5953db
4
- data.tar.gz: 551623fd6fd0317c2510e1a02c36f6a8c3cac4bba72752ffd31907de0e1bfef9
3
+ metadata.gz: 07fd7ce84552274d7b4da982cb81c3952f41745280274b236a8f4b2d22f99c14
4
+ data.tar.gz: 52291714128b6cf2ae583098b0e8c25acb1335826bfbbd6f4db778bf11996533
5
5
  SHA512:
6
- metadata.gz: d6ad287e1f993836c3adac326228312596935313d65313fb60b07b16a962b0b5b9cff3f74db5200ce21e2c5ba5b6e32da0fd445d73fe7024c35308fecfcdc688
7
- data.tar.gz: bcf77106091efc49ae8ee789f076b162eb28491349a2e04ef0a1220ae5b1cfb3501de2e3106d8aa14459c7577207775650232ebf11235fe110c28dfa16614149
6
+ metadata.gz: fdcf18897a729f367411a486747e318c870e92c8eb5c234ed1948123501938ccd7966b129ef99658cca62ec0d6762b2fc339c1064527c6de731eed1bfdf53c72
7
+ data.tar.gz: 945c7b6cbae5a31ad56d142488dedb69d2554ea2367a157e9693b7771be9fec9e12b74236c3e853b9ab05ffba416bc489055264048b4896efa9030767394a7bb
data/lib/vcr.rb CHANGED
@@ -186,6 +186,9 @@ module VCR
186
186
 
187
187
  begin
188
188
  call_block(block, cassette)
189
+ rescue StandardError
190
+ cassette.run_failed!
191
+ raise
189
192
  ensure
190
193
  eject_cassette
191
194
  end
@@ -308,6 +311,9 @@ module VCR
308
311
  # @see #turn_off!
309
312
  # @see #turned_off
310
313
  def turned_on?
314
+ linked_context = current_context[:linked_context]
315
+ return !linked_context[:turned_off] if linked_context
316
+
311
317
  !context_value(:turned_off)
312
318
  end
313
319
 
@@ -24,6 +24,13 @@ module VCR
24
24
  # plays them back, or does both.
25
25
  attr_reader :record_mode
26
26
 
27
+ # @return [Boolean] The cassette's record_on_error mode. When the code that uses the cassette
28
+ # raises an error (for example a test failure) and record_on_error is set to false, no
29
+ # cassette will be recorded. This is useful when you are TDD'ing an API integration: when
30
+ # an error is raised that often means your request is invalid, so you don't want the cassette
31
+ # to be recorded.
32
+ attr_reader :record_on_error
33
+
27
34
  # @return [Array<Symbol, #call>] List of request matchers. Used to find a response from an
28
35
  # existing HTTP interaction to play back.
29
36
  attr_reader :match_requests_on
@@ -66,13 +73,28 @@ module VCR
66
73
  # @param (see VCR#eject_casssette)
67
74
  # @see VCR#eject_cassette
68
75
  def eject(options = {})
69
- write_recorded_interactions_to_disk
76
+ write_recorded_interactions_to_disk if should_write_recorded_interactions_to_disk?
70
77
 
71
78
  if should_assert_no_unused_interactions? && !options[:skip_no_unused_interactions_assertion]
72
79
  http_interactions.assert_no_unused_interactions!
73
80
  end
74
81
  end
75
82
 
83
+ # @private
84
+ def run_failed!
85
+ @run_failed = true
86
+ end
87
+
88
+ # @private
89
+ def run_failed?
90
+ @run_failed = false unless defined?(@run_failed)
91
+ @run_failed
92
+ end
93
+
94
+ def should_write_recorded_interactions_to_disk?
95
+ !run_failed? || record_on_error
96
+ end
97
+
76
98
  # @private
77
99
  def http_interactions
78
100
  # Without this mutex, under threaded access, an HTTPInteractionList will overwrite
@@ -151,7 +173,7 @@ module VCR
151
173
 
152
174
  def assert_valid_options!
153
175
  invalid_options = @options.keys - [
154
- :record, :erb, :match_requests_on, :re_record_interval, :tag, :tags,
176
+ :record, :record_on_error, :erb, :match_requests_on, :re_record_interval, :tag, :tags,
155
177
  :update_content_length_header, :allow_playback_repeats, :allow_unused_http_interactions,
156
178
  :exclusive, :serialize_with, :preserve_exact_body_bytes, :decode_compressed_response,
157
179
  :recompress_response, :persist_with, :clean_outdated_http_interactions
@@ -163,7 +185,7 @@ module VCR
163
185
  end
164
186
 
165
187
  def extract_options
166
- [:erb, :match_requests_on, :re_record_interval, :clean_outdated_http_interactions,
188
+ [:record_on_error, :erb, :match_requests_on, :re_record_interval, :clean_outdated_http_interactions,
167
189
  :allow_playback_repeats, :allow_unused_http_interactions, :exclusive].each do |name|
168
190
  instance_variable_set("@#{name}", @options[name])
169
191
  end
@@ -28,7 +28,9 @@ module VCR
28
28
  # @return [String] the YAML string
29
29
  def serialize(hash)
30
30
  handle_encoding_errors do
31
- ::Psych.dump(hash)
31
+ result = ::Psych.dump(hash)
32
+ result.gsub!(": \n", ": null\n") # set canonical null value in order to avoid trailing whitespaces
33
+ result
32
34
  end
33
35
  end
34
36
 
@@ -30,7 +30,9 @@ module VCR
30
30
  # @return [String] the YAML string
31
31
  def serialize(hash)
32
32
  handle_encoding_errors do
33
- ::YAML.dump(hash)
33
+ result = ::YAML.dump(hash)
34
+ result.gsub!(": \n", ": null\n") # set canonical null value in order to avoid trailing whitespaces
35
+ result
34
36
  end
35
37
  end
36
38
 
@@ -492,6 +492,7 @@ module VCR
492
492
  @rspec_metadata_configured = false
493
493
  @default_cassette_options = {
494
494
  :record => :once,
495
+ :record_on_error => true,
495
496
  :match_requests_on => RequestMatcherRegistry::DEFAULT_MATCHERS,
496
497
  :allow_unused_http_interactions => true,
497
498
  :serialize_with => :yaml,
@@ -62,7 +62,7 @@ module VCR
62
62
  super
63
63
 
64
64
  if body && !body.is_a?(String)
65
- raise ArgumentError, "#{self.class} initialized with an invalid body: #{body.inspect}."
65
+ raise ArgumentError, "#{self.class} initialized with an invalid (non-String) body of class #{body.class}: #{body.inspect}."
66
66
  end
67
67
 
68
68
  # Ensure that the body is a raw string, in case the string instance
@@ -32,10 +32,19 @@ module VCR
32
32
  config.before(:each, when_tagged_with_vcr) do |ex|
33
33
  example = ex.respond_to?(:metadata) ? ex : ex.example
34
34
 
35
+ cassette_name = nil
35
36
  options = example.metadata[:vcr]
36
- options = options.is_a?(Hash) ? options.dup : {} # in case it's just :vcr => true
37
-
38
- cassette_name = options.delete(:cassette_name) ||
37
+ options = case options
38
+ when Hash #=> vcr: { cassette_name: 'foo' }
39
+ options.dup
40
+ when String #=> vcr: 'bar'
41
+ cassette_name = options.dup
42
+ {}
43
+ else #=> :vcr or vcr: true
44
+ {}
45
+ end
46
+
47
+ cassette_name ||= options.delete(:cassette_name) ||
39
48
  vcr_cassette_name_for[example.metadata]
40
49
  VCR.insert_cassette(cassette_name, options)
41
50
  end
@@ -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 = '5.0.0'
13
+ string = '5.1.0'
14
14
 
15
15
  def string.parts
16
16
  split('.').map { |p| p.to_i }
metadata CHANGED
@@ -1,14 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vcr
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.0.0
4
+ version: 5.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Myron Marston
8
+ - Kurtis Rainbolt-Greene
9
+ - Olle Jonsson
8
10
  autorequire:
9
11
  bindir: bin
10
12
  cert_chain: []
11
- date: 2019-05-27 00:00:00.000000000 Z
13
+ date: 2020-02-05 00:00:00.000000000 Z
12
14
  dependencies:
13
15
  - !ruby/object:Gem::Dependency
14
16
  name: bundler
@@ -150,6 +152,26 @@ dependencies:
150
152
  - - ">="
151
153
  - !ruby/object:Gem::Version
152
154
  version: '0'
155
+ - !ruby/object:Gem::Dependency
156
+ name: hashdiff
157
+ requirement: !ruby/object:Gem::Requirement
158
+ requirements:
159
+ - - ">="
160
+ - !ruby/object:Gem::Version
161
+ version: 1.0.0.beta1
162
+ - - "<"
163
+ - !ruby/object:Gem::Version
164
+ version: 2.0.0
165
+ type: :development
166
+ prerelease: false
167
+ version_requirements: !ruby/object:Gem::Requirement
168
+ requirements:
169
+ - - ">="
170
+ - !ruby/object:Gem::Version
171
+ version: 1.0.0.beta1
172
+ - - "<"
173
+ - !ruby/object:Gem::Version
174
+ version: 2.0.0
153
175
  - !ruby/object:Gem::Dependency
154
176
  name: cucumber
155
177
  requirement: !ruby/object:Gem::Requirement
@@ -170,14 +192,14 @@ dependencies:
170
192
  requirements:
171
193
  - - "~>"
172
194
  - !ruby/object:Gem::Version
173
- version: 0.5.3
195
+ version: 0.14.12
174
196
  type: :development
175
197
  prerelease: false
176
198
  version_requirements: !ruby/object:Gem::Requirement
177
199
  requirements:
178
200
  - - "~>"
179
201
  - !ruby/object:Gem::Version
180
- version: 0.5.3
202
+ version: 0.14.12
181
203
  - !ruby/object:Gem::Dependency
182
204
  name: faraday
183
205
  requirement: !ruby/object:Gem::Requirement
@@ -307,7 +329,7 @@ dependencies:
307
329
  description: Record your test suite's HTTP interactions and replay them during future
308
330
  test runs for fast, deterministic, accurate tests.
309
331
  email:
310
- - myron.marston@gmail.com
332
+ - kurtis@rainbolt-greene.online
311
333
  executables: []
312
334
  extensions: []
313
335
  extra_rdoc_files: []
@@ -354,7 +376,7 @@ files:
354
376
  - lib/vcr/version.rb
355
377
  homepage: https://relishapp.com/vcr/vcr/docs
356
378
  licenses:
357
- - MIT
379
+ - MIT-Hippocratic-1.2
358
380
  metadata: {}
359
381
  post_install_message:
360
382
  rdoc_options: []