Skip to content

Commit

Permalink
Use #ignore_localhost? rather than #ignore_localhost, since it's more…
Browse files Browse the repository at this point in the history
… idiomatic ruby.
  • Loading branch information
myronmarston committed Jun 22, 2010
1 parent ef8519a commit 29925bc
Show file tree
Hide file tree
Showing 12 changed files with 21 additions and 18 deletions.
2 changes: 1 addition & 1 deletion features/step_definitions/vcr_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module VCRHelpers
def static_rack_server(response_string)
orig_ignore_localhost = VCR.http_stubbing_adapter.ignore_localhost
orig_ignore_localhost = VCR.http_stubbing_adapter.ignore_localhost?
VCR.http_stubbing_adapter.ignore_localhost = true

begin
Expand Down
4 changes: 2 additions & 2 deletions lib/vcr.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def config
yield VCR::Config
http_stubbing_adapter.check_version!
http_stubbing_adapter.http_connections_allowed = false
http_stubbing_adapter.ignore_localhost = VCR::Config.ignore_localhost
http_stubbing_adapter.ignore_localhost = VCR::Config.ignore_localhost?
end

def cucumber_tags(&block)
Expand All @@ -62,7 +62,7 @@ def http_stubbing_adapter

def record_http_interaction(interaction)
return unless cassette = current_cassette
return if http_stubbing_adapter.ignore_localhost &&
return if http_stubbing_adapter.ignore_localhost? &&
LOCALHOST_ALIASES.include?(URI.parse(interaction.uri).host)

cassette.record_http_interaction(interaction)
Expand Down
2 changes: 1 addition & 1 deletion lib/vcr/cassette.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def load_recorded_interactions
@original_recorded_interactions = begin
interactions = YAML.load(raw_yaml_content)

if VCR.http_stubbing_adapter.ignore_localhost
if VCR.http_stubbing_adapter.ignore_localhost?
interactions.reject! do |i|
i.uri.is_a?(String) && VCR::LOCALHOST_ALIASES.include?(URI.parse(i.uri).host)
end
Expand Down
4 changes: 2 additions & 2 deletions lib/vcr/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ def ignore_localhost=(value)
@ignore_localhost = value
end

def ignore_localhost
VCR.http_stubbing_adapter ? VCR.http_stubbing_adapter.ignore_localhost : @ignore_localhost
def ignore_localhost?
VCR.http_stubbing_adapter ? VCR.http_stubbing_adapter.ignore_localhost? : @ignore_localhost
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/vcr/deprecations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ module VCR
class Cassette
def allow_real_http_requests_to?(uri)
warn "WARNING: VCR::Cassette#allow_real_http_requests_to? is deprecated and should no longer be used."
VCR.http_stubbing_adapter.ignore_localhost && VCR::LOCALHOST_ALIASES.include?(uri.host)
VCR.http_stubbing_adapter.ignore_localhost? && VCR::LOCALHOST_ALIASES.include?(uri.host)
end

private

def deprecate_old_cassette_options(options)
message = "VCR's :allow_real_http cassette option is deprecated. Instead, use the ignore_localhost configuration option."
if options[:allow_real_http] == :localhost
@original_ignore_localhost = VCR.http_stubbing_adapter.ignore_localhost
@original_ignore_localhost = VCR.http_stubbing_adapter.ignore_localhost?
VCR.http_stubbing_adapter.ignore_localhost = true
Kernel.warn "WARNING: #{message}"
elsif options[:allow_real_http]
Expand Down
2 changes: 1 addition & 1 deletion lib/vcr/extensions/net_http.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class HTTP
def request_with_vcr(request, body = nil, &block)
uri = URI.parse(VCR.http_stubbing_adapter.request_uri(self, request))

