Решение на Четвърта задача - Unit тестване от Христина Тодорова

Обратно към всички решения

Към профила на Христина Тодорова

Резултати

  • 5 точки от тестове
  • 0 бонус точки
  • 5 точки общо
  • 15 успешни тест(а)
  • 4 неуспешни тест(а)

Код

RSpec.describe 'Version' do
describe '#initialize' do
it 'initializes correctly with valid input' do
expect(Version.new('1.1.5')).to eq '1.1.5'
expect(Version.new('1.13.3')).to eq '1.13.3'
expect(Version.new('1.105.0')).to eq '1.105'
expect(Version.new('1.2.3.4.600')).to eq '1.2.3.4.600'
expect(Version.new('20.0.0.0')).to eq '20'
expect(Version.new('2.0.0.1')).to eq '2.0.0.1'
end
it 'accepts empty string as argument' do
expect(Version.new('')).to eq '0'
end
it 'initializes without any argument' do
expect(Version.new).to eq '0'
end
context 'raises error for invalid input' do
it 'has too much points' do
expect { Version.new('.3') }.to raise_error(ArgumentError)
expect { Version.new('....3') }.to raise_error(ArgumentError)
expect { Version.new('0..3') }.to raise_error(ArgumentError)
expect { Version.new('0.12...3') }.to raise_error(ArgumentError)
expect { Version.new('1.3.5.') }.to raise_error(ArgumentError)
expect { Version.new('1...3...5') }.to raise_error(ArgumentError)
expect { Version.new('1...') }.to raise_error(ArgumentError)
end
it 'has other symbols included' do
expect { Version.new('2,1,3') }.to raise_error(ArgumentError)
expect { Version.new('2-3-1') }.to raise_error(ArgumentError)
expect { Version.new('2.3,1') }.to raise_error(ArgumentError)
expect { Version.new('2*3') }.to raise_error(ArgumentError)
end
it 'has negative number' do
expect { Version.new('-1') }.to raise_error(ArgumentError)
expect { Version.new('-12332.23') }.to raise_error(ArgumentError)
end
end
end
describe 'comparing versions' do
it 'compares correctly two versions' do
expect(Version.new('1.0.1') < Version.new('1.1.0')).to be true
expect(Version.new('1.2.3') < Version.new('1.3.1')).to be true
expect(Version.new('1.2.3') < Version.new('1.3')).to be true
expect(Version.new('1.2.3') < Version.new('1')).to be false
expect(Version.new('1') > Version.new('1.1')).to be false
expect(Version.new('1.22.3') <= Version.new('1.22.4')).to be true
expect(Version.new('1.22.0.0') >= Version.new('1.22')).to be true
expect(Version.new('1.1.0') == Version.new('1.1')).to be true
expect(Version.new('0.1') == Version.new('1')).to be false
expect(Version.new('1') == Version.new('1.0.0.0.0')).to be true
expect(Version.new('1') <=> Version.new('2')).to eq -1
end
end
describe '#to_s' do
it 'converts properly to string' do
expect(Version.new('1.1.0').to_s).to eq '1.1'
expect(Version.new('1.1.0.0.0.0').to_s).to eq '1.1'
expect(Version.new('25.12.0.2').to_s).to eq '25.12.0.2'
expect(Version.new('0.5').to_s).to eq '0.5'
end
end
describe '#components' do
it 'returns components' do
expect(Version.new('1.22.0').components).to eq [1, 22]
expect(Version.new('2.2.2').components).to eq [2, 2, 2]
end
it 'returns selected number of components' do
expect(Version.new('1.3.5').components(2)).to eq [1, 3]
expect(Version.new('1.1').components(4)).to eq [1, 1, 0, 0]
end
it 'doesnt change the initial object' do
object = Version.new('1.3.5')
array = object.components
array.reverse!
expect(object.components).to eq [1, 3, 5]
end
end
describe 'Range' do
describe '#include?' do
it 'checks range' do
object = Version::Range.new(Version.new('1'), Version.new('2'))
expect(object.include?(Version.new('1.5'))).to be true
expect(object.include?(Version.new('1.9'))).to be true
expect(object.include?(Version.new('2'))).to be false
expect(object.include?(Version.new('1'))).to be true
expect(object.include?(Version.new('1.6.8'))).to be true
end
end
describe '#to_a' do
it 'generates all versions' do
result = ['1.1', '1.1.1', '1.1.2', '1.1.3', '1.1.4', '1.1.5', '1.1.6']
expect(Version::Range.new('1.1.0', '1.1.7').to_a).to eq result
expect(Version::Range.new('1.3.5', '1.3.5').to_a).to eq []
result = ['2.9.7', '2.9.8', '2.9.9', '3']
expect(Version::Range.new('2.9.7', '3.0.1').to_a).to eq result
object = Version::Range.new(Version.new('1.2.9'), Version.new('1.3.1'))
expect(object.to_a).to eq ['1.2.9', '1.3.0']
end
end
end
end

