Permalink
Browse files

Allow newly released WebMock 1.5.0 to be used without a warning.

  • Loading branch information...
myronmarston committed Nov 2, 2010
1 parent 65c599d commit 4b342804bd6b1dde3bc0712f40060aa1d0821287
View
@@ -7,6 +7,7 @@
* Moved documentation from README to [Wiki](http://github.com/myronmarston/vcr/wiki).
* Refactoring and code cleanup.
* Fix InternetConnection.available? so that it memoizes correctly when a connection is not available.
+* Fix WebMock version checking to allow newly released 1.5.0 to be used without a warning.
## 1.2.0 (October 13, 2010)
@@ -19,29 +19,39 @@ def check_version!
version_too_low, version_too_high = compare_version
if version_too_low
- raise "You are using #{library_name} #{version}. VCR requires version #{self::VERSION_REQUIREMENT} or greater."
+ raise "You are using #{library_name} #{version}. VCR requires version #{version_requirement}."
elsif version_too_high
- warn "You are using #{library_name} #{version}. VCR is known to work with #{library_name} ~> #{self::VERSION_REQUIREMENT}. It may not work with this version."
+ warn "You are using #{library_name} #{version}. VCR is known to work with #{library_name} #{version_requirement}. It may not work with this version."
end
end
+ def library_name
+ @library_name ||= self.to_s.split('::').last
+ end
+
private
def compare_version
- major, minor, patch = *version.split('.').map { |v| v.to_i }
- req_major, req_minor, req_patch = *self::VERSION_REQUIREMENT.split('.').map { |v| v.to_i }
+ major, minor, patch = parse_version(version)
+ min_major, min_minor, min_patch = parse_version(self::MINIMUM_VERSION)
+ max_major, max_minor = parse_version(self::MAXIMUM_VERSION)
- return true, false if major < req_major
- return false, true if major > req_major
+ return true, false if major < min_major
+ return false, true if major > max_major
- return true, false if minor < req_minor
- return false, true if minor > req_minor
+ return true, false if minor < min_minor
+ return false, true if minor > max_minor
- return patch < req_patch, false
+ return patch < min_patch, false
end
- def library_name
- @library_name ||= self.to_s.split('::').last
+ def version_requirement
+ max_major, max_minor = parse_version(self::MAXIMUM_VERSION)
+ ">= #{self::MINIMUM_VERSION}, < #{max_major}.#{max_minor + 1}"
+ end
+
+ def parse_version(version)
+ version.split('.').map { |v| v.to_i }
end
def grouped_responses(http_interactions, match_attributes)
@@ -10,7 +10,8 @@ module FakeWeb
UNSUPPORTED_REQUEST_MATCH_ATTRIBUTES = [:body, :headers].freeze
LOCALHOST_REGEX = %r|\Ahttps?://((\w+:)?\w+@)?(#{VCR::LOCALHOST_ALIASES.map { |a| Regexp.escape(a) }.join('|')})(:\d+)?/|i
- VERSION_REQUIREMENT = '1.3.0'
+ MINIMUM_VERSION = '1.3.0'
+ MAXIMUM_VERSION = '1.3'
def http_connections_allowed=(value)
@http_connections_allowed = value
@@ -6,7 +6,8 @@ module WebMock
include VCR::HttpStubbingAdapters::Common
extend self
- VERSION_REQUIREMENT = '1.4.0'
+ MINIMUM_VERSION = '1.4.0'
+ MAXIMUM_VERSION = '1.5'
def http_connections_allowed=(value)
::WebMock::Config.instance.allow_net_connect = value
@@ -5,33 +5,18 @@
it_behaves_like 'an http stubbing adapter', ['net/http'], [:method, :uri, :host, :path], :needs_net_http_extension
- describe '#check_version!' do
+ it_performs('version checking',
+ :valid => %w[ 1.3.0 1.3.1 1.3.99 ],
+ :too_low => %w[ 1.2.8 1.1.30 0.30.30 ],
+ :too_high => %w[ 1.4.0 1.10.0 2.0.0 ]
+ ) do
disable_warnings
before(:each) { @orig_version = FakeWeb::VERSION }
after(:each) { FakeWeb::VERSION = @orig_version }
- %w( 1.2.8 1.1.30 0.30.30 ).each do |version|
- it "raises an error when FakeWeb's version is #{version}" do
- FakeWeb::VERSION = version
- described_class.should_not_receive(:warn)
- expect { described_class.check_version! }.to raise_error(/You are using FakeWeb #{version}. VCR requires version .* or greater/)
- end
- end
-
- %w( 1.3.0 1.3.1 1.3.99 ).each do |version|
- it "does nothing when FakeWeb's version is #{version}" do
- FakeWeb::VERSION = version
- described_class.should_not_receive(:warn)
- expect { described_class.check_version! }.to_not raise_error
- end
- end
-
- %w( 1.4.0 1.10.0 2.0.0 ).each do |version|
- it "prints a warning when FakeWeb's version is #{version}" do
- FakeWeb::VERSION = version
- described_class.should_receive(:warn).with(/VCR is known to work with FakeWeb ~> .*\./)
- expect { described_class.check_version! }.to_not raise_error
- end
+ # Cannot be regular method def as that raises a "dynamic constant assignment" error
+ define_method :stub_version do |version|
+ FakeWeb::VERSION = version
end
end
end
@@ -7,31 +7,13 @@
%w[net/http patron httpclient em-http-request curb],
[:method, :uri, :host, :path, :body, :headers]
- describe '#check_version!' do
- before(:each) { WebMock.should respond_to(:version) }
-
- %w( 0.9.9 0.9.10 0.1.30 1.0.30 1.2.9 1.3.9 ).each do |version|
- it "raises an error when WebMock's version is #{version}" do
- WebMock.stub!(:version).and_return(version)
- described_class.should_not_receive(:warn)
- expect { described_class.check_version! }.to raise_error(/You are using WebMock #{version}. VCR requires version .* or greater/)
- end
- end
-
- %w( 1.4.0 1.4.10 1.4.99 ).each do |version|
- it "does nothing when WebMock's version is #{version}" do
- WebMock.stub!(:version).and_return(version)
- described_class.should_not_receive(:warn)
- expect { described_class.check_version! }.to_not raise_error
- end
- end
-
- %w( 1.5.0 1.10.0 2.0.0 ).each do |version|
- it "does nothing when WebMock's version is #{version}" do
- WebMock.stub!(:version).and_return(version)
- described_class.should_receive(:warn).with(/VCR is known to work with WebMock ~> .*\./)
- expect { described_class.check_version! }.to_not raise_error
- end
+ it_performs('version checking',
+ :valid => %w[ 1.4.0 1.4.99 1.5.0 1.5.99 ],
+ :too_low => %w[ 0.9.9 0.9.10 0.1.30 1.0.30 1.2.9 1.3.9 ],
+ :too_high => %w[ 1.6.0 1.10.0 2.0.0 ]
+ ) do
+ def stub_version(version)
+ WebMock.stub(:version).and_return(version)
end
end
end
View
@@ -36,5 +36,7 @@
config.filter_run :focus => true
config.run_all_when_everything_filtered = true
+
+ config.alias_it_should_behave_like_to :it_performs, 'it performs'
end
@@ -0,0 +1,29 @@
+shared_examples_for "version checking" do |options|
+ library = described_class.library_name
+
+ describe '#check_version!' do
+ options[:valid].each do |version|
+ it "does nothing when #{library}'s version is #{version}" do
+ stub_version(version)
+ described_class.should_not_receive(:warn)
+ expect { described_class.check_version! }.to_not raise_error
+ end
+ end
+
+ options[:too_low].each do |version|
+ it "raises an error when #{library}'s version is #{version}" do
+ stub_version(version)
+ described_class.should_not_receive(:warn)
+ expect { described_class.check_version! }.to raise_error(/You are using #{library} #{version}. VCR requires version/)
+ end
+ end
+
+ options[:too_high].each do |version|
+ it "does nothing when #{library}'s version is #{version}" do
+ stub_version(version)
+ described_class.should_receive(:warn).with(/VCR is known to work with #{library}/)
+ expect { described_class.check_version! }.to_not raise_error
+ end
+ end
+ end
+end

0 comments on commit 4b34280

Please sign in to comment.