vcr 6.0.0 → 6.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: 79ff7c5f67afb190b63450e117a7dbda6709340fbab8c17680c36b2bb5a8a6f6
4
- data.tar.gz: a6a17620c6c63d9a596a39e2700f3f1becddb26bfa63f862e42ef0dfabb783d9
3
+ metadata.gz: 0230f475b5c666e17c97d0b81695860d18a54c40d07dccfb82ab63098fc60084
4
+ data.tar.gz: b79ad4ff6425ef66da8810b75f9cdc787d656c97cb5d60acf31c9ba09a4b6a5d
5
5
  SHA512:
6
- metadata.gz: 9f43f626bae24850a8b5f912203dba5ee7e38ef39ecb3d325382ca2cbfb24ff789c3e630edd628588fdd59b0a8b10919bedd820675a039b5d619f1c779dc186b
7
- data.tar.gz: ffc8534bbab227c6f8f4636306644c1c28d1ac8c2d29d47551d1b84c04cd5c37979acfb44803b18c54ee558e961d92826a38e6a75b93d8002af6adde5f2e7d05
6
+ metadata.gz: 22d462bea8b4048575d82db89ecc36327be825267d76f69fa366ca98894b691210b6e859f4ab7d7acaf5fef537749b010ea166dcb09af642677bf402d6aaf855
7
+ data.tar.gz: 9f2a224345cabd78d03c0ac5f687b6261c7e1e34fe64c24dca7c4c46057de6122ec74d58c11ff3e3aefb8cc848efda899441c65c3d7dd0bdad86fbcccda9163d
@@ -32,7 +32,7 @@ module VCR
32
32
  end
33
33
 
34
34
  def erb_variables
35
- @erb if @erb.is_a?(Hash)
35
+ @erb if @erb.is_a?(Hash) && !@erb.empty?
36
36
  end
37
37
 
38
38
  def template
@@ -40,7 +40,9 @@ module VCR
40
40
  end
41
41
 
42
42
  @@struct_cache = Hash.new do |hash, attributes|
43
- hash[attributes] = Struct.new(*attributes)
43
+ attributes = attributes.map(&:to_sym)
44
+ hash[attributes] = Struct.new(*attributes) unless hash.key?(attributes)
45
+ hash[attributes]
44
46
  end
45
47
 
46
48
  def variables_object
@@ -50,7 +50,11 @@ module VCR
50
50
  end
51
51
 
52
52
  def load_yaml(cassette)
53
- ::YAML.load_file(cassette)
53
+ if ::YAML.respond_to?(:unsafe_load_file)
54
+ ::YAML.unsafe_load_file(cassette)
55
+ else
56
+ ::YAML.load_file(cassette)
57
+ end
54
58
  rescue *@yaml_load_errors
55
59
  return nil
56
60
  end
@@ -3,7 +3,7 @@ require 'json'
3
3
  module VCR
4
4
  class Cassette
5
5
  class Serializers
6
- # The JSON serializer. Uses `MultiJson` under the covers.
6
+ # The JSON serializer.
7
7
  #
8
8
  # @see Psych
9
9
  # @see Syck
@@ -11,11 +11,15 @@ module VCR
11
11
  module JSON
12
12
  extend self
13
13
  extend EncodingErrorHandling
14
+ extend SyntaxErrorHandling
14
15
 
15
16
  # @private
16
17
  ENCODING_ERRORS = [ArgumentError]
17
18
  ENCODING_ERRORS << ::JSON::GeneratorError
18
19
 
20
+ # @private
21
+ SYNTAX_ERRORS = [::JSON::ParserError]
22
+
19
23
  # The file extension to use for this serializer.
20
24
  #
21
25
  # @return [String] "json"
@@ -29,7 +33,7 @@ module VCR
29
33
  # @return [String] the JSON string
30
34
  def serialize(hash)
31
35
  handle_encoding_errors do
32
- ::JSON.generate(hash)
36
+ ::JSON.pretty_generate(hash)
33
37
  end
34
38
  end
35
39
 
@@ -39,7 +43,9 @@ module VCR
39
43
  # @return [Hash] the deserialized object
40
44
  def deserialize(string)
