Стоян обнови решението на 18.11.2016 21:32 (преди над 8 години)
+RSpec.describe 'Version' do
+ describe Version do
+ it 'Is bigger then' do
+ expect( Version.new( '1.2.3' ) > Version.new( '1.1.1' ) ).to be true
+ expect( Version.new( '1.2' ) > Version.new( '1.1.3' ) ).to be true
+ end
+ it 'Is smaller then' do
+ expect( Version.new( '1.2.3' ) < Version.new( '1.3.1' ) ).to be true
+ expect( Version.new( '1.3' ) < Version.new( '1.5.1' ) ).to be true
+ end
+ it 'Is equal' do
+ expect(Version.new('1.1.3') == Version.new('1.1.4')).to be false
+ expect(Version.new('1.3.0') == Version.new('1.3')).to be true
+ expect(Version.new('0.3') == Version.new('3')).to be false
+ expect(Version.new('1.0.3') == Version.new('1.3')).to be false
+ end
+ it 'Is bigger or equal' do
+ expect(Version.new('1.3') >= Version.new('1.3.0')).to be true
+ expect(Version.new('0.4') >= Version.new('4')).to be false
+ expect(Version.new('1.3.2') >= Version.new('1.1.1')).to be true
+ expect(Version.new('1.3.2') >= Version.new('1.3.1')).to be true
+ expect(Version.new('1.1.0') >= Version.new('1.1')).to be true
+ expect(Version.new('1.0.1') >= Version.new('1.1')).to be false
+ expect(Version.new('1.5') >= Version.new('1.3')).to be true
+ end
+ it 'Is smaller or equal' do
+ expect(Version.new('0.8') <= Version.new('3')).to be true
+ expect(Version.new('0.8') <= Version.new('0.8.0')).to be true
+ expect(Version.new('1.8.5') <= Version.new('1.9.9')).to be true
+ expect(Version.new('1.1.0') <= Version.new('1.1')).to be true
+ expect(Version.new('1') <= Version.new('0.1')).to be false
+ end
+ it '<=>' do
+ expect(Version.new('1.2.3') <=> Version.new('1.2.5')).to eq 1
+ expect(Version.new('1.1.2') <=> Version.new('1.2.3')).to eq - 1
+ expect(Version.new('1.3.5') <=> Version.new('1.1.2')).to eq 1
+ expect(Version.new('1.1.0') <=> Version.new('1.1')).to eq 0
+ expect(Version.new('0.1') <=> Version.new('1')).to eq - 1
+ end
+
+ describe '#to_s' do
+ it 'return as string' do
+ expect(Version.new('1.2.3').to_s).to eq '1.2.3'
+ expect(Version.new('1.1.0').to_s).to eq '1.1'
+ expect(Version.new('1.0.2').to_s).to eq '1.0.2'
+ end
+ end
+ describe '#components' do
+ it 'return as array' do
+ expect(Version.new('1.2.3').components).to eq [1, 2, 3]
+ expect(Version.new('1.3.0').components).to eq [1, 3]
+ expect(Version.new('1.0.5').components).to eq [1, 0, 5]
+ end
+ end
+ end
+end