Skip to content

Commit

Permalink
Merge pull request #1006 from marcrohloff/fix-version-checking
Browse files Browse the repository at this point in the history
Version checker fails under some conditions
  • Loading branch information
bblimke authored Aug 19, 2023
2 parents 0771fbc + 0e9519c commit 87786a2
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 6 deletions.
11 changes: 5 additions & 6 deletions lib/webmock/util/version_checker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,12 @@ 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 @max_major && @major < @max_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 87786a2

Please sign in to comment.