41
45
  handle_encoding_errors do
42
- ::JSON.parse(string)
46
+ handle_syntax_errors do
47
+ ::JSON.parse(string)
48
+ end
43
49
  end
44
50
  end
45
51
  end
@@ -11,10 +11,14 @@ module VCR
11
11
  module Psych
12
12
  extend self
13
13
  extend EncodingErrorHandling
14
+ extend SyntaxErrorHandling
14
15
 
15
16
  # @private
16
17
  ENCODING_ERRORS = [ArgumentError]
17
18
 
19
+ # @private
20
+ SYNTAX_ERRORS = [::Psych::SyntaxError]
21
+
18
22
  # The file extension to use for this serializer.
19
23
  #
20
24
  # @return [String] "yml"
@@ -40,7 +44,9 @@ module VCR
40
44
  # @return [Hash] the deserialized object
41
45
  def deserialize(string)
42
46
  handle_encoding_errors do
43
- ::Psych.load(string)
47
+ handle_syntax_errors do
48
+ ::Psych.load(string)
49
+ end
44
50
  end
45
51
  end
46
52
  end
@@ -11,10 +11,14 @@ module VCR
11
11
  module Syck
12
12
  extend self
13
13
  extend EncodingErrorHandling
14
+ extend SyntaxErrorHandling
14
15
 
15
16
  # @private
16
17
  ENCODING_ERRORS = [ArgumentError]
17
18
 
19
+ # @private
20
+ SYNTAX_ERRORS = [::Psych::SyntaxError]
21
+
18
22
  # The file extension to use for this serializer.
19
23
  #
20
24
  # @return [String] "yml"
@@ -38,7 +42,9 @@ module VCR
38
42
  # @return [Hash] the deserialized object
39
43
  def deserialize(string)
40
44
  handle_encoding_errors do
41
- using_syck { ::YAML.load(string) }
45
+ handle_syntax_errors do
46
+ using_syck { ::YAML.load(string) }
47
+ end
42
48
  end
43
49
  end
44
50
 
@@ -13,10 +13,14 @@ module VCR
13
13
  module YAML
14
14
  extend self
15
15
  extend EncodingErrorHandling
16
+ extend SyntaxErrorHandling
16
17
 
17
18
  # @private
18
19
  ENCODING_ERRORS = [ArgumentError]
19
20
 
21
+ # @private
22
+ SYNTAX_ERRORS = [::Psych::SyntaxError]
23
+
20
24
  # The file extension to use for this serializer.
21
25
  #
22
26
  # @return [String] "yml"
@@ -42,7 +46,13 @@ module VCR
42
46
  # @return [Hash] the deserialized object
43
47
  def deserialize(string)
44
48
  handle_encoding_errors do
45
- ::YAML.load(string)
49
+ handle_syntax_errors do
50
+ if ::YAML.respond_to?(:unsafe_load)
51
+ ::YAML.unsafe_load(string)
52
+ else
53
+ ::YAML.load(string)
54
+ end
55
+ end
46
56
  end
47
57
  end
48
58
  end
@@ -54,6 +54,16 @@ module VCR
54
54
  raise
55
55
  end
56
56
  end
57
+
58
+ # @private
59
+ module SyntaxErrorHandling
60
+ def handle_syntax_errors
61
+ yield
62
+ rescue *self::SYNTAX_ERRORS => e
63
+ e.message << "\nNote: This is a VCR cassette. If it is using ERB, you may have forgotten to pass the `:erb` option to `use_cassette`."
64
+ raise
65
+ end
66
+ end
57
67
  end
58
68
  end
59
69
 
data/lib/vcr/cassette.rb CHANGED
@@ -192,10 +192,9 @@ module VCR
192
192
 
193
193
  assign_tags
194
194
 
195
- @record_mode = @options[:record]
196
195
  @serializer = VCR.cassette_serializers[@options[:serialize_with]]
197
196
  @persister = VCR.cassette_persisters[@options[:persist_with]]
198
- @record_mode = :all if should_re_record?
197
+ @record_mode = should_re_record?(@options[:record]) ? :all : @options[:record]
199
198
  @parent_list = @exclusive ? HTTPInteractionList::NullList : VCR.http_interactions
