Skip to content

Commit

Permalink
Add deprecations.
Browse files Browse the repository at this point in the history
The following are deprecated:

- VCR::Config.ignore_localhost?
- VCR::HttpStubbingAdapters::{FakeWeb,WebMock,Typhoeus,Faraday}.ignore_localhost?
- VCR::HttpStubbingAdapters::FakeWeb::LOCALHOST_REGEX
  • Loading branch information
myronmarston committed Jan 31, 2011
1 parent bf907f7 commit dbfb3f8
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 15 deletions.
6 changes: 1 addition & 5 deletions lib/vcr/config.rb
Expand Up @@ -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?
Expand All @@ -68,3 +63,4 @@ def uri_should_be_ignored?(uri)
end
end
end

29 changes: 20 additions & 9 deletions 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

Expand Down
7 changes: 6 additions & 1 deletion lib/vcr/http_stubbing_adapters/fakeweb.rb
Expand Up @@ -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'
Expand Down Expand Up @@ -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
Expand Down
52 changes: 52 additions & 0 deletions 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 }
Expand All @@ -28,6 +78,8 @@
described_class.http_stubbing_library = :webmock
end
end

it_behaves_like '.ignore_localhost? deprecation'
end

describe VCR::Cassette do
Expand Down

0 comments on commit dbfb3f8

Please sign in to comment.