lib/vcr/http_stubbing_adapters/common.rb in vcr-1.3.3 vs lib/vcr/http_stubbing_adapters/common.rb in vcr-1.4.0
- old
+ new
@@ -1,26 +1,53 @@
module VCR
module HttpStubbingAdapters
autoload :FakeWeb, 'vcr/http_stubbing_adapters/fakeweb'
+ autoload :Faraday, 'vcr/http_stubbing_adapters/faraday'
autoload :MultiObjectProxy, 'vcr/http_stubbing_adapters/multi_object_proxy'
autoload :Typhoeus, 'vcr/http_stubbing_adapters/typhoeus'
autoload :WebMock, 'vcr/http_stubbing_adapters/webmock'
class UnsupportedRequestMatchAttributeError < ArgumentError; end
module Common
- def self.add_vcr_info_to_exception_message(exception_klass)
- exception_klass.class_eval do
- def initialize(message)
- super(message + '. ' + VCR::HttpStubbingAdapters::Common::RECORDING_INSTRUCTIONS)
+ class << self
+ attr_accessor :exclusively_enabled_adapter
+
+ def add_vcr_info_to_exception_message(exception_klass)
+ exception_klass.class_eval do
+ def initialize(message)
+ super(message + '. ' + VCR::HttpStubbingAdapters::Common::RECORDING_INSTRUCTIONS)
+ end
end
end
+
+ def adapters
+ @adapters ||= []
+ end
+
+ def included(adapter)
+ adapters << adapter
+ end
end
RECORDING_INSTRUCTIONS = "You can use VCR to automatically record this request and replay it later. " +
"For more details, visit the VCR wiki at: http://github.com/myronmarston/vcr/wiki"
+ def enabled?
+ [nil, self].include? VCR::HttpStubbingAdapters::Common.exclusively_enabled_adapter
+ end
+
+ def exclusively_enabled
+ VCR::HttpStubbingAdapters::Common.exclusively_enabled_adapter = self
+
+ begin
+ yield
+ ensure
+ VCR::HttpStubbingAdapters::Common.exclusively_enabled_adapter = nil
+ end
+ end
+
def check_version!
version_too_low, version_too_high = compare_version
if version_too_low
raise "You are using #{library_name} #{version}. VCR requires version #{version_requirement}."
@@ -29,9 +56,13 @@
end
end
def library_name
@library_name ||= self.to_s.split('::').last
+ end
+
+ def set_http_connections_allowed_to_default
+ self.http_connections_allowed = VCR::Config.allow_http_connections_when_no_cassette?
end
private
def compare_version