200
199
  end
201
200
 
@@ -231,9 +230,10 @@ module VCR
231
230
  end
232
231
  end
233
232
 
234
- def should_re_record?
233
+ def should_re_record?(record_mode)
235
234
  return false unless @re_record_interval
236
235
  return false unless originally_recorded_at
236
+ return false if record_mode == :none
237
237
 
238
238
  now = Time.now
239
239
 
@@ -2,137 +2,121 @@ require 'vcr/util/version_checker'
2
2
  require 'vcr/request_handler'
3
3
  require 'typhoeus'
4
4
 
5
- if Float(Typhoeus::VERSION[/^\d+\.\d+/]) < 0.5
6
- require 'vcr/library_hooks/typhoeus_0.4'
7
- else
8
- VCR::VersionChecker.new('Typhoeus', Typhoeus::VERSION, '0.5.0').check_version!
9
-
10
- module VCR
11
- class LibraryHooks
5
+ module VCR
6
+ class LibraryHooks
7
+ # @private
8
+ module Typhoeus
12
9
  # @private
13
- module Typhoeus
14
- # @private
15
- class RequestHandler < ::VCR::RequestHandler
16
- attr_reader :request
17
- def initialize(request)
18
- @request = request
19
- request.block_connection = false if VCR.turned_on?
20
- end
21
-
22
- def vcr_request
23
- @vcr_request ||= VCR::Request.new \
24
- request.options.fetch(:method, :get),
25
- request.url,
26
- request_body,
27
- request.options.fetch(:headers, {})
28
- end
29
-
30
- private
10
+ class RequestHandler < ::VCR::RequestHandler
11
+ attr_reader :request
12
+ def initialize(request)
13
+ @request = request
14
+ request.block_connection = false if VCR.turned_on?
15
+ end
31
16
 
32
- def externally_stubbed?
33
- ::Typhoeus::Expectation.find_by(request)
34
- end
17
+ def vcr_request
18
+ @vcr_request ||= VCR::Request.new \
19
+ request.options.fetch(:method, :get),
20
+ request.url,
21
+ request.encoded_body,
22
+ request.options.fetch(:headers, {})
23
+ end
35
24
 
36
- def set_typed_request_for_after_hook(*args)
37
- super
38
- request.instance_variable_set(:@__typed_vcr_request, @after_hook_typed_request)
39
- end
25
+ private
40
26
 
41
- def on_unhandled_request
42
- invoke_after_request_hook(nil)
43
- super
44
- end
27
+ def externally_stubbed?
28
+ ::Typhoeus::Expectation.find_by(request)
29
+ end
45
30
 
46
- def on_stubbed_by_vcr_request
47
- response = ::Typhoeus::Response.new \
48
- :http_version => stubbed_response.http_version,
49
- :code => stubbed_response.status.code,
50
- :status_message => stubbed_response.status.message,
51
- :headers => stubbed_response_headers,
52
- :body => stubbed_response.body,
53
- :effective_url => stubbed_response.adapter_metadata.fetch('effective_url', request.url),
54
- :mock => true
55
-
56
- first_header_line = "HTTP/#{stubbed_response.http_version} #{response.code} #{response.status_message}\r\n"
57
- response.instance_variable_set(:@first_header_line, first_header_line)
58
- response.instance_variable_get(:@options)[:response_headers] =
59
- first_header_line + response.headers.map { |k,v| "#{k}: #{v}"}.join("\r\n")
60
-
61
- response
62
- end
31
+ def set_typed_request_for_after_hook(*args)
32
+ super
33
+ request.instance_variable_set(:@__typed_vcr_request, @after_hook_typed_request)
34
+ end
63
35
 
64
- def stubbed_response_headers
65
- @stubbed_response_headers ||= {}.tap do |hash|
66
- stubbed_response.headers.each do |key, values|
67
- hash[key] = values.size == 1 ? values.first : values
68
- end if stubbed_response.headers
69
- end
70
- end
36
+ def on_unhandled_request
37
+ invoke_after_request_hook(nil)
38
+ super
39
+ end
71
40
 