Лог от изпълнението

.F...FF.........F..

Failures:

  1) spec Version checks for ArgumentError with the correct message
     Failure/Error: expect(@solution).to_not pass_tests
       expected this solution to not pass the tests:
       
         class Version
           VALID_VERSION_REGEXP = /\A\z|\A[0-9]+(\.[0-9]+)*\z/
         
           include Comparable
         
           def initialize(version = '')
             unless VALID_VERSION_REGEXP.match(version.to_s)
               raise ArgumentError, "Invalid version string"
             end
           
             @components = version.to_s
               .split('.')
               .map(&:to_i)
               .reverse
               .drop_while(&:zero?)
               .reverse
           end
         
           def <=>(other)
             @components <=> Version.new(other).internal_components
           end
         
           def internal_components(positions = 0)
             padding_size = positions - @components.size
         
             if padding_size > 0
               @components + [0] * padding_size
             elsif positions != 0
               @components.take(positions)
             else
               @components.dup
             end
           end
         
           def components(positions = 0)
             padding_size = positions - @components.size
         
             if padding_size > 0
               @components + [0] * padding_size
             elsif positions != 0
               @components.take(positions)
             else
               @components.dup
             end
           end
         
           def to_s
             @components.join('.')
           end
         
           class Range
             include Enumerable
         
             def initialize(start_version, end_version)
               @start_version = Version.new(start_version)
               @end_version   = Version.new(end_version)
             end
         
             def include?(version)
               (@start_version <=> version) < 1 && (@end_version <=> version) == 1
             end
         
             def each
               current_version = @start_version
         
               while (current_version <=> @end_version) == -1
                 yield current_version
         
                 current_version = increment_version(current_version)
               end
             end
         
             private
         
             def increment_version(version)
               components = version.internal_components(3)
         
               components[2] += 1
         
               components.to_enum.with_index.reverse_each do |_, index|
                 component = components[index]
         
                 if component >= 10 && components[index - 1]
                   components[index]      = 0
                   components[index - 1] += 1
                 end
               end
         
               Version.new(components.join('.'))
             end
           end
         end
     # /tmp/d20161119-19072-1uddwhj/spec.rb:257:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'

  2) spec Version checks for comparison operators positively
     Failure/Error: expect(@solution).to_not pass_tests
       expected this solution to not pass the tests:
       
         class Version
         def >(other)
           false
         end
           VALID_VERSION_REGEXP = /\A\z|\A[0-9]+(\.[0-9]+)*\z/
         
           include Comparable
         
           def initialize(version = '')
             unless VALID_VERSION_REGEXP.match(version.to_s)
               raise ArgumentError, "Invalid version string '#{version}'"
             end
         
             @components = version.to_s
               .split('.')
               .map(&:to_i)
               .reverse
               .drop_while(&:zero?)
               .reverse
           end
         
           def <=>(other)
             @components <=> Version.new(other).internal_components
           end
         
           def internal_components(positions = 0)
             padding_size = positions - @components.size
         
             if padding_size > 0
               @components + [0] * padding_size
             elsif positions != 0
               @components.take(positions)
             else
               @components.dup
             end
           end
         
           def components(positions = 0)
             padding_size = positions - @components.size
         
             if padding_size > 0
               @components + [0] * padding_size
             elsif positions != 0
               @components.take(positions)
             else
               @components.dup
             end
           end
         
           def to_s
             @components.join('.')
           end
         
           class Range
             include Enumerable
         
             def initialize(start_version, end_version)
               @start_version = Version.new(start_version)
               @end_version   = Version.new(end_version)
             end
         
             def include?(version)
               (@start_version <=> version) < 1 && (@end_version <=> version) == 1
             end
         
             def each
               current_version = @start_version
         
               while (current_version <=> @end_version) == -1
                 yield current_version
         
                 current_version = increment_version(current_version)
               end
             end
         
             private
         
             def increment_version(version)
               components = version.internal_components(3)
         
               components[2] += 1
         
               components.to_enum.with_index.reverse_each do |_, index|
                 component = components[index]
         
                 if component >= 10 && components[index - 1]
                   components[index]      = 0
                   components[index - 1] += 1
                 end
               end
         
               Version.new(components.join('.'))
             end
           end
         end
     # /tmp/d20161119-19072-1uddwhj/spec.rb:323:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'

  3) spec Version checks for comparison operators negatively
     Failure/Error: expect(@solution).to_not pass_tests
       expected this solution to not pass the tests:
       
         class Version
         def <=(other)
           true
         end
           VALID_VERSION_REGEXP = /\A\z|\A[0-9]+(\.[0-9]+)*\z/
         
           include Comparable
         
           def initialize(version = '')
             unless VALID_VERSION_REGEXP.match(version.to_s)
               raise ArgumentError, "Invalid version string '#{version}'"
             end
         
             @components = version.to_s
               .split('.')
               .map(&:to_i)
               .reverse
               .drop_while(&:zero?)
               .reverse
           end
         
           def <=>(other)
             @components <=> Version.new(other).internal_components
           end
         
           def internal_components(positions = 0)
             padding_size = positions - @components.size
         
             if padding_size > 0
               @components + [0] * padding_size
             elsif positions != 0
               @components.take(positions)
             else
               @components.dup
             end
           end
         
           def components(positions = 0)
             padding_size = positions - @components.size
         
             if padding_size > 0
               @components + [0] * padding_size
             elsif positions != 0
               @components.take(positions)
             else
               @components.dup
             end
           end
         
           def to_s
             @components.join('.')
           end
         
           class Range
             include Enumerable
         
             def initialize(start_version, end_version)
               @start_version = Version.new(start_version)
               @end_version   = Version.new(end_version)
             end
         
             def include?(version)
               (@start_version <=> version) < 1 && (@end_version <=> version) == 1
             end
         
             def each
               current_version = @start_version
         
               while (current_version <=> @end_version) == -1
                 yield current_version
         
                 current_version = increment_version(current_version)
               end
             end
         
             private
         
             def increment_version(version)
               components = version.internal_components(3)
         
               components[2] += 1
         
               components.to_enum.with_index.reverse_each do |_, index|
                 component = components[index]
         
                 if component >= 10 && components[index - 1]
                   components[index]      = 0
                   components[index - 1] += 1
                 end
               end
         
               Version.new(components.join('.'))
             end
           end
         end
     # /tmp/d20161119-19072-1uddwhj/spec.rb:377:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'

  4) spec Version::Range tests include? with versions lower than the start one
     Failure/Error: expect(@solution).to_not pass_tests
       expected this solution to not pass the tests:
       
         class Version
           VALID_VERSION_REGEXP = /\A\z|\A[0-9]+(\.[0-9]+)*\z/
         
           include Comparable
         
           def initialize(version = '')
             unless VALID_VERSION_REGEXP.match(version.to_s)
               raise ArgumentError, "Invalid version string '#{version}'"
             end
         
             @components = version.to_s
               .split('.')
               .map(&:to_i)
               .reverse
               .drop_while(&:zero?)
               .reverse
           end
         
           def <=>(other)
             @components <=> Version.new(other).internal_components
           end
         
           def internal_components(positions = 0)
             padding_size = positions - @components.size
         
             if padding_size > 0
               @components + [0] * padding_size
             elsif positions != 0
               @components.take(positions)
             else
               @components.dup
             end
           end
         
           def components(positions = 0)
             padding_size = positions - @components.size
         
             if padding_size > 0
               @components + [0] * padding_size
             elsif positions != 0
               @components.take(positions)
             else
               @components.dup
             end
           end
         
           def to_s
             @components.join('.')
           end
         
           class Range
             include Enumerable
         
             def initialize(start_version, end_version)
               @start_version = Version.new(start_version)
               @end_version   = Version.new(end_version)
             end
         
             def include?(version)
               @end_version > version
             end
         
             def each
               current_version = @start_version
         
               while (current_version <=> @end_version) == -1
                 yield current_version
         
                 current_version = increment_version(current_version)
               end
             end
         
             private
         
             def increment_version(version)
               components = version.internal_components(3)
         
               components[2] += 1
         
               components.to_enum.with_index.reverse_each do |_, index|
                 component = components[index]
         
                 if component >= 10 && components[index - 1]
                   components[index]      = 0
                   components[index - 1] += 1
                 end
               end
         
               Version.new(components.join('.'))
             end
           end
         end
     # /tmp/d20161119-19072-1uddwhj/spec.rb:522:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'