if VCR::LOCALHOST_ALIASES.include?(uri.host) && VCR.http_stubbing_adapter.ignore_localhost
if VCR::LOCALHOST_ALIASES.include?(uri.host) && VCR.http_stubbing_adapter.ignore_localhost?
VCR.http_stubbing_adapter.with_http_connections_allowed_set_to(true) do
return request_without_vcr(request, body, &block)
end
Expand Down
5 changes: 4 additions & 1 deletion lib/vcr/http_stubbing_adapters/fakeweb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,10 @@ def request_uri(net_http, request)
"#{protocol}://#{userinfo}#{net_http.address}:#{net_http.port}#{path}"
end

attr_accessor :ignore_localhost
attr_writer :ignore_localhost
def ignore_localhost?
@ignore_localhost
end

private

Expand Down
2 changes: 1 addition & 1 deletion lib/vcr/http_stubbing_adapters/webmock.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def ignore_localhost=(value)
::WebMock::Config.instance.allow_localhost = value
end

def ignore_localhost
def ignore_localhost?
::WebMock::Config.instance.allow_localhost
end

Expand Down
2 changes: 1 addition & 1 deletion spec/cassette_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def cassette_body(name, options = {})
expected_uri_hosts += VCR::LOCALHOST_ALIASES unless ignore_localhost

it "#{ ignore_localhost ? 'does not load' : 'loads' } localhost interactions from the cassette file when http_stubbing_adapter.ignore_localhost is set to #{ignore_localhost}" do
VCR.http_stubbing_adapter.stub!(:ignore_localhost).and_return(ignore_localhost)
VCR.http_stubbing_adapter.stub!(:ignore_localhost?).and_return(ignore_localhost)
VCR::Config.cassette_library_dir = File.expand_path(File.dirname(__FILE__) + "/fixtures/#{RUBY_VERSION}/cassette_spec")
cassette = VCR::Cassette.new('with_localhost_requests', :record => record_mode)
cassette.recorded_interactions.map { |i| URI.parse(i.uri).host }.should =~ expected_uri_hosts
Expand Down
6 changes: 3 additions & 3 deletions spec/config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,20 +48,20 @@
end

describe '#ignore_localhost' do
it 'sets VCR.http_stubbing_adapter.ignore_localhost' do
it 'sets VCR.http_stubbing_adapter.ignore_localhost?' do
[true, false].each do |val|
VCR.http_stubbing_adapter.ignore_localhost = !val
expect {
VCR::Config.ignore_localhost = val
}.to change { VCR.http_stubbing_adapter.ignore_localhost }.from(!val).to(val)
}.to change { VCR.http_stubbing_adapter.ignore_localhost? }.from(!val).to(val)
end
end

it 'stores the value even when VCR.http_stubbing_adapter is nil' do
VCR.stub!(:http_stubbing_adapter).and_return(nil)
[true, false].each do |val|
VCR::Config.ignore_localhost = val
VCR::Config.ignore_localhost.should == val
VCR::Config.ignore_localhost?.should == val
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions spec/deprecations_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

it "sets the http_stubbing_adapter's ignore_localhost attribute to true" do
subject
VCR.http_stubbing_adapter.ignore_localhost.should be_true
VCR.http_stubbing_adapter.ignore_localhost?.should be_true
end

it "prints a warning: VCR's :allow_real_http cassette option is deprecated. Instead, use the ignore_localhost configuration option." do
Expand All @@ -33,7 +33,7 @@

it "reverts ignore_localhost when the cassette is ejected" do
subject.eject
VCR.http_stubbing_adapter.ignore_localhost.should == orig_ignore_localhost
VCR.http_stubbing_adapter.ignore_localhost?.should == orig_ignore_localhost
end

{
Expand Down
2 changes: 1 addition & 1 deletion spec/vcr_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def insert_cassette

def self.with_ignore_localhost_set_to(value, &block)
context "when http_stubbing_adapter.ignore_localhost is #{value}" do
before(:each) { VCR.http_stubbing_adapter.stub!(:ignore_localhost).and_return(value) }
before(:each) { VCR.http_stubbing_adapter.stub!(:ignore_localhost?).and_return(value) }

instance_eval(&block)
end
Expand Down

0 comments on commit 29925bc

Please sign in to comment.