72
- if ::Typhoeus::Request.method_defined?(:encoded_body)
73
- def request_body
74
- request.encoded_body
75
- end
76
- else
77
- def request_body
78
- request.options.fetch(:body, "")
79
- end
80
- end
41
+ def on_stubbed_by_vcr_request
42
+ response = ::Typhoeus::Response.new \
43
+ :http_version => stubbed_response.http_version,
44
+ :code => stubbed_response.status.code,
45
+ :status_message => stubbed_response.status.message,
46
+ :headers => stubbed_response_headers,
47
+ :body => stubbed_response.body,
48
+ :effective_url => stubbed_response.adapter_metadata.fetch('effective_url', request.url),
49
+ :mock => true
50
+
51
+ first_header_line = "HTTP/#{stubbed_response.http_version} #{response.code} #{response.status_message}\r\n"
52
+ response.instance_variable_set(:@first_header_line, first_header_line)
53
+ response.instance_variable_get(:@options)[:response_headers] =
54
+ first_header_line + response.headers.map { |k,v| "#{k}: #{v}"}.join("\r\n")
55
+
56
+ response
81
57
  end
82
58
 
83
- # @private
84
- class << self
85
- def vcr_response_from(response)
86
- VCR::Response.new \
87
- VCR::ResponseStatus.new(response.code, response.status_message),
88
- response.headers,
89
- response.body,
90
- response.http_version,
91
- { "effective_url" => response.effective_url }
59
+ def stubbed_response_headers
60
+ @stubbed_response_headers ||= {}.tap do |hash|
61
+ stubbed_response.headers.each do |key, values|
62
+ hash[key] = values.size == 1 ? values.first : values
63
+ end if stubbed_response.headers
92
64
  end
65
+ end
66
+ end
93
67
 
94
- def collect_chunks(request)
95
- chunks = ''
96
- request.on_body.unshift(
97
- Proc.new do |body, response|
98
- chunks += body
99
- request.instance_variable_set(:@chunked_body, chunks)
100
- end
101
- )
102
- end
68
+ # @private
69
+ class << self
70
+ def vcr_response_from(response)
71
+ VCR::Response.new \
72
+ VCR::ResponseStatus.new(response.code, response.status_message),
73
+ response.headers,
74
+ response.body,
75
+ response.http_version,
76
+ { "effective_url" => response.effective_url }
77
+ end
103
78
 
104
- def restore_body_from_chunks(response, request)
105
- response.options[:response_body] = request.instance_variable_get(:@chunked_body)
106
- end
79
+ def collect_chunks(request)
80
+ chunks = ''
81
+ request.on_body.unshift(
82
+ Proc.new do |body, response|
83
+ chunks += body
84
+ request.instance_variable_set(:@chunked_body, chunks)
85
+ end
86
+ )
107
87
  end
108
88
 
109
- ::Typhoeus.on_complete do |response|
110
- request = response.request
89
+ def restore_body_from_chunks(response, request)
90
+ response.options[:response_body] = request.instance_variable_get(:@chunked_body)
91
+ end
92
+ end
111
93
 
112
- restore_body_from_chunks(response, request) if request.streaming?
94
+ ::Typhoeus.on_complete do |response|
95
+ request = response.request
113
96
 
114
- unless VCR.library_hooks.disabled?(:typhoeus)
115
- vcr_response = vcr_response_from(response)
116
- typed_vcr_request = request.send(:remove_instance_variable, :@__typed_vcr_request)
97
+ restore_body_from_chunks(response, request) if request.streaming?
117
98
 
118
- unless request.response.mock
119
- http_interaction = VCR::HTTPInteraction.new(typed_vcr_request, vcr_response)
120
- VCR.record_http_interaction(http_interaction)
121
- end
99
+ unless VCR.library_hooks.disabled?(:typhoeus)
100
+ vcr_response = vcr_response_from(response)
101
+ typed_vcr_request = request.send(:remove_instance_variable, :@__typed_vcr_request)
122
102
 
123
- VCR.configuration.invoke_hook(:after_http_request, typed_vcr_request, vcr_response)
103
+ unless request.response.mock
104
+ http_interaction = VCR::HTTPInteraction.new(typed_vcr_request, vcr_response)
105
+ VCR.record_http_interaction(http_interaction)
124
106
  end