Finished in 15.52 seconds
19 examples, 4 failures

Failed examples:

rspec /tmp/d20161119-19072-1uddwhj/spec.rb:241 # spec Version checks for ArgumentError with the correct message
rspec /tmp/d20161119-19072-1uddwhj/spec.rb:317 # spec Version checks for comparison operators positively
rspec /tmp/d20161119-19072-1uddwhj/spec.rb:353 # spec Version checks for comparison operators negatively
rspec /tmp/d20161119-19072-1uddwhj/spec.rb:515 # spec Version::Range tests include? with versions lower than the start one

История (3 версии и 0 коментара)

Христина обнови решението на 18.11.2016 07:59 (преди над 1 година)

+RSpec.describe 'Version' do
+ describe '#initialize' do
+ it 'initializes correctly with valid input' do
+ expect(Version.new('1.1.5')).to eq '1.1.5'
+ expect(Version.new('1.13.3')).to eq '1.13.3'
+ expect(Version.new('1.105.0')).to eq '1.105'
+ expect(Version.new('1.2.3.4.600')).to eq '1.2.3.4.600'
+ expect(Version.new('20.0.0.0')).to eq '20'
+ expect(Version.new('2.0.0.1')).to eq '2.0.0.1'
+ end
+
+ it 'accepts empty string as argument' do
+ expect(Version.new('')).to eq '0'
+ end
+
+ it 'initializes without any argument' do
+ expect(Version.new).to eq '0'
+ end
+
+ context 'raises error for invalid input' do
+ it 'has too much points' do
+ expect { Version.new('.3') }.to raise_error(ArgumentError)
+ expect { Version.new('....3') }.to raise_error(ArgumentError)
+ expect { Version.new('0..3') }.to raise_error(ArgumentError)
+ expect { Version.new('0.12...3') }.to raise_error(ArgumentError)
+ expect { Version.new('1.3.5.') }.to raise_error(ArgumentError)
+ expect { Version.new('1...3...5') }.to raise_error(ArgumentError)
+ expect { Version.new('1...') }.to raise_error(ArgumentError)
+ end
+
+ it 'has other symbols included' do
+ expect { Version.new('2,1,3') }.to raise_error(ArgumentError)
+ expect { Version.new('2-3-1') }.to raise_error(ArgumentError)
+ expect { Version.new('2.3,1') }.to raise_error(ArgumentError)
+ expect { Version.new('2*3') }.to raise_error(ArgumentError)
+ end
+
+ it 'has negative number' do
+ expect { Version.new('-1') }.to raise_error(ArgumentError)
+ expect { Version.new('-12332.23') }.to raise_error(ArgumentError)
+ end
+ end
+ end
+
+ describe 'comparing versions' do
+ it 'compares correctly two versions' do
+ expect(Version.new('1.0.1') < Version.new('1.1.0')).to be true
+ expect(Version.new('1.2.3') < Version.new('1.3.1')).to be true
+ expect(Version.new('1.2.3') < Version.new('1.3')).to be true
+ expect(Version.new('1.2.3') < Version.new('1')).to be false
+ expect(Version.new('1') > Version.new('1.1')).to be false
+ expect(Version.new('1.22.3') <= Version.new('1.22.4')).to be true
+ expect(Version.new('1.22.0.0') >= Version.new('1.22')).to be true
+ expect(Version.new('1.1.0') == Version.new('1.1')).to be true
+ expect(Version.new('0.1') == Version.new('1')).to be false
+ expect(Version.new('1') == Version.new('1.0.0.0.0')).to be true
+ expect(Version.new('1') <=> Version.new('2')).to eq -1
+ end
+ end
+
+ describe '#to_s' do
+ it 'converts properly to string' do
+ expect(Version.new('1.1.0').to_s).to eq '1.1'
+ end
+ end
+
+ describe '#components' do
+ it 'returns components' do
+ expect(Version.new('1.22.0').components).to eq [1, 22]
+ end
+
+ it 'returns selected number of components' do
+ expect(Version.new('1.3.5').components(2)).to eq [1, 3]
+ expect(Version.new('1.1').components(4)).to eq [1, 1, 0, 0]
+ end
+
+ it 'doesnt change the initial object' do
+ object = Version.new('1.3.5')
+ array = object.components
+ array.reverse!
+ expect(object.components).to eq [1, 3, 5]
+ end
+ end
+end

