spec/monkey_patches.rb in vcr-2.0.0.rc1 vs spec/monkey_patches.rb in vcr-2.0.0.rc2
- old
+ new
@@ -12,27 +12,34 @@
[NET_HTTP_SINGLETON, :socket_type]
]
ALL_MONKEY_PATCHES = NET_HTTP_MONKEY_PATCHES.dup
- ALL_MONKEY_PATCHES << [Typhoeus::Hydra::Stubbing::SharedMethods, :find_stub_from_request] if defined?(::Typhoeus)
-
def enable!(scope)
case scope
when :fakeweb
realias_net_http :with_fakeweb
enable!(:vcr) # fakeweb hook relies upon VCR's Net::HTTP monkey patch
when :webmock
::WebMock.reset!
::WebMock::HttpLibAdapters::NetHttpAdapter.enable!
::WebMock::HttpLibAdapters::TyphoeusAdapter.enable! if defined?(::Typhoeus)
+ ::WebMock::HttpLibAdapters::ExconAdapter.enable! if defined?(::Excon)
$original_webmock_callbacks.each do |cb|
::WebMock::CallbackRegistry.add_callback(cb[:options], cb[:block])
end
when :typhoeus
- Typhoeus::Hydra.global_hooks = $original_typhoeus_hooks
- realias Typhoeus::Hydra::Stubbing::SharedMethods, :find_stub_from_request, :with_vcr
+ ::Typhoeus::Hydra.global_hooks = $original_typhoeus_global_hooks
+ ::Typhoeus::Hydra.stub_finders.clear
+ $original_typhoeus_stub_finders.each do |finder|
+ ::Typhoeus::Hydra.stub_finders << finder
+ end
+ when :excon
+ $original_excon_stubs.each do |stub|
+ ::Excon.stubs << stub
+ end
+ ::Excon.defaults[:mock] = true
when :vcr
realias Net::HTTP, :request, :with_vcr
else raise ArgumentError.new("Unexpected scope: #{scope}")
end
end
@@ -41,17 +48,24 @@
realias_all :without_monkeypatches
if defined?(::WebMock::HttpLibAdapters)
::WebMock::HttpLibAdapters::NetHttpAdapter.disable!
::WebMock::HttpLibAdapters::TyphoeusAdapter.disable! if defined?(::Typhoeus)
+ ::WebMock::HttpLibAdapters::ExconAdapter.disable! if defined?(::Excon)
::WebMock::CallbackRegistry.reset
::WebMock::StubRegistry.instance.request_stubs = []
end
if defined?(::Typhoeus)
- Typhoeus::Hydra.clear_global_hooks
+ ::Typhoeus::Hydra.clear_global_hooks
+ ::Typhoeus::Hydra.stub_finders.clear
end
+
+ if defined?(::Excon)
+ ::Excon.stubs.clear
+ ::Excon.defaults[:mock] = false
+ end
end
def init
# capture the monkey patched definitions so we can realias to them in the future
ALL_MONKEY_PATCHES.each do |mp|
@@ -116,19 +130,17 @@
require 'patron'
require 'em-http-request'
require 'curb'
require 'vcr/library_hooks/typhoeus'
- $original_typhoeus_hooks = Typhoeus::Hydra.global_hooks.dup
-
- # define an alias that we can re-alias to in the future
- Typhoeus::Hydra::Stubbing::SharedMethods.class_eval do
- alias find_stub_from_request_with_vcr find_stub_from_request
- end
+ $typhoeus_after_loaded_hook = VCR.configuration.hooks[:after_library_hooks_loaded].last
+ $original_typhoeus_global_hooks = Typhoeus::Hydra.global_hooks.dup
+ $original_typhoeus_stub_finders = Typhoeus::Hydra.stub_finders.dup
end
require 'vcr/library_hooks/fakeweb'
+$fakeweb_after_loaded_hook = VCR.configuration.hooks[:after_library_hooks_loaded].last
# All Net::HTTP monkey patches have now been loaded, so capture the
# appropriate method definitions so we can disable them later.
MonkeyPatches.init
@@ -137,16 +149,19 @@
MonkeyPatches.disable_all!
require 'vcr/library_hooks/webmock'
$original_webmock_callbacks = ::WebMock::CallbackRegistry.callbacks
+require 'vcr/library_hooks/excon'
+$excon_after_loaded_hook = VCR.configuration.hooks[:after_library_hooks_loaded].last
+$original_excon_stubs = ::Excon.stubs.dup
+
# disable all by default; we'll enable specific ones when we need them
MonkeyPatches.disable_all!
RSpec.configure do |config|
- [:fakeweb, :webmock, :vcr, :typhoeus].each do |scope|
+ [:fakeweb, :webmock, :vcr, :typhoeus, :excon].each do |scope|
config.before(:all, :with_monkey_patches => scope) { MonkeyPatches.enable!(scope) }
config.after(:all, :with_monkey_patches => scope) { MonkeyPatches.disable_all! }
end
end
-require 'vcr/library_hooks/excon'