BigW Consortium Gitlab

version_info_spec.rb 2.13 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14
require 'spec_helper'

describe 'Gitlab::VersionInfo', no_db: true do
  before do
    @unknown = Gitlab::VersionInfo.new
    @v0_0_1 = Gitlab::VersionInfo.new(0, 0, 1)
    @v0_1_0 = Gitlab::VersionInfo.new(0, 1, 0)
    @v1_0_0 = Gitlab::VersionInfo.new(1, 0, 0)
    @v1_0_1 = Gitlab::VersionInfo.new(1, 0, 1)
    @v1_1_0 = Gitlab::VersionInfo.new(1, 1, 0)
    @v2_0_0 = Gitlab::VersionInfo.new(2, 0, 0)
  end

  context '>' do
15 16 17 18 19
    it { expect(@v2_0_0).to be > @v1_1_0 }
    it { expect(@v1_1_0).to be > @v1_0_1 }
    it { expect(@v1_0_1).to be > @v1_0_0 }
    it { expect(@v1_0_0).to be > @v0_1_0 }
    it { expect(@v0_1_0).to be > @v0_0_1 }
20 21 22
  end

  context '>=' do
23 24
    it { expect(@v2_0_0).to be >= Gitlab::VersionInfo.new(2, 0, 0) }
    it { expect(@v2_0_0).to be >= @v1_1_0 }
25 26 27
  end

  context '<' do
28 29 30 31 32
    it { expect(@v0_0_1).to be < @v0_1_0 }
    it { expect(@v0_1_0).to be < @v1_0_0 }
    it { expect(@v1_0_0).to be < @v1_0_1 }
    it { expect(@v1_0_1).to be < @v1_1_0 }
    it { expect(@v1_1_0).to be < @v2_0_0 }
33 34 35
  end

  context '<=' do
36 37
    it { expect(@v0_0_1).to be <= Gitlab::VersionInfo.new(0, 0, 1) }
    it { expect(@v0_0_1).to be <= @v0_1_0 }
38 39 40
  end

  context '==' do
41 42 43
    it { expect(@v0_0_1).to eq(Gitlab::VersionInfo.new(0, 0, 1)) }
    it { expect(@v0_1_0).to eq(Gitlab::VersionInfo.new(0, 1, 0)) }
    it { expect(@v1_0_0).to eq(Gitlab::VersionInfo.new(1, 0, 0)) }
44 45 46
  end

  context '!=' do
47
    it { expect(@v0_0_1).not_to eq(@v0_1_0) }
48 49 50
  end

  context 'unknown' do
51 52
    it { expect(@unknown).not_to be @v0_0_1 }
    it { expect(@unknown).not_to be Gitlab::VersionInfo.new }
53 54 55 56 57
    it { expect{@unknown > @v0_0_1}.to raise_error(ArgumentError) }
    it { expect{@unknown < @v0_0_1}.to raise_error(ArgumentError) }
  end

  context 'parse' do
58 59 60 61
    it { expect(Gitlab::VersionInfo.parse("1.0.0")).to eq(@v1_0_0) }
    it { expect(Gitlab::VersionInfo.parse("1.0.0.1")).to eq(@v1_0_0) }
    it { expect(Gitlab::VersionInfo.parse("git 1.0.0b1")).to eq(@v1_0_0) }
    it { expect(Gitlab::VersionInfo.parse("git 1.0b1")).not_to be_valid }
62 63 64
  end

  context 'to_s' do
65 66
    it { expect(@v1_0_0.to_s).to eq("1.0.0") }
    it { expect(@unknown.to_s).to eq("Unknown") }
67 68
  end
end