mustwin-vcr 2.9.3

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 (148) hide show
  1. checksums.yaml +7 -0
  2. data/features/about_these_examples.md +18 -0
  3. data/features/cassettes/allow_unused_http_interactions.feature +100 -0
  4. data/features/cassettes/automatic_re_recording.feature +72 -0
  5. data/features/cassettes/decompress.feature +74 -0
  6. data/features/cassettes/dynamic_erb.feature +100 -0
  7. data/features/cassettes/exclusive.feature +126 -0
  8. data/features/cassettes/format.feature +323 -0
  9. data/features/cassettes/freezing_time.feature +68 -0
  10. data/features/cassettes/naming.feature +28 -0
  11. data/features/cassettes/no_cassette.feature +152 -0
  12. data/features/cassettes/update_content_length_header.feature +112 -0
  13. data/features/configuration/allow_http_connections_when_no_cassette.feature +55 -0
  14. data/features/configuration/cassette_library_dir.feature +31 -0
  15. data/features/configuration/debug_logging.feature +59 -0
  16. data/features/configuration/default_cassette_options.feature +100 -0
  17. data/features/configuration/filter_sensitive_data.feature +153 -0
  18. data/features/configuration/hook_into.feature +172 -0
  19. data/features/configuration/ignore_request.feature +192 -0
  20. data/features/configuration/preserve_exact_body_bytes.feature +108 -0
  21. data/features/configuration/query_parser.feature +84 -0
  22. data/features/configuration/uri_parser.feature +89 -0
  23. data/features/getting_started.md +82 -0
  24. data/features/hooks/after_http_request.feature +58 -0
  25. data/features/hooks/around_http_request.feature +57 -0
  26. data/features/hooks/before_http_request.feature +63 -0
  27. data/features/hooks/before_playback.feature +184 -0
  28. data/features/hooks/before_record.feature +172 -0
  29. data/features/http_libraries/em_http_request.feature +250 -0
  30. data/features/http_libraries/net_http.feature +179 -0
  31. data/features/middleware/faraday.feature +56 -0
  32. data/features/middleware/rack.feature +92 -0
  33. data/features/record_modes/all.feature +82 -0
  34. data/features/record_modes/new_episodes.feature +79 -0
  35. data/features/record_modes/none.feature +72 -0
  36. data/features/record_modes/once.feature +95 -0
  37. data/features/request_matching/README.md +30 -0
  38. data/features/request_matching/body.feature +91 -0
  39. data/features/request_matching/body_as_json.feature +90 -0
  40. data/features/request_matching/custom_matcher.feature +135 -0
  41. data/features/request_matching/headers.feature +85 -0
  42. data/features/request_matching/host.feature +95 -0
  43. data/features/request_matching/identical_request_sequence.feature +89 -0
  44. data/features/request_matching/method.feature +96 -0
  45. data/features/request_matching/path.feature +96 -0
  46. data/features/request_matching/playback_repeats.feature +98 -0
  47. data/features/request_matching/query.feature +97 -0
  48. data/features/request_matching/uri.feature +94 -0
  49. data/features/request_matching/uri_without_param.feature +101 -0
  50. data/features/step_definitions/cli_steps.rb +193 -0
  51. data/features/support/env.rb +44 -0
  52. data/features/support/http_lib_filters.rb +53 -0
  53. data/features/test_frameworks/cucumber.feature +211 -0
  54. data/features/test_frameworks/rspec_macro.feature +81 -0
  55. data/features/test_frameworks/rspec_metadata.feature +150 -0
  56. data/features/test_frameworks/test_unit.feature +49 -0
  57. data/lib/vcr.rb +347 -0
  58. data/lib/vcr/cassette.rb +291 -0
  59. data/lib/vcr/cassette/erb_renderer.rb +55 -0
  60. data/lib/vcr/cassette/http_interaction_list.rb +108 -0
  61. data/lib/vcr/cassette/migrator.rb +118 -0
  62. data/lib/vcr/cassette/persisters.rb +42 -0
  63. data/lib/vcr/cassette/persisters/file_system.rb +64 -0
  64. data/lib/vcr/cassette/serializers.rb +57 -0
  65. data/lib/vcr/cassette/serializers/json.rb +48 -0
  66. data/lib/vcr/cassette/serializers/psych.rb +48 -0
  67. data/lib/vcr/cassette/serializers/syck.rb +61 -0
  68. data/lib/vcr/cassette/serializers/yaml.rb +50 -0
  69. data/lib/vcr/configuration.rb +555 -0
  70. data/lib/vcr/deprecations.rb +109 -0
  71. data/lib/vcr/errors.rb +266 -0
  72. data/lib/vcr/extensions/net_http_response.rb +36 -0
  73. data/lib/vcr/library_hooks.rb +18 -0
  74. data/lib/vcr/library_hooks/excon.rb +27 -0
  75. data/lib/vcr/library_hooks/fakeweb.rb +196 -0
  76. data/lib/vcr/library_hooks/faraday.rb +51 -0
  77. data/lib/vcr/library_hooks/typhoeus.rb +120 -0
  78. data/lib/vcr/library_hooks/typhoeus_0.4.rb +103 -0
  79. data/lib/vcr/library_hooks/webmock.rb +164 -0
  80. data/lib/vcr/middleware/excon.rb +221 -0
  81. data/lib/vcr/middleware/excon/legacy_methods.rb +33 -0
  82. data/lib/vcr/middleware/faraday.rb +118 -0
  83. data/lib/vcr/middleware/rack.rb +79 -0
  84. data/lib/vcr/request_handler.rb +114 -0
  85. data/lib/vcr/request_ignorer.rb +43 -0
  86. data/lib/vcr/request_matcher_registry.rb +149 -0
  87. data/lib/vcr/structs.rb +578 -0
  88. data/lib/vcr/tasks/vcr.rake +9 -0
  89. data/lib/vcr/test_frameworks/cucumber.rb +64 -0
  90. data/lib/vcr/test_frameworks/rspec.rb +47 -0
  91. data/lib/vcr/util/hooks.rb +61 -0
  92. data/lib/vcr/util/internet_connection.rb +43 -0
  93. data/lib/vcr/util/logger.rb +59 -0
  94. data/lib/vcr/util/variable_args_block_caller.rb +13 -0
  95. data/lib/vcr/util/version_checker.rb +48 -0
  96. data/lib/vcr/version.rb +34 -0
  97. data/spec/acceptance/threading_spec.rb +34 -0
  98. data/spec/fixtures/cassette_spec/1_x_cassette.yml +110 -0
  99. data/spec/fixtures/cassette_spec/empty.yml +0 -0
  100. data/spec/fixtures/cassette_spec/example.yml +111 -0
  101. data/spec/fixtures/cassette_spec/with_localhost_requests.yml +111 -0
  102. data/spec/fixtures/fake_example_responses.yml +110 -0
  103. data/spec/fixtures/match_requests_on.yml +187 -0
  104. data/spec/lib/vcr/cassette/erb_renderer_spec.rb +53 -0
  105. data/spec/lib/vcr/cassette/http_interaction_list_spec.rb +295 -0
  106. data/spec/lib/vcr/cassette/migrator_spec.rb +195 -0
  107. data/spec/lib/vcr/cassette/persisters/file_system_spec.rb +69 -0
  108. data/spec/lib/vcr/cassette/persisters_spec.rb +39 -0
  109. data/spec/lib/vcr/cassette/serializers_spec.rb +176 -0
  110. data/spec/lib/vcr/cassette_spec.rb +618 -0
  111. data/spec/lib/vcr/configuration_spec.rb +326 -0
  112. data/spec/lib/vcr/deprecations_spec.rb +85 -0
  113. data/spec/lib/vcr/errors_spec.rb +162 -0
  114. data/spec/lib/vcr/extensions/net_http_response_spec.rb +86 -0
  115. data/spec/lib/vcr/library_hooks/excon_spec.rb +104 -0
  116. data/spec/lib/vcr/library_hooks/fakeweb_spec.rb +169 -0
  117. data/spec/lib/vcr/library_hooks/faraday_spec.rb +68 -0
  118. data/spec/lib/vcr/library_hooks/typhoeus_0.4_spec.rb +36 -0
  119. data/spec/lib/vcr/library_hooks/typhoeus_spec.rb +162 -0
  120. data/spec/lib/vcr/library_hooks/webmock_spec.rb +118 -0
  121. data/spec/lib/vcr/library_hooks_spec.rb +51 -0
  122. data/spec/lib/vcr/middleware/faraday_spec.rb +182 -0
  123. data/spec/lib/vcr/middleware/rack_spec.rb +115 -0
  124. data/spec/lib/vcr/request_ignorer_spec.rb +70 -0
  125. data/spec/lib/vcr/request_matcher_registry_spec.rb +345 -0
  126. data/spec/lib/vcr/structs_spec.rb +732 -0
  127. data/spec/lib/vcr/test_frameworks/cucumber_spec.rb +107 -0
  128. data/spec/lib/vcr/test_frameworks/rspec_spec.rb +83 -0
  129. data/spec/lib/vcr/util/hooks_spec.rb +158 -0
  130. data/spec/lib/vcr/util/internet_connection_spec.rb +37 -0
  131. data/spec/lib/vcr/util/version_checker_spec.rb +31 -0
  132. data/spec/lib/vcr/version_spec.rb +27 -0
  133. data/spec/lib/vcr_spec.rb +349 -0
  134. data/spec/monkey_patches.rb +182 -0
  135. data/spec/spec_helper.rb +62 -0
  136. data/spec/support/configuration_stubbing.rb +8 -0
  137. data/spec/support/cucumber_helpers.rb +35 -0
  138. data/spec/support/fixnum_extension.rb +10 -0
  139. data/spec/support/http_library_adapters.rb +289 -0
  140. data/spec/support/limited_uri.rb +21 -0
  141. data/spec/support/ruby_interpreter.rb +7 -0
  142. data/spec/support/shared_example_groups/excon.rb +63 -0
  143. data/spec/support/shared_example_groups/hook_into_http_library.rb +594 -0
  144. data/spec/support/shared_example_groups/request_hooks.rb +59 -0
  145. data/spec/support/sinatra_app.rb +86 -0
  146. data/spec/support/vcr_localhost_server.rb +76 -0
  147. data/spec/support/vcr_stub_helpers.rb +17 -0
  148. metadata +677 -0
