Skip to content

Commit

Permalink
Version checker fails under some conditions
Browse files Browse the repository at this point in the history
Currently it prints a warning for Curb 0.9.7
  • Loading branch information
marcrohloff committed Nov 8, 2022
1 parent 833291d commit f6ed904
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 5 deletions.
11 changes: 6 additions & 5 deletions lib/webmock/util/version_checker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,13 @@ def warn_in_red(text)
def compare_version
case
when @major < @min_major then :too_low
when @major == @min_major && @minor < @min_minor then :too_low
when @major == @min_major && @minor == @min_minor && @patch < @min_patch then :too_low

when @max_major && @major > @max_major then :too_high
when @major > @min_major then :ok
when @minor < @min_minor then :too_low
when @max_minor && @minor > @max_minor then :too_high
when @minor > @min_minor then :ok
when @patch < @min_patch then :too_low
when @max_major && @major == @max_major && @max_minor && @minor > @max_minor then :too_high

else :ok
end
end

Expand Down
60 changes: 60 additions & 0 deletions spec/unit/util/version_checker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,36 @@ module WebMock
checker.check_version!
end

it 'prints a warning if the major version is too low - 2' do
checker = VersionChecker.new('foo', '0.7.3', '1.0.0', '2.1')
expect(Kernel).to receive(:warn).with("\e[31mYou are using foo 0.7.3. WebMock supports version >= 1.0.0, < 2.2.\e[0m")
checker.check_version!
end

it 'prints a warning if the minor version is too low' do
checker = VersionChecker.new('foo', '1.0.99', '1.1.3', '1.2')
expect(Kernel).to receive(:warn).with("\e[31mYou are using foo 1.0.99. WebMock supports version >= 1.1.3, < 1.3.\e[0m")
checker.check_version!
end

it 'prints a warning if the minor version is too low - 2' do
checker = VersionChecker.new('foo', '0.7.8', '0.9.7', '1.0.1')
expect(Kernel).to receive(:warn).with("\e[31mYou are using foo 0.7.8. WebMock supports version >= 0.9.7, < 1.1.\e[0m")
checker.check_version!
end

it 'prints a warning if the patch version is too low' do
checker = VersionChecker.new('foo', '1.0.8', '1.0.10', '1.2')
expect(Kernel).to receive(:warn).with("\e[31mYou are using foo 1.0.8. WebMock supports version >= 1.0.10, < 1.3.\e[0m")
checker.check_version!
end

it 'prints a warning if the patch version is too low - 2' do
checker = VersionChecker.new('foo', '0.9.1', '0.9.7', '1.0.1')
expect(Kernel).to receive(:warn).with("\e[31mYou are using foo 0.9.1. WebMock supports version >= 0.9.7, < 1.1.\e[0m")
checker.check_version!
end

it 'prints a warning if the patch version is too low and max version is not specified' do
checker = VersionChecker.new('foo', '1.0.8', '1.0.10')
expect(Kernel).to receive(:warn).with("\e[31mYou are using foo 1.0.8. WebMock supports version >= 1.0.10.\e[0m")
Expand All @@ -32,12 +50,24 @@ module WebMock
checker.check_version!
end

it 'prints a warning if the major version is too high - 2' do
checker = VersionChecker.new('foo', '2.0.0', '0.9.7', '1.1')
expect(Kernel).to receive(:warn).with(/may not work with this version/)
checker.check_version!
end

it 'prints a warning if the minor version is too high' do
checker = VersionChecker.new('foo', '1.2.0', '1.0.0', '1.1')
expect(Kernel).to receive(:warn).with(/may not work with this version/)
checker.check_version!
end

it 'prints a warning if the minor version is too high - 2' do
checker = VersionChecker.new('foo', '1.2.0', '0.9.7', '1.1')
expect(Kernel).to receive(:warn).with(/may not work with this version/)
checker.check_version!
end

it 'does not raise an error or print a warning when the major version is between the min and max' do
checker = VersionChecker.new('foo', '2.0.0', '1.0.0', '3.0')
expect(Kernel).not_to receive(:warn)
Expand All @@ -50,12 +80,42 @@ module WebMock
checker.check_version!
end

it 'does not raise an error or print a warning when the min_patch is 0.6.5, the max_minor is 1.0.1 and the version is 0.7.3' do
checker = VersionChecker.new('foo', '0.7.3', '0.6.5', '1.0.1')
expect(Kernel).not_to receive(:warn)
checker.check_version!
end

it 'does not raise an error or print a warning when the min_patch is 0.6.5, the max_minor is 1.0.1 and the version is 0.7.3' do
checker = VersionChecker.new('foo', '0.7.3', '0.6.5', '1.0.1')
expect(Kernel).not_to receive(:warn)
checker.check_version!
end

it 'does not raise an error or print a warning when the min_patch is 0.6.5, the max_minor is 1.0.1 and the version is 0.6.5' do
checker = VersionChecker.new('foo', '0.7.3', '0.6.5', '1.0.1')
expect(Kernel).not_to receive(:warn)
checker.check_version!
end

it 'does not raise an error or print a warning when the min_patch is 0.6.5, the max_minor is 1.0.1 and the version is 1.0.1' do
checker = VersionChecker.new('foo', '0.7.3', '0.6.5', '1.0.1')
expect(Kernel).not_to receive(:warn)
checker.check_version!
end

it 'does not raise an error or print a warning when the min_patch is 0.6.5, the max_minor is not specified and the version is 0.8.3' do
checker = VersionChecker.new('foo', '0.8.3', '0.6.5')
expect(Kernel).not_to receive(:warn)
checker.check_version!
end

it 'does not raise an error or print a warning when the min_patch is 0.6.5, the max_minor is not specified and the version is 0.6.5' do
checker = VersionChecker.new('foo', '0.8.3', '0.6.5')
expect(Kernel).not_to receive(:warn)
checker.check_version!
end

it "prints warning if version is unsupported" do
checker = VersionChecker.new('foo', '2.0.0', '1.0.0', '3.0', ['2.0.0'])
expect(Kernel).to receive(:warn).with(%r{You are using foo 2.0.0. WebMock does not support this version. WebMock supports versions >= 1.0.0, < 3.1, except versions 2.0.0.})
Expand Down

0 comments on commit f6ed904

Please sign in to comment.