Христина обнови решението на 18.11.2016 17:42 (преди над 1 година)

RSpec.describe 'Version' do
describe '#initialize' do
it 'initializes correctly with valid input' do
expect(Version.new('1.1.5')).to eq '1.1.5'
expect(Version.new('1.13.3')).to eq '1.13.3'
expect(Version.new('1.105.0')).to eq '1.105'
expect(Version.new('1.2.3.4.600')).to eq '1.2.3.4.600'
expect(Version.new('20.0.0.0')).to eq '20'
expect(Version.new('2.0.0.1')).to eq '2.0.0.1'
end
it 'accepts empty string as argument' do
expect(Version.new('')).to eq '0'
end
it 'initializes without any argument' do
expect(Version.new).to eq '0'
end
context 'raises error for invalid input' do
it 'has too much points' do
expect { Version.new('.3') }.to raise_error(ArgumentError)
expect { Version.new('....3') }.to raise_error(ArgumentError)
expect { Version.new('0..3') }.to raise_error(ArgumentError)
expect { Version.new('0.12...3') }.to raise_error(ArgumentError)
expect { Version.new('1.3.5.') }.to raise_error(ArgumentError)
expect { Version.new('1...3...5') }.to raise_error(ArgumentError)
expect { Version.new('1...') }.to raise_error(ArgumentError)
end
it 'has other symbols included' do
expect { Version.new('2,1,3') }.to raise_error(ArgumentError)
expect { Version.new('2-3-1') }.to raise_error(ArgumentError)
expect { Version.new('2.3,1') }.to raise_error(ArgumentError)
expect { Version.new('2*3') }.to raise_error(ArgumentError)
end
it 'has negative number' do
expect { Version.new('-1') }.to raise_error(ArgumentError)
expect { Version.new('-12332.23') }.to raise_error(ArgumentError)
end
end
end
describe 'comparing versions' do
it 'compares correctly two versions' do
expect(Version.new('1.0.1') < Version.new('1.1.0')).to be true
expect(Version.new('1.2.3') < Version.new('1.3.1')).to be true
expect(Version.new('1.2.3') < Version.new('1.3')).to be true
expect(Version.new('1.2.3') < Version.new('1')).to be false
expect(Version.new('1') > Version.new('1.1')).to be false
expect(Version.new('1.22.3') <= Version.new('1.22.4')).to be true
expect(Version.new('1.22.0.0') >= Version.new('1.22')).to be true
expect(Version.new('1.1.0') == Version.new('1.1')).to be true
expect(Version.new('0.1') == Version.new('1')).to be false
expect(Version.new('1') == Version.new('1.0.0.0.0')).to be true
expect(Version.new('1') <=> Version.new('2')).to eq -1
end
end
describe '#to_s' do
it 'converts properly to string' do
expect(Version.new('1.1.0').to_s).to eq '1.1'
end
end
describe '#components' do
it 'returns components' do
expect(Version.new('1.22.0').components).to eq [1, 22]
end
it 'returns selected number of components' do
expect(Version.new('1.3.5').components(2)).to eq [1, 3]
expect(Version.new('1.1').components(4)).to eq [1, 1, 0, 0]
end
it 'doesnt change the initial object' do
object = Version.new('1.3.5')
array = object.components
array.reverse!
expect(object.components).to eq [1, 3, 5]
end
end
+
+ describe 'Range' do
+ describe '#include?' do
+ it 'checks range' do
+ object = Version::Range.new(Version.new('1'), Version.new('2'))
+ expect(object.include?(Version.new('1.5'))).to be true
+ end
+ end
+
+ describe '#to_a' do
+ it 'generates all versions' do
+ result = ['1.1', '1.1.1', '1.1.2', '1.1.3', '1.1.4', '1.1.5', '1.1.6']
+ expect(Version::Range.new('1.1.0', '1.1.7').to_a).to eq result
+
+ expect(Version::Range.new('1.3.5', '1.3.5').to_a).to eq []
+ end
+ end
+ end
end