@@ -0,0 +1,196 @@
1
+ require 'vcr/util/version_checker'
2
+ require 'fakeweb'
3
+ require 'net/http'
4
+ require 'vcr/extensions/net_http_response'
5
+ require 'vcr/request_handler'
6
+ require 'set'
7
+
8
+ VCR::VersionChecker.new('FakeWeb', FakeWeb::VERSION, '1.3.0').check_version!
9
+
10
+ module VCR
11
+ class LibraryHooks
12
+ # @private
13
+ module FakeWeb
14
+ # @private
15
+ class RequestHandler < ::VCR::RequestHandler
16
+ attr_reader :net_http, :request, :request_body, :response_block
17
+ def initialize(net_http, request, request_body = nil, &response_block)
18
+ @net_http, @request, @request_body, @response_block =
19
+ net_http, request, request_body, response_block
20
+ @stubbed_response, @vcr_response, @recursing = nil, nil, false
21
+ end
22
+
23
+ def handle
24
+ super
25
+ ensure
26
+ invoke_after_request_hook(@vcr_response) unless @recursing
27
+ end
28
+
29
+ private
30
+
31
+ def externally_stubbed?
32
+ ::FakeWeb.registered_uri?(request_method, uri)
33
+ end
34
+
35
+ def on_externally_stubbed_request
36
+ # just perform the request--FakeWeb will handle it
37
+ perform_request(:started)
38
+ end
39
+
40
+ def on_recordable_request
41
+ perform_request(net_http.started?, :record_interaction)
42
+ end
43
+
44
+ def on_stubbed_by_vcr_request
45
+ with_exclusive_fakeweb_stub(stubbed_response) do
46
+ # force it to be considered started since it doesn't
47
+ # recurse in this case like the others.
48
+ perform_request(:started)
49
+ end
50
+ end
51
+
52
+ def on_ignored_request
53
+ perform_request(net_http.started?)
54
+ end
55
+
56
+ def perform_request(started, record_interaction = false)
57
+ # Net::HTTP calls #request recursively in certain circumstances.
58
+ # We only want to record the request when the request is started, as
59
+ # that is the final time through #request.
60
+ unless started
61
+ @recursing = true
62
+ request.instance_variable_set(:@__vcr_request_handler, recursive_request_handler)
63
+ return net_http.request_without_vcr(request, request_body, &response_block)
64
+ end
65
+
66
+ net_http.request_without_vcr(request, request_body) do |response|
67
+ @vcr_response = vcr_response_from(response)
68
+
69
+ if record_interaction
70
+ VCR.record_http_interaction VCR::HTTPInteraction.new(vcr_request, @vcr_response)
71
+ end
72
+
73
+ response.extend VCR::Net::HTTPResponse # "unwind" the response
74
+ response_block.call(response) if response_block
75
+ end
76
+ end
77
+
78
+ def uri
79
+ @uri ||= ::FakeWeb::Utility.request_uri_as_string(net_http, request)
80
+ end
81
+
82
+ def response_hash(response)
83
+ (response.headers || {}).merge(
84
+ :body => response.body,
85
+ :status => [response.status.code.to_s, response.status.message]
86
+ )
87
+ end
88
+
89
+ def with_exclusive_fakeweb_stub(response)
90
+ original_map = ::FakeWeb::Registry.instance.uri_map.dup
91
+ ::FakeWeb.clean_registry
92
+ ::FakeWeb.register_uri(:any, /.*/, response_hash(response))
93
+
94
+ begin
95
+ return yield
96
+ ensure
97
+ ::FakeWeb::Registry.instance.uri_map = original_map
98
+ end
99
+ end
100
+
101
+ def request_method
102
+ request.method.downcase.to_sym
103
+ end
104
+
105
+ def vcr_request
106
+ @vcr_request ||= VCR::Request.new \
107
+ request_method,
108
+ uri,
109
+ (request_body || request.body),
110
+ request.to_hash
111
+ end
112
+
113
+ def vcr_response_from(response)
114
+ VCR::Response.new \
115
+ VCR::ResponseStatus.new(response.code.to_i, response.message),
116
+ response.to_hash,
117
+ response.body,
118
+ response.http_version
119
+ end
120
+
121
+ def recursive_request_handler
122
+ @recursive_request_handler ||= RecursiveRequestHandler.new(
123
+ @after_hook_typed_request.type, @stubbed_response, @vcr_request,
124
+ @net_http, @request, @request_body, &@response_block
125
+ )
126
+ end
127
+ end
128
+
129
+ class RecursiveRequestHandler < RequestHandler
130
+ attr_reader :stubbed_response
131
+
132
+ def initialize(request_type, stubbed_response, vcr_request, *args, &response_block)
133
+ @request_type, @stubbed_response, @vcr_request =
134
+ request_type, stubbed_response, vcr_request
135
+ super(*args)
136
+ end
137
+
138
+ def handle
139
+ set_typed_request_for_after_hook(@request_type)
140
+ send "on_#{@request_type}_request"
141
+ ensure
142
+ invoke_after_request_hook(@vcr_response)
143
+ end
144
+
145
+ def request_type(*args)
146
+ @request_type
147
+ end
148
+ end
149
+ end
150
+ end
151
+ end
152
+
153
+ # @private
154
+ module Net
155
+ # @private
156
+ class HTTP
157
+ unless method_defined?(:request_with_vcr)
158
+ def request_with_vcr(request, *args, &block)
159
+ if VCR.turned_on?
160
+ handler = request.instance_eval do
161
+ remove_instance_variable(:@__vcr_request_handler) if defined?(@__vcr_request_handler)
162
+ end || VCR::LibraryHooks::FakeWeb::RequestHandler.new(self, request, *args, &block)
163
+
164
+ handler.handle
165
+ else
166
+ request_without_vcr(request, *args, &block)
167
+ end
168
+ end
169
+
170
+ alias request_without_vcr request
171
+ alias request request_with_vcr
172
+ end
173
+ end
174
+ end
175
+
176
+ # @private
177
+ module FakeWeb
178
+ class << self
179
+ # ensure HTTP requests are always allowed; VCR takes care of disallowing
180
+ # them at the appropriate times in its hook
181
+ def allow_net_connect_with_vcr?(*args)
182
+ VCR.turned_on? ? true : allow_net_connect_without_vcr?(*args)
183
+ end
184
+
185
+ alias allow_net_connect_without_vcr? allow_net_connect?
186
+ alias allow_net_connect? allow_net_connect_with_vcr?
187
+ end unless respond_to?(:allow_net_connect_with_vcr?)
188
+ end
189
+
190
+ VCR.configuration.after_library_hooks_loaded do
191
+ if defined?(WebMock)
192
+ raise ArgumentError.new("You have configured VCR to hook into both :fakeweb and :webmock. You cannot use both.")
193
+ end
194
+ ::Kernel.warn "WARNING: VCR's FakeWeb integration is deprecated and will be removed in VCR 3.0."
195
+ end
196
+
@@ -0,0 +1,51 @@
1
+ require 'vcr/middleware/faraday'
2
+
3
+ module VCR
4
+ class LibraryHooks
5
+ # @private
6
+ module Faraday
7
+ # @private
8
+ module BuilderClassExtension
9
+ def new(*args)
10
+ super.extend BuilderInstanceExtension
11
+ end
12
+
13
+ if defined?(::Faraday::RackBuilder)
14
+ ::Faraday::RackBuilder.extend self
15
+ else
16
+ ::Faraday::Builder.extend self
17
+ end
18
+ end
19
+
20
+ # @private
21
+ module BuilderInstanceExtension
22
+ def lock!(*args)
23
+ insert_vcr_middleware
24
+ super
25
+ end
26
+
27
+ private
28
+
29
+ def insert_vcr_middleware
30
+ return if handlers.any? { |h| h.klass == VCR::Middleware::Faraday }
31
+ adapter_index = handlers.index { |h| h.klass < ::Faraday::Adapter }
32
+ adapter_index ||= handlers.size
33
+ warn_about_after_adapter_middleware(adapter_index)
34
+ insert_before(adapter_index, VCR::Middleware::Faraday)
35
+ end
36
+
37
+ def warn_about_after_adapter_middleware(adapter_index)
38
+ after_adapter_middleware_count = (handlers.size - adapter_index - 1)
39
+ return if after_adapter_middleware_count < 1
40
+
41
+ after_adapter_middlewares = handlers.last(after_adapter_middleware_count)
42
+ warn "WARNING: The Faraday connection stack contains middleware after " +
43
+ "the HTTP adapter (#{after_adapter_middlewares.map(&:inspect).join(', ')}). " +
44
+ "This is a non-standard configuration and VCR may not be able to " +
45
+ "record the HTTP requests made through this Faraday connection."
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
51
+
@@ -0,0 +1,120 @@
1
+ require 'vcr/util/version_checker'
2
+ require 'vcr/request_handler'
3
+ require 'typhoeus'
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
12
+ # @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
31
+
32
+ def externally_stubbed?
33
+ ::Typhoeus::Expectation.find_by(request)
34
+ end
35
+
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
40
+
41
+ def on_unhandled_request
42
+ invoke_after_request_hook(nil)
43
+ super
44
+ end
45
+
46
+ def on_stubbed_by_vcr_request
47
+ ::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
+ end
56
+
57
+ def stubbed_response_headers
58
+ @stubbed_response_headers ||= {}.tap do |hash|
59
+ stubbed_response.headers.each do |key, values|
60
+ hash[key] = values.size == 1 ? values.first : values
61
+ end if stubbed_response.headers
62
+ end
63
+ end
64
+
65
+ if ::Typhoeus::Request.method_defined?(:encoded_body)
66
+ def request_body
67
+ request.encoded_body
68
+ end
69
+ else
70
+ def request_body
71
+ request.options.fetch(:body, "")
72
+ end
73
+ end
74
+ end
75
+
76
+ # @private
77
+ def self.vcr_response_from(response)
78
+ VCR::Response.new \
79
+ VCR::ResponseStatus.new(response.code, response.status_message),
80
+ response.headers,
81
+ response.body,
82
+ response.http_version,
83
+ { "effective_url" => response.effective_url }
84
+ end
85
+
86
+ ::Typhoeus.on_complete do |response|
87
+ request = response.request
88
+ unless VCR.library_hooks.disabled?(:typhoeus)
89
+ vcr_response = vcr_response_from(response)
90
+ typed_vcr_request = request.send(:remove_instance_variable, :@__typed_vcr_request)
91
+
92
+ unless request.response.mock
93
+ http_interaction = VCR::HTTPInteraction.new(typed_vcr_request, vcr_response)
94
+ VCR.record_http_interaction(http_interaction)
95
+ end
96
+
97
+ VCR.configuration.invoke_hook(:after_http_request, typed_vcr_request, vcr_response)
98
+ end
99
+ end
100
+
101
+ ::Typhoeus.before do |request|
102
+ if response = VCR::LibraryHooks::Typhoeus::RequestHandler.new(request).handle
103
+ request.finish(response)
104
+ else
105
+ true
106
+ end
107
+ end
108
+ end
109
+ end
110
+ end
111
+ end
112
+
113
+ VCR.configuration.after_library_hooks_loaded do
114
+ # ensure WebMock's Typhoeus adapter does not conflict with us here
115
+ # (i.e. to double record requests or whatever).
116
+ if defined?(WebMock::HttpLibAdapters::TyphoeusAdapter)
117
+ WebMock::HttpLibAdapters::TyphoeusAdapter.disable!
118
+ end
119
+ end
120
+
@@ -0,0 +1,103 @@
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
+