107
+
108
+ VCR.configuration.invoke_hook(:after_http_request, typed_vcr_request, vcr_response)
125
109
  end
110
+ end
126
111
 
127
- ::Typhoeus.before do |request|
128
- collect_chunks(request) if request.streaming?
129
- if response = VCR::LibraryHooks::Typhoeus::RequestHandler.new(request).handle
130
- request.on_headers.each { |cb| cb.call(response) }
131
- request.on_body.each { |cb| cb.call(response.body, response) }
132
- request.finish(response)
133
- else
134
- true
135
- end
112
+ ::Typhoeus.before do |request|
113
+ collect_chunks(request) if request.streaming?
114
+ if response = VCR::LibraryHooks::Typhoeus::RequestHandler.new(request).handle
115
+ request.on_headers.each { |cb| cb.call(response) }
116
+ request.on_body.each { |cb| cb.call(response.body, response) }
117
+ request.finish(response)
118
+ else
119
+ true
136
120
  end
137
121
  end
138
122
  end
@@ -146,4 +130,3 @@ VCR.configuration.after_library_hooks_loaded do
146
130
  WebMock::HttpLibAdapters::TyphoeusAdapter.disable!
147
131
  end
148
132
  end
149
-
@@ -12,8 +12,6 @@ module VCR
12
12
  module WebMock
13
13
  extend self
14
14
 
15
- @global_hook_disabled_requests = {}
16
-
17
15
  def with_global_hook_disabled(request)
18
16
  global_hook_disabled_requests << request
19
17
 
@@ -25,19 +23,12 @@ module VCR
25
23
  end
26
24
 
27
25
  def global_hook_disabled?(request)
28
- requests = @global_hook_disabled_requests[Thread.current.object_id]
26
+ requests = Thread.current[:_vcr_webmock_disabled_requests]
29
27
  requests && requests.include?(request)
30
28
  end
31
29
 
32
30
  def global_hook_disabled_requests
33
- requests = @global_hook_disabled_requests[Thread.current.object_id]
34
- return requests if requests
35
-
36
- ObjectSpace.define_finalizer(Thread.current, lambda {
37
- @global_hook_disabled_requests.delete(Thread.current.object_id)
38
- })
39
-
40
- @global_hook_disabled_requests[Thread.current.object_id] = []
31
+ Thread.current[:_vcr_webmock_disabled_requests] ||= []
41
32
  end
42
33
 
43
34
  # @private
@@ -74,7 +74,7 @@ module VCR
74
74
  def after_request(response)
75
75
  vcr_response = vcr_response_for(response)
76
76
 
77
- if should_record?
77
+ if vcr_response && should_record?
78
78
  VCR.record_http_interaction(VCR::HTTPInteraction.new(vcr_request, vcr_response))
79
79
  end
80
80
 
@@ -25,6 +25,10 @@ module VCR
25
25
  end
26
26
  end
27
27
 
28
+ def localhost_ignored?
29
+ (LOCALHOST_ALIASES & ignore_hosts.to_a).any?
30
+ end
31
+
28
32
  def ignore_hosts(*hosts)
29
33
  ignored_hosts.merge(hosts)
30
34
  end
@@ -110,12 +110,12 @@ module VCR
110
110
 
111
111
  def register_built_ins
112
112
  register(:method) { |r1, r2| r1.method == r2.method }
113
- register(:uri) { |r1, r2| r1.uri == r2.uri }
113
+ register(:uri) { |r1, r2| r1.parsed_uri == r2.parsed_uri }
114
114
  register(:body) { |r1, r2| r1.body == r2.body }
115
115
  register(:headers) { |r1, r2| r1.headers == r2.headers }
116
116
 
117
117
  register(:host) do |r1, r2|
118
- r1.parsed_uri.host == r2.parsed_uri.host
118
+ r1.parsed_uri.host.chomp('.') == r2.parsed_uri.host.chomp('.')
119
119
  end
120
120
  register(:path) do |r1, r2|
121
121
  r1.parsed_uri.path == r2.parsed_uri.path
@@ -47,10 +47,21 @@ module VCR
47
47
  scenario.scenario_outline.name,