Христина обнови решението на 18.11.2016 18:41 (преди над 1 година)

RSpec.describe 'Version' do
describe '#initialize' do
it 'initializes correctly with valid input' do
expect(Version.new('1.1.5')).to eq '1.1.5'
expect(Version.new('1.13.3')).to eq '1.13.3'
expect(Version.new('1.105.0')).to eq '1.105'
expect(Version.new('1.2.3.4.600')).to eq '1.2.3.4.600'
expect(Version.new('20.0.0.0')).to eq '20'
expect(Version.new('2.0.0.1')).to eq '2.0.0.1'
end
it 'accepts empty string as argument' do
expect(Version.new('')).to eq '0'
end
it 'initializes without any argument' do
expect(Version.new).to eq '0'
end
context 'raises error for invalid input' do
it 'has too much points' do
expect { Version.new('.3') }.to raise_error(ArgumentError)
expect { Version.new('....3') }.to raise_error(ArgumentError)
expect { Version.new('0..3') }.to raise_error(ArgumentError)
expect { Version.new('0.12...3') }.to raise_error(ArgumentError)
expect { Version.new('1.3.5.') }.to raise_error(ArgumentError)
expect { Version.new('1...3...5') }.to raise_error(ArgumentError)
expect { Version.new('1...') }.to raise_error(ArgumentError)
end
it 'has other symbols included' do
expect { Version.new('2,1,3') }.to raise_error(ArgumentError)
expect { Version.new('2-3-1') }.to raise_error(ArgumentError)
expect { Version.new('2.3,1') }.to raise_error(ArgumentError)
expect { Version.new('2*3') }.to raise_error(ArgumentError)
end
it 'has negative number' do
expect { Version.new('-1') }.to raise_error(ArgumentError)
expect { Version.new('-12332.23') }.to raise_error(ArgumentError)
end
end
end
describe 'comparing versions' do
it 'compares correctly two versions' do
expect(Version.new('1.0.1') < Version.new('1.1.0')).to be true
expect(Version.new('1.2.3') < Version.new('1.3.1')).to be true
expect(Version.new('1.2.3') < Version.new('1.3')).to be true
expect(Version.new('1.2.3') < Version.new('1')).to be false
expect(Version.new('1') > Version.new('1.1')).to be false
expect(Version.new('1.22.3') <= Version.new('1.22.4')).to be true
expect(Version.new('1.22.0.0') >= Version.new('1.22')).to be true
expect(Version.new('1.1.0') == Version.new('1.1')).to be true
expect(Version.new('0.1') == Version.new('1')).to be false
expect(Version.new('1') == Version.new('1.0.0.0.0')).to be true
expect(Version.new('1') <=> Version.new('2')).to eq -1
end
end
describe '#to_s' do
it 'converts properly to string' do
expect(Version.new('1.1.0').to_s).to eq '1.1'
+ expect(Version.new('1.1.0.0.0.0').to_s).to eq '1.1'
+ expect(Version.new('25.12.0.2').to_s).to eq '25.12.0.2'
+ expect(Version.new('0.5').to_s).to eq '0.5'
end
end
describe '#components' do
it 'returns components' do
expect(Version.new('1.22.0').components).to eq [1, 22]
+ expect(Version.new('2.2.2').components).to eq [2, 2, 2]
end
it 'returns selected number of components' do
expect(Version.new('1.3.5').components(2)).to eq [1, 3]
expect(Version.new('1.1').components(4)).to eq [1, 1, 0, 0]
end
it 'doesnt change the initial object' do
object = Version.new('1.3.5')
array = object.components
array.reverse!
expect(object.components).to eq [1, 3, 5]
end
end
describe 'Range' do
describe '#include?' do
it 'checks range' do
object = Version::Range.new(Version.new('1'), Version.new('2'))
expect(object.include?(Version.new('1.5'))).to be true
+ expect(object.include?(Version.new('1.9'))).to be true
+ expect(object.include?(Version.new('2'))).to be false
+ expect(object.include?(Version.new('1'))).to be true
+ expect(object.include?(Version.new('1.6.8'))).to be true
end
end
describe '#to_a' do
it 'generates all versions' do
result = ['1.1', '1.1.1', '1.1.2', '1.1.3', '1.1.4', '1.1.5', '1.1.6']
expect(Version::Range.new('1.1.0', '1.1.7').to_a).to eq result
expect(Version::Range.new('1.3.5', '1.3.5').to_a).to eq []
+
+ result = ['2.9.7', '2.9.8', '2.9.9', '3']
+ expect(Version::Range.new('2.9.7', '3.0.1').to_a).to eq result
+
+ object = Version::Range.new(Version.new('1.2.9'), Version.new('1.3.1'))
+ expect(object.to_a).to eq ['1.2.9', '1.3.0']
end
end
end
end