diff --git a/lib/vcr/config.rb b/lib/vcr/config.rb index c7ab4b29..52d31b6f 100644 --- a/lib/vcr/config.rb +++ b/lib/vcr/config.rb @@ -48,11 +48,6 @@ def ignore_localhost=(value) end end - # TODO: deprecate this - def ignore_localhost? - (VCR::LOCALHOST_ALIASES - ignored_hosts).empty? - end - def allow_http_connections_when_no_cassette=(value) @allow_http_connections_when_no_cassette = value VCR.http_stubbing_adapter.set_http_connections_allowed_to_default if http_stubbing_libraries.any? @@ -68,3 +63,4 @@ def uri_should_be_ignored?(uri) end end end + diff --git a/lib/vcr/deprecations.rb b/lib/vcr/deprecations.rb index cae7017f..3eedf146 100644 --- a/lib/vcr/deprecations.rb +++ b/lib/vcr/deprecations.rb @@ -1,15 +1,26 @@ module VCR - module Config - class << self - def http_stubbing_library - warn "WARNING: `VCR::Config.http_stubbing_library` is deprecated. Use `VCR::Config.http_stubbing_libraries` instead." - @http_stubbing_libraries && @http_stubbing_libraries.first + module HttpStubbingAdapters + module Common + def ignore_localhost? + VCR::Config.ignore_localhost? end + end + end - def http_stubbing_library=(library) - warn "WARNING: `VCR::Config.http_stubbing_library = #{library.inspect}` is deprecated. Use `VCR::Config.stub_with #{library.inspect}` instead." - stub_with library - end + module Config + def http_stubbing_library + warn "WARNING: `VCR::Config.http_stubbing_library` is deprecated. Use `VCR::Config.http_stubbing_libraries` instead." + @http_stubbing_libraries && @http_stubbing_libraries.first + end + + def http_stubbing_library=(library) + warn "WARNING: `VCR::Config.http_stubbing_library = #{library.inspect}` is deprecated. Use `VCR::Config.stub_with #{library.inspect}` instead." + stub_with library + end + + def ignore_localhost? + warn "WARNING: `VCR::Config.ignore_localhost?` is deprecated. Check the list of ignored hosts using `VCR::Config.ignored_hosts` instead." + (VCR::LOCALHOST_ALIASES - ignored_hosts).empty? end end diff --git a/lib/vcr/http_stubbing_adapters/fakeweb.rb b/lib/vcr/http_stubbing_adapters/fakeweb.rb index 09526140..9a865084 100644 --- a/lib/vcr/http_stubbing_adapters/fakeweb.rb +++ b/lib/vcr/http_stubbing_adapters/fakeweb.rb @@ -7,7 +7,6 @@ module FakeWeb include VCR::HttpStubbingAdapters::Common extend self - # TODO: deprecate regex constant UNSUPPORTED_REQUEST_MATCH_ATTRIBUTES = [:body, :headers] MINIMUM_VERSION = '1.3.0' @@ -98,6 +97,12 @@ def validate_match_attributes(match_attributes) raise UnsupportedRequestMatchAttributeError.new("FakeWeb does not support matching requests on #{invalid_attributes.join(' or ')}") end end + + def self.const_missing(const) + return super unless const == :LOCALHOST_REGEX + warn "WARNING: `VCR::HttpStubbingAdapters::FakeWeb::LOCALHOST_REGEX` is deprecated." + VCR::Regexes.url_regex_for_hosts(VCR::LOCALHOST_ALIASES) + end end end end diff --git a/spec/vcr/deprecations_spec.rb b/spec/vcr/deprecations_spec.rb index d5fe27cb..6ae1c62e 100644 --- a/spec/vcr/deprecations_spec.rb +++ b/spec/vcr/deprecations_spec.rb @@ -1,8 +1,58 @@ require 'spec_helper' +shared_examples_for '.ignore_localhost? deprecation' do + it 'returns false when no hosts are ignored' do + VCR::Config.ignored_hosts.should be_empty + described_class.ignore_localhost?.should be_false + end + + it 'returns false when only non-local hosts are ignored' do + VCR::Config.ignore_hosts 'example.com' + described_class.ignore_localhost?.should be_false + end + + it 'returns false when only some localhost aliases are ignored' do + aliases = VCR::LOCALHOST_ALIASES.dup + aliases.pop + VCR::Config.ignore_hosts *aliases + described_class.ignore_localhost?.should be_false + end + + it 'returns true when all localhost aliases are ignored, even if some other hosts are ignored, too' do + VCR::Config.ignore_hosts 'example.com', *VCR::LOCALHOST_ALIASES + described_class.ignore_localhost?.should be_true + end + + it 'prints a warning: WARNING: `VCR::Config.ignore_localhost?` is deprecated. Check the list of ignored hosts using `VCR::Config.ignored_hosts` instead.' do + VCR::Config.should_receive(:warn).with(/Check the list of ignored hosts using `VCR::Config.ignored_hosts` instead/) + described_class.ignore_localhost? + end +end + describe 'Deprecations' do disable_warnings + VCR::HttpStubbingAdapters::Common.adapters.each do |adapter| + describe adapter do + it_behaves_like '.ignore_localhost? deprecation' + end + end + + describe VCR::HttpStubbingAdapters::FakeWeb do + describe 'LOCALHOST_REGEX constant' do + subject { described_class::LOCALHOST_REGEX } + + it 'refers to the expected regex' do + should == %r|\Ahttps?://((\w+:)?\w+@)?(#{VCR::LOCALHOST_ALIASES.map { |a| Regexp.escape(a) }.join('|')})(:\d+)?/|i + end + + it 'prints a warning: WARNING: `VCR::HttpStubbingAdapters::FakeWeb::LOCALHOST_REGEX` is deprecated.' do + described_class.should_receive(:warn).with("WARNING: `VCR::HttpStubbingAdapters::FakeWeb::LOCALHOST_REGEX` is deprecated.") + subject + end + end + end + describe VCR::Config do describe '.http_stubbing_library' do before(:each) { described_class.stub_with :webmock, :typhoeus } @@ -28,6 +78,8 @@ described_class.http_stubbing_library = :webmock end end + + it_behaves_like '.ignore_localhost? deprecation' end describe VCR::Cassette do