48
48
  scenario.name.split("\n").first
49
49
  ].join("/")
50
- else
50
+ elsif scenario.respond_to?(:feature)
51
51
  [ scenario.feature.name.split("\n").first,
52
52
  scenario.name.split("\n").first
53
53
  ].join("/")
54
+ elsif scenario.location.lines.min == scenario.location.lines.max
55
+ # test case from a regular scenario in cucumber version 4
56
+ [ scenario.location.file.split("/").last.split(".").first,
57
+ scenario.name.split("\n").first
58
+ ].join("/")
59
+ else
60
+ # test case from a scenario with examples ("scenario outline") in cucumber version 4
61
+ [ scenario.location.file.split("/").last.split(".").first,
62
+ scenario.name.split("\n").first,
63
+ "Example at line #{scenario.location.lines.max}"
64
+ ].join("/")
54
65
  end
55
66
  else
56
67
  "cucumber_tags/#{tag_name.gsub(/\A@/, '')}"
@@ -5,27 +5,30 @@ module VCR
5
5
  module Metadata
6
6
  extend self
7
7
 
8
+ def vcr_cassette_name_for(metadata)
9
+ description =
10
+ if metadata[:description].empty?
11
+ # we have an "it { is_expected.to be something }" block
12
+ metadata[:scoped_id]
13
+ else
14
+ metadata[:description]
15
+ end
16
+ example_group =
17
+ if metadata.key?(:example_group)
18
+ metadata[:example_group]
19
+ else
20
+ metadata[:parent_example_group]
21
+ end
22
+
23
+ if example_group
24
+ [vcr_cassette_name_for(example_group), description].join('/')
25
+ else
26
+ description
27
+ end
28
+ end
29
+
8
30
  def configure!
9
31
  ::RSpec.configure do |config|
10
- vcr_cassette_name_for = lambda do |metadata|
11
- description = if metadata[:description].empty?
12
- # we have an "it { is_expected.to be something }" block
13
- metadata[:scoped_id]
14
- else
15
- metadata[:description]
16
- end
17
- example_group = if metadata.key?(:example_group)
18
- metadata[:example_group]
19
- else
20
- metadata[:parent_example_group]
21
- end
22
-
23
- if example_group
24
- [vcr_cassette_name_for[example_group], description].join('/')
25
- else
26
- description
27
- end
28
- end
29
32
 
30
33
  when_tagged_with_vcr = { :vcr => lambda { |v| !!v } }
31
34
 
@@ -45,7 +48,7 @@ module VCR
45
48
  end
46
49
 
47
50
  cassette_name ||= options.delete(:cassette_name) ||
48
- vcr_cassette_name_for[example.metadata]
51
+ VCR::RSpec::Metadata.vcr_cassette_name_for(example.metadata)
49
52
  VCR.insert_cassette(cassette_name, options)
50
53
  end
51
54
 
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.0.0'
13
+ string = +'6.1.0'
14
14
 
15
15
  def string.parts
16
16
  split('.').map { |p| p.to_i }
@@ -28,7 +28,7 @@ module VCR
28
28
  parts[2]
29
29
  end
30
30
 
31
- string
31
+ string.freeze
32
32
  end
33
33
  end
34
34
  end
data/lib/vcr.rb CHANGED
@@ -52,7 +52,7 @@ module VCR
52
52
  # Inserts the named cassette using the given cassette options.
53
53
  # New HTTP interactions, if allowed by the cassette's `:record` option, will
54
54
  # be recorded to the cassette. The cassette's existing HTTP interactions
55
- # will be used to stub requests, unless prevented by the cassete's
55
+ # will be used to stub requests, unless prevented by the cassette's
56
56
  # `:record` option.
57
57
  #
58
58
  # @example
@@ -266,6 +266,7 @@ module VCR
266
266
  # @see #turn_off!
267
267
  # @see #turn_on!
268
268
  # @see #turned_on?
269
+ # @see #turned_on
269
270
  def turned_off(options = {})
270
271
  turn_off!(options)
271
272
 
@@ -301,11 +302,28 @@ module VCR
301
302
  set_context_value(:turned_off, true)
