File: comparable_version_spec.rb

package info (click to toggle)
ruby-rspec 3.12.0c0e1m1s0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 6,752 kB
  • sloc: ruby: 69,818; sh: 1,861; makefile: 99
file content (39 lines) | stat: -rw-r--r-- 1,427 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
require 'rspec/support/comparable_version'

module RSpec::Support
  RSpec.describe ComparableVersion do
    describe '#<=>' do
      [
        ['1.2.3',        '1.2.3',        0],
        ['1.2.4',        '1.2.3',        1],
        ['1.3.0',        '1.2.3',        1],
        ['1.2.3',        '1.2.4',       -1],
        ['1.2.3',        '1.3.0',       -1],
        ['1.2.10',       '1.2.3',        1],
        ['1.2.3',        '1.2.10',      -1],
        ['1.2.3.0',      '1.2.3',        0],
        ['1.2.3',        '1.2.3.0',      0],
        ['1.2.3.1',      '1.2.3',        1],
        ['1.2.3.1',      '1.2.3.0',      1],
        ['1.2.3',        '1.2.3.1',     -1],
        ['1.2.3.0',      '1.2.3.1',     -1],
        ['1.2.3.rc1',    '1.2.3',       -1],
        ['1.2.3.rc1',    '1.2.3.rc2',   -1],
        ['1.2.3.rc2',    '1.2.3.rc10',  -1],
        ['1.2.3.alpha2', '1.2.3.beta1', -1],
        ['1.2.3',        '1.2.3.rc1',    1],
        ['1.2.3.rc2',    '1.2.3.rc1',    1],
        ['1.2.3.rc10',   '1.2.3.rc2',    1],
        ['1.2.3.beta1',  '1.2.3.alpha2', 1]
      ].each do |subject_string, other_string, expected|
        context "with #{subject_string.inspect} and #{other_string.inspect}" do
          subject do
            ComparableVersion.new(subject_string) <=> ComparableVersion.new(other_string)
          end

          it { is_expected.to eq(expected) }
        end
      end
    end
  end
end