Skip to content

Commit

Permalink
Remove #after_adapters_loaded from adapter interface.
Browse files Browse the repository at this point in the history
Instead, use a callback.
  • Loading branch information
myronmarston committed Oct 2, 2011
1 parent cae04f3 commit 80c281b
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 18 deletions.
5 changes: 4 additions & 1 deletion lib/vcr.rb
Expand Up @@ -14,8 +14,11 @@

module VCR
include VariableArgsBlockCaller
include Hooks
extend self

define_hook :after_http_stubbing_adapters_loaded

autoload :BasicObject, 'vcr/util/basic_object'
autoload :CucumberTags, 'vcr/test_frameworks/cucumber'
autoload :InternetConnection, 'vcr/util/internet_connection'
Expand Down Expand Up @@ -107,7 +110,7 @@ def http_stubbing_adapters

adapters = VCR.configuration.http_stubbing_libraries.map { |l| adapter_for(l) }
raise ArgumentError.new("The http stubbing library is not configured.") if adapters.empty?
adapters.each { |a| a.after_adapters_loaded }
invoke_hook(:after_http_stubbing_adapters_loaded)
adapters
end
end
Expand Down
4 changes: 0 additions & 4 deletions lib/vcr/http_stubbing_adapters/common.rb
Expand Up @@ -31,10 +31,6 @@ def enabled?
[nil, self].include? VCR::HttpStubbingAdapters::Common.exclusively_enabled_adapter
end

def after_adapters_loaded
# no-op
end

def exclusively_enabled
VCR::HttpStubbingAdapters::Common.exclusively_enabled_adapter = self

Expand Down
16 changes: 8 additions & 8 deletions lib/vcr/http_stubbing_adapters/typhoeus.rb
Expand Up @@ -8,14 +8,6 @@ module Typhoeus
include VCR::HttpStubbingAdapters::Common
extend self

def after_adapters_loaded
# ensure WebMock's Typhoeus adapter does not conflict with us here
# (i.e. to double record requests or whatever).
if defined?(::WebMock::HttpLibAdapters::TyphoeusAdapter)
::WebMock::HttpLibAdapters::TyphoeusAdapter.disable!
end
end

class RequestHandler
extend Forwardable

Expand Down Expand Up @@ -113,3 +105,11 @@ def find_stub_from_request(request)
end
end

VCR.after_http_stubbing_adapters_loaded do
# ensure WebMock's Typhoeus adapter does not conflict with us here
# (i.e. to double record requests or whatever).
if defined?(WebMock::HttpLibAdapters::TyphoeusAdapter)
WebMock::HttpLibAdapters::TyphoeusAdapter.disable!
end
end

2 changes: 1 addition & 1 deletion lib/vcr/util/hooks.rb
Expand Up @@ -6,7 +6,7 @@ def self.included(klass)
klass.extend(ClassMethods)
end

def invoke_hook(hook, tag, *args)
def invoke_hook(hook, tag=nil, *args)
hooks_for(hook, tag).each do |callback|
call_block(callback, *args)
end
Expand Down
5 changes: 3 additions & 2 deletions spec/vcr/http_stubbing_adapters/typhoeus_spec.rb
Expand Up @@ -17,10 +17,11 @@
end
end

describe ".after_adapters_loaded" do
describe "VCR.after_http_stubbing_adapters_loaded hook", :disable_warnings do
it 'disables the webmock typhoeus adapter so it does not conflict with our typhoeus adapter' do
load "vcr/http_stubbing_adapters/typhoeus.rb"
::WebMock::HttpLibAdapters::TyphoeusAdapter.should_receive(:disable!)
described_class.after_adapters_loaded
VCR.invoke_hook(:after_http_stubbing_adapters_loaded)
end
end
end unless RUBY_PLATFORM == 'java'
Expand Down
6 changes: 4 additions & 2 deletions spec/vcr_spec.rb
Expand Up @@ -204,10 +204,12 @@ def insert_cassette(name = :cassette_test)
end
end

it 'calls #after_adapters_loaded on the configured stubbing adapters' do
VCR::HttpStubbingAdapters::FakeWeb.should_receive(:after_adapters_loaded)
it 'invokes the after_htp_stubbing_adapters_loaded hook' do
called = false
VCR.after_http_stubbing_adapters_loaded { called = true }
VCR.configuration.stub_with :fakeweb
VCR.http_stubbing_adapters
called.should be_true
end

it 'raises an error if both :fakeweb and :webmock are configured' do
Expand Down

0 comments on commit 80c281b

Please sign in to comment.