302
303
  end
303
304
 
305
+ # Turns on VCR, for the duration of a block.
306
+ # @param (see #turn_off!)
307
+ # @return [void]
308
+ # @see #turn_off!
309
+ # @see #turned_off
310
+ # @see #turned_on?
311
+ def turned_on(options = {})
312
+ turn_on!
313
+
314
+ begin
315
+ yield
316
+ ensure
317
+ turn_off!(options)
318
+ end
319
+ end
320
+
304
321
  # Turns on VCR, if it has previously been turned off.
305
322
  # @return [void]
306
323
  # @see #turn_off!
307
324
  # @see #turned_off
308
325
  # @see #turned_on?
326
+ # @see #turned_on
309
327
  def turn_on!
310
328
  set_context_value(:turned_off, false)
311
329
  end
metadata CHANGED
@@ -1,16 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vcr
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.0.0
4
+ version: 6.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Myron Marston
8
8
  - Kurtis Rainbolt-Greene
9
9
  - Olle Jonsson
10
- autorequire:
10
+ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2020-05-28 00:00:00.000000000 Z
13
+ date: 2022-03-13 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: bundler
@@ -46,28 +46,28 @@ dependencies:
46
46
  requirements:
47
47
  - - "~>"
48
48
  - !ruby/object:Gem::Version
49
- version: 3.1.4
49
+ version: 3.4.4
50
50
  type: :development
51
51
  prerelease: false
52
52
  version_requirements: !ruby/object:Gem::Requirement
53
53
  requirements:
54
54
  - - "~>"
55
55
  - !ruby/object:Gem::Version
56
- version: 3.1.4
56
+ version: 3.4.4
57
57
  - !ruby/object:Gem::Dependency
58
58
  name: rake
59
59
  requirement: !ruby/object:Gem::Requirement
60
60
  requirements:
61
- - - "~>"
61
+ - - ">="
62
62
  - !ruby/object:Gem::Version
63
- version: '10.1'
63
+ version: 12.3.3
64
64
  type: :development
65
65
  prerelease: false
66
66
  version_requirements: !ruby/object:Gem::Requirement
67
67
  requirements:
68
- - - "~>"
68
+ - - ">="
69
69
  - !ruby/object:Gem::Version
70
- version: '10.1'
70
+ version: 12.3.3
71
71
  - !ruby/object:Gem::Dependency
72
72
  name: pry
73
73
  requirement: !ruby/object:Gem::Requirement
@@ -178,14 +178,14 @@ dependencies:
178
178
  requirements:
179
179
  - - "~>"
180
180
  - !ruby/object:Gem::Version
181
- version: '3.1'
181
+ version: '7.0'
182
182
  type: :development
183
183
  prerelease: false
184
184
  version_requirements: !ruby/object:Gem::Requirement
185
185
  requirements:
186
186
  - - "~>"
187
187
  - !ruby/object:Gem::Version
188
- version: '3.1'
188
+ version: '7.0'
189
189
  - !ruby/object:Gem::Dependency
190
190
  name: aruba
191
191
  requirement: !ruby/object:Gem::Requirement
@@ -346,7 +346,6 @@ files:
346
346
  - lib/vcr/library_hooks/excon.rb
347
347
  - lib/vcr/library_hooks/faraday.rb
348
348
  - lib/vcr/library_hooks/typhoeus.rb
349
- - lib/vcr/library_hooks/typhoeus_0.4.rb
350
349
  - lib/vcr/library_hooks/webmock.rb
351
350
  - lib/vcr/linked_cassette.rb
352
351
  - lib/vcr/middleware/excon.rb
@@ -371,7 +370,7 @@ licenses:
371
370
  - Hippocratic-2.1
372
371
  - MIT
373
372
  metadata: {}
374
- post_install_message:
373
+ post_install_message:
375
374
  rdoc_options: []
376
375
  require_paths:
377
376
  - lib
@@ -379,15 +378,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
379
378
  requirements:
380
379
  - - ">="
381
380
  - !ruby/object:Gem::Version
382
- version: '2.3'
381
+ version: '2.6'
383
382
  required_rubygems_version: !ruby/object:Gem::Requirement
384
383
  requirements:
