File: version_checker_spec.rb

package info (click to toggle)
ruby-webmock 3.26.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,196 kB
  • sloc: ruby: 12,905; makefile: 6
file content (131 lines) | stat: -rw-r--r-- 6,089 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
require 'spec_helper'

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

    it 'prints a warning if the major version is too high' do
      checker = VersionChecker.new('foo', '2.0.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 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)
      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 0.7 and the version is 0.7.3' do
      checker = VersionChecker.new('foo', '0.7.3', '0.6.5', '0.7')
      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.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.})
      checker.check_version!
    end

    it "does not raise an error or print a warning when the max_minor_version is 1.0 and the version is 0.9" do
      checker = VersionChecker.new('foo', '0.9.0', '0.8.0', '1.0')
      expect(Kernel).not_to receive(:warn)#.with(%r{You are using foo 0.9.0. WebMock does not support this version. WebMock supports versions >= 0.8.0, < 1.0.})
      checker.check_version!
    end
  end
end