385
384
  - - ">="
386
385
  - !ruby/object:Gem::Version
387
386
  version: '0'
388
387
  requirements: []
389
- rubygems_version: 3.1.3
390
- signing_key:
388
+ rubygems_version: 3.2.7
389
+ signing_key:
391
390
  specification_version: 4
392
391
  summary: Record your test suite's HTTP interactions and replay them during future
393
392
  test runs for fast, deterministic, accurate tests.
@@ -1,103 +0,0 @@
1
- VCR::VersionChecker.new('Typhoeus', Typhoeus::VERSION, '0.3.2').check_version!
2
-
3
- module VCR
4
- class LibraryHooks
5
- # @private
6
- module Typhoeus
7
- # @private
8
- class RequestHandler < ::VCR::RequestHandler
9
- attr_reader :request
10
- def initialize(request)
11
- @request = request
12
- end
13
-
14
- def vcr_request
15
- @vcr_request ||= VCR::Request.new \
16
- request.method,
17
- request.url,
18
- request.body,
19
- request.headers
20
- end
21
-
22
- private
23
-
24
- def externally_stubbed?
25
- ::Typhoeus::Hydra.stubs.detect { |stub| stub.matches?(request) }
26
- end
27
-
28
- def set_typed_request_for_after_hook(*args)
29
- super
30
- request.instance_variable_set(:@__typed_vcr_request, @after_hook_typed_request)
31
- end
32
-
33
- def on_unhandled_request
34
- invoke_after_request_hook(nil)
35
- super
36
- end
37
-
38
- def on_stubbed_by_vcr_request
39
- ::Typhoeus::Response.new \
40
- :http_version => stubbed_response.http_version,
41
- :code => stubbed_response.status.code,
42
- :status_message => stubbed_response.status.message,
43
- :headers_hash => stubbed_response_headers,
44
- :body => stubbed_response.body
45
- end
46
-
47
- def stubbed_response_headers
48
- @stubbed_response_headers ||= {}.tap do |hash|
49
- stubbed_response.headers.each do |key, values|
50
- hash[key] = values.size == 1 ? values.first : values
51
- end if stubbed_response.headers
52
- end
53
- end
54
- end
55
-
56
- # @private
57
- def self.vcr_response_from(response)
58
- VCR::Response.new \
59
- VCR::ResponseStatus.new(response.code, response.status_message),
60
- response.headers_hash,
61
- response.body,
62
- response.http_version
63
- end
64
-
65
- ::Typhoeus::Hydra.after_request_before_on_complete do |request|
66
- unless VCR.library_hooks.disabled?(:typhoeus)
67
- vcr_response = vcr_response_from(request.response)
68
- typed_vcr_request = request.send(:remove_instance_variable, :@__typed_vcr_request)
69
-
70
- unless request.response.mock?
71
- http_interaction = VCR::HTTPInteraction.new(typed_vcr_request, vcr_response)
72
- VCR.record_http_interaction(http_interaction)
73
- end
74
-
75
- VCR.configuration.invoke_hook(:after_http_request, typed_vcr_request, vcr_response)
76
- end
77
- end
78
-
79
- ::Typhoeus::Hydra.register_stub_finder do |request|
80
- VCR::LibraryHooks::Typhoeus::RequestHandler.new(request).handle
81
- end
82
- end
83
- end
84
- end
85
-
86
- # @private
87
- module Typhoeus
88
- class << Hydra
89
- # ensure HTTP requests are always allowed; VCR takes care of disallowing
90
- # them at the appropriate times in its hook
91
- def allow_net_connect_with_vcr?(*args)
92
- VCR.turned_on? ? true : allow_net_connect_without_vcr?
93
- end
94
-
95
- alias allow_net_connect_without_vcr? allow_net_connect?
96
- alias allow_net_connect? allow_net_connect_with_vcr?
97
- end unless Hydra.respond_to?(:allow_net_connect_with_vcr?)
98
- end
99
-
100
- VCR.configuration.after_library_hooks_loaded do
101
- ::Kernel.warn "WARNING: VCR's Typhoeus 0.4 integration is deprecated and will be removed in VCR 3.0."
102
- end
103
-