Решение на Четвърта задача - Unit тестване от Светослав Годжев

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

Към профила на Светослав Годжев

Резултати

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

Код

RSpec.describe 'Version' do
describe 'Argument exception' do
it 'throws ArgumentError on wrong input' do
expect { Version.new('.3') }.to raise_error(ArgumentError)
expect { Version.new('1.3.4..') }.to raise_error(ArgumentError)
expect { Version.new('0..3') }.to raise_error(ArgumentError)
expect { Version.new('throwexception') }.to raise_error(ArgumentError)
end
end
describe 'Version comparison' do
it 'compares versions with same number of components' do
expect(Version.new('')).to eq Version.new
expect(Version.new('1.3.3')).to eq Version.new('1.3.3')
expect(Version.new('1.2.3')).to be < Version.new('1.3.3')
expect(Version.new('2.3.3')).to be > Version.new('1.4.3')
end
it 'compares versions with different number of components' do
expect(Version.new('1.3.3.0')).to eq Version.new('1.3.3')
expect(Version.new('0.5')).to_not eq Version.new('5')
expect(Version.new('1.3.3')).to be < Version.new('1.3.3.1')
expect(Version.new('1.3.3.0.1')).to be < Version.new('1.3.3.1')
expect(Version.new('1.3')).to be > Version.new('1.2.3')
expect(Version.new('3')).to be > Version.new('0.3')
end
end
describe 'Version#to_s' do
it 'transforms version to string' do
expect(Version.new('').to_s).to eq('')
expect(Version.new.to_s).to eq('')
expect(Version.new('30.5').to_s).to eq('30.5')
expect(Version.new('0.3.5').to_s).to eq('0.3.5')
expect(Version.new('0.0.5').to_s).to eq('0.0.5')
expect(Version.new('1.0.5').to_s).to eq('1.0.5')
end
it 'transforms version to string and removes ending zeros' do
expect(Version.new('1.3.0').to_s).to eq('1.3')
expect(Version.new('1.3.5.0.0').to_s).to eq('1.3.5')
end
end
describe 'Version#components' do
context 'Version#components without an argument' do
it 'returns an array with the version components' do
expect(Version.new('2.4.6').components).to eq([2, 4, 6])
expect(Version.new('0.4.6').components).to eq([0, 4, 6])
end
it 'returns an array with the version components without ending zeros' do
expect(Version.new('2.4.0.0').components).to eq([2, 4])
expect(Version.new('2.4.0.6.0').components).to eq([2, 4, 0, 6])
end
end
context 'Version#components with an argument' do
it 'returns an array with exact number of components' do
expect(Version.new('3.5.8').components(3)).to eq([3, 5, 8])
end
it 'returns an array with more components' do
expect(Version.new('3.5.8').components(5)).to eq([3, 5, 8, 0, 0])
end
it 'returns an array with less components' do
expect(Version.new('3.5.8').components(2)).to eq([3, 5])
end
end
end
describe 'Version::Range' do
describe 'Range#include?' do
it 'returns true if version is within range' do
range = Version::Range.new('1.0.0', '3.0.0')
version = Version.new('2.0.0')
expect(range.include?(version)).to eq true
range = Version::Range.new('1.3.5', '3.5.8')
version = Version.new('1.3.5')
expect(range.include?(version)).to eq true
range = Version::Range.new('1.0.0', '2')
version = Version.new('1.5')
expect(range.include?(version)).to be true
range = Version::Range.new('1.10.5', '2.3.6.1')
version = Version.new('2.3.5')
expect(range.include?(version)).to eq true
end
it 'returns false if version is not withing range' do
range = Version::Range.new('1.0.0', '2.0.0')
version = Version.new('3.0.0')
expect(range.include?(version)).to eq false
range = Version::Range.new('1.3.5', '1.3.5')
version = Version.new('1.3.5')
expect(range.include?(version)).to eq false
range = Version::Range.new('1.0.0', '2.0.0')
version = Version.new('2.0.0')
expect(range.include?(version)).to eq false
end
end
describe 'Range#to_a' do
context 'begining version is equal to ending version' do
it 'returns an empty array' do
version_1 = Version.new('3.5.8')
version_2 = Version.new('3.5.8')
range = Version::Range.new(version_1, version_2)
expect(range.to_a).to eq([])
version_1 = Version.new('3.0')
version_2 = Version.new('3.0.0')
range = Version::Range.new(version_1, version_2)
expect(range.to_a).to eq([])
end
end
context 'begining version is not equal to ending version' do
it 'returns an array with versions between' do
version_1 = Version.new('3.4.8')
version_2 = Version.new('3.5.8')
range = Version::Range.new(version_1, version_2)
result = [
'3.4.8', '3.4.9', '3.5.0', '3.5.1', '3.5.2',
'3.5.3', '3.5.4', '3.5.5', '3.5.6', '3.5.7'
]
expect(range.to_a).to eq(result)
version_1 = Version.new('3.9')
version_2 = Version.new('4')
range = Version::Range.new(version_1, version_2)
result = [
'3.9.0', '3.9.1', '3.9.2', '3.9.3', '3.9.4',
'3.9.5', '3.9.6', '3.9.7', '3.9.8', '3.9.9'
]
expect(range.to_a).to eq(result)
version_1 = Version.new('1.9.5')
version_2 = Version.new('2.0.3')
range = Version::Range.new(version_1, version_2)
result = [
'1.9.5', '1.9.6', '1.9.7', '1.9.8', '1.9.9',
'2.0.0', '2.0.1', '2.0.2'
]
expect(range.to_a).to eq(result)
end
end
end
end
end

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

.F...FF...F.F...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-g073kb/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-g073kb/spec.rb:341: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-g073kb/spec.rb:359: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 tests that #components cannot be used to modify the version
     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
             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-g073kb/spec.rb:456: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)>'

  5) spec Version::Range tests constructing ranges with strings
     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 = start_version
               @end_version   = 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-g073kb/spec.rb:479: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)>'

  6) 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-g073kb/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.69 seconds
19 examples, 6 failures

Failed examples:

rspec /tmp/d20161119-19072-g073kb/spec.rb:241 # spec Version checks for ArgumentError with the correct message
rspec /tmp/d20161119-19072-g073kb/spec.rb:317 # spec Version checks for comparison operators positively
rspec /tmp/d20161119-19072-g073kb/spec.rb:353 # spec Version checks for comparison operators negatively
rspec /tmp/d20161119-19072-g073kb/spec.rb:441 # spec Version tests that #components cannot be used to modify the version
rspec /tmp/d20161119-19072-g073kb/spec.rb:471 # spec Version::Range tests constructing ranges with strings
rspec /tmp/d20161119-19072-g073kb/spec.rb:515 # spec Version::Range tests include? with versions lower than the start one

История (5 версии и 6 коментара)

Светослав обнови решението на 15.11.2016 02:12 (преди над 1 година)

+RSpec.describe 'Version' do
+ describe 'Version comparison' do
+ it 'compares versions with same number of digits' do
+ expect(Version.new('') == Version.new).to be true
+
+ v1 = Version.new('1.3.3')
+ v2 = Version.new('1.3.3')
+ expect(v1).to eq v2
+
+ expect(Version.new('1.2.3') < Version.new('1.3.3')).to be true
+
+ expect(Version.new('2.3.3') > Version.new('1.4.3')).to be true
+ end
+
+ it 'compares versions with different number of digits' do
+ expect(Version.new('1.3.3.0') == Version.new('1.3.3')).to be true
+
+ expect(Version.new('1.3.3') < Version.new('1.3.3.1')).to be true
+
+ expect(Version.new('1.3.3.0.1') < Version.new('1.3.3.1')).to be true
+
+ expect(Version.new('1.3') > Version.new('1.2.3')).to be true
+
+ expect(Version.new('3') > Version.new('0.3')).to be true
+ end
+ end
+
+ describe 'Version#to_s' do
+ it 'transforms version to string' do
+ v = Version.new('')
+ expect(v.to_s).to eq('')
+
+ v = Version.new
+ expect(v.to_s).to eq('')
+
+ v = Version.new('1.3.5')
+ expect(v.to_s).to eq('1.3.5')
+
+ v = Version.new('0.3.5')
+ expect(v.to_s).to eq('0.3.5')
+
+ v = Version.new('0.0.5')
+ expect(v.to_s).to eq('0.0.5')
+
+ v = Version.new('1.3.0')
+ expect(v.to_s).to eq('1.3')
+
+ v = Version.new('1.0.5')
+ expect(v.to_s).to eq('1.0.5')
+
+ v = Version.new('1.3.5.0.0')
+ expect(v.to_s).to eq('1.3.5')
+ end
+ end
+
+ describe 'Version#components' do
+ context 'Version#components without an argument' do
+ it 'returns an array with the version components' do
+ v = Version.new('2.4.6')
+ expect(v.components).to eq( [2, 4, 6] )
+
+ v = Version.new('0.4.6')
+ expect(v.components).to eq( [0, 4, 6] )
+ end
+
+ it 'returns an array with the version components without ending zeros' do
+ v = Version.new('2.4.0.0')
+ expect(v.components).to eq( [2, 4] )
+
+ v = Version.new('2.4.0.6.0')
+ expect(v.components).to eq( [2, 4, 0, 6] )
+ end
+ end
+
+ context 'Version#components with an argument' do
+ it 'returns an array with exact number of components' do
+ v = Version.new('3.5.8')
+ expect(v.components(3)).to eq( [3, 5, 8] )
+ end
+
+ it 'returns an array with more components' do
+ v = Version.new('3.5.8')
+ expect(v.components(5)).to eq( [3, 5, 8, 0, 0] )
+ end
+
+ it 'returns an array with less components' do
+ v = Version.new('3.5.8')
+ expect(v.components(2)).to eq( [3, 5] )
+ end
+ end
+ end
+
+ describe 'Version::Range' do
+ describe 'Range#include?' do
+ it 'returns true if version is within range' do
+ r = Version::Range.new('1.0.0', '3.0.0')
+ v = Version.new('2.0.0')
+ expect(r.include?(v)).to eq true
+
+ r = Version::Range.new('1.3.5', '3.5.8')
+ v = Version.new('1.3.5')
+ expect(r.include?(v)).to eq true
+
+ r = Version::Range.new('1.0.0', '2')
+ v = Version.new('1.5')
+ expect(r.include?(v)).to be true
+
+ r = Version::Range.new('1.10.5', '2.3.6.1')
+ v = Version.new('2.3.5')
+ expect(r.include?(v)).to eq true
+ end
+
+ it 'returns false if version is not withing range' do
+ r = Version::Range.new('1.0.0', '2.0.0')
+ v = Version.new('3.0.0')
+ expect(r.include?(v)).to eq false
+
+ r = Version::Range.new('1.3.5', '1.3.5')
+ v = Version.new('1.3.5')
+ expect(r.include?(v)).to eq false
+
+ r = Version::Range.new('1.0.0', '2.0.0')
+ v = Version.new('2.0.0')
+ expect(r.include?(v)).to eq false
+ end
+ end
+
+ describe 'Range#to_a' do
+ context 'begining version is equal to ending version' do
+ it 'returns an empty array' do
+ v1 = Version.new('3.5.8')
+ v2 = Version.new('3.5.8')
+ r = Version::Range.new(v1, v2)
+ expect(r.to_a).to eq([])
+
+ v1 = Version.new('3.0')
+ v2 = Version.new('3.0.0')
+ r = Version::Range.new(v1, v2)
+ expect(r.to_a).to eq([])
+ end
+ end
+
+ context 'begining version is not equal to ending version' do
+ it 'returns an array with versions between' do
+ v1 = Version.new('3.4.8')
+ v2 = Version.new('3.5.8')
+ r = Version::Range.new(v1, v2)
+ result = [
+ '3.4.8', '3.4.9', '3.5.0', '3.5.1', '3.5.2',
+ '3.5.3', '3.5.4', '3.5.5', '3.5.6', '3.5.7',
+ ]
+ expect(r.to_a).to eq(result)
+
+ v1 = Version.new('3.9')
+ v2 = Version.new('4')
+ r = Version::Range.new(v1, v2)
+ result = [
+ '3.9.0', '3.9.1', '3.9.2', '3.9.3', '3.9.4',
+ '3.9.5', '3.9.6', '3.9.7', '3.9.8', '3.9.9',
+ ]
+ expect(r.to_a).to eq(result)
+ end
+ end
+ end
+ end
+end

Светослав обнови решението на 15.11.2016 16:03 (преди над 1 година)

RSpec.describe 'Version' do
describe 'Version comparison' do
- it 'compares versions with same number of digits' do
- expect(Version.new('') == Version.new).to be true
+ it 'compares versions with same number of components' do
+ expect(Version.new('')).to eq Version.new
- v1 = Version.new('1.3.3')
- v2 = Version.new('1.3.3')
- expect(v1).to eq v2
+ expect(Version.new('1.3.3')).to eq Version.new('1.3.3')
- expect(Version.new('1.2.3') < Version.new('1.3.3')).to be true
+ expect(Version.new('1.2.3')).to be < Version.new('1.3.3')
- expect(Version.new('2.3.3') > Version.new('1.4.3')).to be true
+ expect(Version.new('2.3.3')).to be > Version.new('1.4.3')
end
- it 'compares versions with different number of digits' do
- expect(Version.new('1.3.3.0') == Version.new('1.3.3')).to be true
+ it 'compares versions with different number of components' do
+ expect(Version.new('1.3.3.0')).to eq Version.new('1.3.3')
- expect(Version.new('1.3.3') < Version.new('1.3.3.1')).to be true
+ expect(Version.new('0.5')).to_not eq Version.new('5')
- expect(Version.new('1.3.3.0.1') < Version.new('1.3.3.1')).to be true
+ expect(Version.new('1.3.3')).to be < Version.new('1.3.3.1')
- expect(Version.new('1.3') > Version.new('1.2.3')).to be true
+ expect(Version.new('1.3.3.0.1')).to be < Version.new('1.3.3.1')
- expect(Version.new('3') > Version.new('0.3')).to be true
+ expect(Version.new('1.3')).to be > Version.new('1.2.3')
+
+ expect(Version.new('3')).to be > Version.new('0.3')
end
end
describe 'Version#to_s' do
it 'transforms version to string' do
- v = Version.new('')
- expect(v.to_s).to eq('')
+ expect(Version.new('').to_s).to eq('')
- v = Version.new
- expect(v.to_s).to eq('')
+ expect(Version.new.to_s).to eq('')
- v = Version.new('1.3.5')
- expect(v.to_s).to eq('1.3.5')
+ expect(Version.new('30.5').to_s).to eq('30.5')
- v = Version.new('0.3.5')
- expect(v.to_s).to eq('0.3.5')
+ expect(Version.new('0.3.5').to_s).to eq('0.3.5')
- v = Version.new('0.0.5')
- expect(v.to_s).to eq('0.0.5')
+ expect(Version.new('0.0.5').to_s).to eq('0.0.5')
- v = Version.new('1.3.0')
- expect(v.to_s).to eq('1.3')
+ expect(Version.new('1.0.5').to_s).to eq('1.0.5')
+ end
- v = Version.new('1.0.5')
- expect(v.to_s).to eq('1.0.5')
+ it 'transforms version to string and removes ending zeros' do
+ expect(Version.new('1.3.0').to_s).to eq('1.3')
- v = Version.new('1.3.5.0.0')
- expect(v.to_s).to eq('1.3.5')
+ expect(Version.new('1.3.5.0.0').to_s).to eq('1.3.5')
end
end
describe 'Version#components' do
context 'Version#components without an argument' do
it 'returns an array with the version components' do
- v = Version.new('2.4.6')
- expect(v.components).to eq( [2, 4, 6] )
+ expect(Version.new('2.4.6').components).to eq( [2, 4, 6] )
- v = Version.new('0.4.6')
- expect(v.components).to eq( [0, 4, 6] )
+ expect(Version.new('0.4.6').components).to eq( [0, 4, 6] )
end
- it 'returns an array with the version components without ending zeros' do
- v = Version.new('2.4.0.0')
- expect(v.components).to eq( [2, 4] )
+ it 'returns an array with the version components without ending zeros' do
+ expect(Version.new('2.4.0.0').components).to eq( [2, 4] )
- v = Version.new('2.4.0.6.0')
- expect(v.components).to eq( [2, 4, 0, 6] )
+ expect(Version.new('2.4.0.6.0').components).to eq( [2, 4, 0, 6] )
end
end
context 'Version#components with an argument' do
it 'returns an array with exact number of components' do
- v = Version.new('3.5.8')
- expect(v.components(3)).to eq( [3, 5, 8] )
+ expect(Version.new('3.5.8').components(3)).to eq( [3, 5, 8] )
end
it 'returns an array with more components' do
- v = Version.new('3.5.8')
- expect(v.components(5)).to eq( [3, 5, 8, 0, 0] )
+ expect(Version.new('3.5.8').components(5)).to eq( [3, 5, 8, 0, 0] )
end
it 'returns an array with less components' do
- v = Version.new('3.5.8')
- expect(v.components(2)).to eq( [3, 5] )
+ expect(Version.new('3.5.8').components(2)).to eq( [3, 5] )
end
end
end
describe 'Version::Range' do
describe 'Range#include?' do
it 'returns true if version is within range' do
r = Version::Range.new('1.0.0', '3.0.0')
v = Version.new('2.0.0')
expect(r.include?(v)).to eq true
r = Version::Range.new('1.3.5', '3.5.8')
v = Version.new('1.3.5')
expect(r.include?(v)).to eq true
r = Version::Range.new('1.0.0', '2')
v = Version.new('1.5')
expect(r.include?(v)).to be true
r = Version::Range.new('1.10.5', '2.3.6.1')
v = Version.new('2.3.5')
expect(r.include?(v)).to eq true
end
it 'returns false if version is not withing range' do
r = Version::Range.new('1.0.0', '2.0.0')
v = Version.new('3.0.0')
expect(r.include?(v)).to eq false
r = Version::Range.new('1.3.5', '1.3.5')
v = Version.new('1.3.5')
expect(r.include?(v)).to eq false
r = Version::Range.new('1.0.0', '2.0.0')
v = Version.new('2.0.0')
expect(r.include?(v)).to eq false
end
end
describe 'Range#to_a' do
context 'begining version is equal to ending version' do
it 'returns an empty array' do
v1 = Version.new('3.5.8')
v2 = Version.new('3.5.8')
r = Version::Range.new(v1, v2)
expect(r.to_a).to eq([])
v1 = Version.new('3.0')
v2 = Version.new('3.0.0')
r = Version::Range.new(v1, v2)
expect(r.to_a).to eq([])
end
end
context 'begining version is not equal to ending version' do
it 'returns an array with versions between' do
v1 = Version.new('3.4.8')
v2 = Version.new('3.5.8')
r = Version::Range.new(v1, v2)
result = [
'3.4.8', '3.4.9', '3.5.0', '3.5.1', '3.5.2',
- '3.5.3', '3.5.4', '3.5.5', '3.5.6', '3.5.7',
+ '3.5.3', '3.5.4', '3.5.5', '3.5.6', '3.5.7'
]
expect(r.to_a).to eq(result)
v1 = Version.new('3.9')
v2 = Version.new('4')
r = Version::Range.new(v1, v2)
result = [
'3.9.0', '3.9.1', '3.9.2', '3.9.3', '3.9.4',
- '3.9.5', '3.9.6', '3.9.7', '3.9.8', '3.9.9',
+ '3.9.5', '3.9.6', '3.9.7', '3.9.8', '3.9.9'
+ ]
+ expect(r.to_a).to eq(result)
+
+ v1 = Version.new('1.9.5')
+ v2 = Version.new('2.0.3')
+ r = Version::Range.new(v1, v2)
+ result = [
+ '1.9.5', '1.9.6', '1.9.7', '1.9.8', '1.9.9',
+ '2.0.0', '2.0.1', '2.0.2'
]
expect(r.to_a).to eq(result)
end
end
end
end
end

Светослав обнови решението на 15.11.2016 16:08 (преди над 1 година)

RSpec.describe 'Version' do
describe 'Version comparison' do
it 'compares versions with same number of components' do
expect(Version.new('')).to eq Version.new
expect(Version.new('1.3.3')).to eq Version.new('1.3.3')
expect(Version.new('1.2.3')).to be < Version.new('1.3.3')
expect(Version.new('2.3.3')).to be > Version.new('1.4.3')
end
it 'compares versions with different number of components' do
expect(Version.new('1.3.3.0')).to eq Version.new('1.3.3')
expect(Version.new('0.5')).to_not eq Version.new('5')
expect(Version.new('1.3.3')).to be < Version.new('1.3.3.1')
expect(Version.new('1.3.3.0.1')).to be < Version.new('1.3.3.1')
expect(Version.new('1.3')).to be > Version.new('1.2.3')
expect(Version.new('3')).to be > Version.new('0.3')
end
end
describe 'Version#to_s' do
it 'transforms version to string' do
expect(Version.new('').to_s).to eq('')
expect(Version.new.to_s).to eq('')
expect(Version.new('30.5').to_s).to eq('30.5')
expect(Version.new('0.3.5').to_s).to eq('0.3.5')
expect(Version.new('0.0.5').to_s).to eq('0.0.5')
expect(Version.new('1.0.5').to_s).to eq('1.0.5')
end
it 'transforms version to string and removes ending zeros' do
expect(Version.new('1.3.0').to_s).to eq('1.3')
expect(Version.new('1.3.5.0.0').to_s).to eq('1.3.5')
end
end
describe 'Version#components' do
context 'Version#components without an argument' do
it 'returns an array with the version components' do
expect(Version.new('2.4.6').components).to eq( [2, 4, 6] )
expect(Version.new('0.4.6').components).to eq( [0, 4, 6] )
end
it 'returns an array with the version components without ending zeros' do
expect(Version.new('2.4.0.0').components).to eq( [2, 4] )
expect(Version.new('2.4.0.6.0').components).to eq( [2, 4, 0, 6] )
end
end
context 'Version#components with an argument' do
it 'returns an array with exact number of components' do
expect(Version.new('3.5.8').components(3)).to eq( [3, 5, 8] )
end
it 'returns an array with more components' do
expect(Version.new('3.5.8').components(5)).to eq( [3, 5, 8, 0, 0] )
end
it 'returns an array with less components' do
expect(Version.new('3.5.8').components(2)).to eq( [3, 5] )
end
end
end
describe 'Version::Range' do
describe 'Range#include?' do
it 'returns true if version is within range' do
- r = Version::Range.new('1.0.0', '3.0.0')
- v = Version.new('2.0.0')
- expect(r.include?(v)).to eq true
+ range = Version::Range.new('1.0.0', '3.0.0')
+ version = Version.new('2.0.0')
+ expect(range.include?(version)).to eq true
- r = Version::Range.new('1.3.5', '3.5.8')
- v = Version.new('1.3.5')
- expect(r.include?(v)).to eq true
+ range = Version::Range.new('1.3.5', '3.5.8')
+ version = Version.new('1.3.5')
+ expect(range.include?(version)).to eq true
- r = Version::Range.new('1.0.0', '2')
- v = Version.new('1.5')
- expect(r.include?(v)).to be true
+ range = Version::Range.new('1.0.0', '2')
+ version = Version.new('1.5')
+ expect(range.include?(version)).to be true
- r = Version::Range.new('1.10.5', '2.3.6.1')
- v = Version.new('2.3.5')
- expect(r.include?(v)).to eq true
+ range = Version::Range.new('1.10.5', '2.3.6.1')
+ version = Version.new('2.3.5')
+ expect(range.include?(version)).to eq true
end
it 'returns false if version is not withing range' do
- r = Version::Range.new('1.0.0', '2.0.0')
- v = Version.new('3.0.0')
- expect(r.include?(v)).to eq false
+ range = Version::Range.new('1.0.0', '2.0.0')
+ version = Version.new('3.0.0')
+ expect(range.include?(version)).to eq false
- r = Version::Range.new('1.3.5', '1.3.5')
- v = Version.new('1.3.5')
- expect(r.include?(v)).to eq false
+ range = Version::Range.new('1.3.5', '1.3.5')
+ version = Version.new('1.3.5')
+ expect(range.include?(version)).to eq false
- r = Version::Range.new('1.0.0', '2.0.0')
- v = Version.new('2.0.0')
- expect(r.include?(v)).to eq false
+ range = Version::Range.new('1.0.0', '2.0.0')
+ version = Version.new('2.0.0')
+ expect(range.include?(version)).to eq false
end
end
describe 'Range#to_a' do
context 'begining version is equal to ending version' do
it 'returns an empty array' do
- v1 = Version.new('3.5.8')
- v2 = Version.new('3.5.8')
- r = Version::Range.new(v1, v2)
- expect(r.to_a).to eq([])
+ version_1 = Version.new('3.5.8')
+ version_2 = Version.new('3.5.8')
+ range = Version::Range.new(version_1, version_2)
+ expect(range.to_a).to eq([])
- v1 = Version.new('3.0')
- v2 = Version.new('3.0.0')
- r = Version::Range.new(v1, v2)
- expect(r.to_a).to eq([])
+ version_1 = Version.new('3.0')
+ version_2 = Version.new('3.0.0')
+ range = Version::Range.new(version_1, version_2)
+ expect(range.to_a).to eq([])
end
end
context 'begining version is not equal to ending version' do
it 'returns an array with versions between' do
- v1 = Version.new('3.4.8')
- v2 = Version.new('3.5.8')
- r = Version::Range.new(v1, v2)
+ version_1 = Version.new('3.4.8')
+ version_2 = Version.new('3.5.8')
+ range = Version::Range.new(version_1, version_2)
result = [
'3.4.8', '3.4.9', '3.5.0', '3.5.1', '3.5.2',
'3.5.3', '3.5.4', '3.5.5', '3.5.6', '3.5.7'
]
- expect(r.to_a).to eq(result)
+ expect(range.to_a).to eq(result)
- v1 = Version.new('3.9')
- v2 = Version.new('4')
- r = Version::Range.new(v1, v2)
+ version_1 = Version.new('3.9')
+ version_2 = Version.new('4')
+ range = Version::Range.new(version_1, version_2)
result = [
'3.9.0', '3.9.1', '3.9.2', '3.9.3', '3.9.4',
'3.9.5', '3.9.6', '3.9.7', '3.9.8', '3.9.9'
]
- expect(r.to_a).to eq(result)
+ expect(range.to_a).to eq(result)
- v1 = Version.new('1.9.5')
- v2 = Version.new('2.0.3')
- r = Version::Range.new(v1, v2)
+ version_1 = Version.new('1.9.5')
+ version_2 = Version.new('2.0.3')
+ range = Version::Range.new(version_1, version_2)
result = [
'1.9.5', '1.9.6', '1.9.7', '1.9.8', '1.9.9',
'2.0.0', '2.0.1', '2.0.2'
]
- expect(r.to_a).to eq(result)
+ expect(range.to_a).to eq(result)
end
end
end
end
end

Светослав обнови решението на 15.11.2016 16:16 (преди над 1 година)

RSpec.describe 'Version' do
describe 'Version comparison' do
it 'compares versions with same number of components' do
expect(Version.new('')).to eq Version.new
expect(Version.new('1.3.3')).to eq Version.new('1.3.3')
expect(Version.new('1.2.3')).to be < Version.new('1.3.3')
expect(Version.new('2.3.3')).to be > Version.new('1.4.3')
end
it 'compares versions with different number of components' do
expect(Version.new('1.3.3.0')).to eq Version.new('1.3.3')
expect(Version.new('0.5')).to_not eq Version.new('5')
expect(Version.new('1.3.3')).to be < Version.new('1.3.3.1')
expect(Version.new('1.3.3.0.1')).to be < Version.new('1.3.3.1')
expect(Version.new('1.3')).to be > Version.new('1.2.3')
expect(Version.new('3')).to be > Version.new('0.3')
end
end
describe 'Version#to_s' do
it 'transforms version to string' do
expect(Version.new('').to_s).to eq('')
expect(Version.new.to_s).to eq('')
expect(Version.new('30.5').to_s).to eq('30.5')
expect(Version.new('0.3.5').to_s).to eq('0.3.5')
expect(Version.new('0.0.5').to_s).to eq('0.0.5')
expect(Version.new('1.0.5').to_s).to eq('1.0.5')
end
it 'transforms version to string and removes ending zeros' do
expect(Version.new('1.3.0').to_s).to eq('1.3')
expect(Version.new('1.3.5.0.0').to_s).to eq('1.3.5')
end
end
describe 'Version#components' do
context 'Version#components without an argument' do
it 'returns an array with the version components' do
- expect(Version.new('2.4.6').components).to eq( [2, 4, 6] )
+ expect(Version.new('2.4.6').components).to eq([2, 4, 6])
- expect(Version.new('0.4.6').components).to eq( [0, 4, 6] )
+ expect(Version.new('0.4.6').components).to eq([0, 4, 6])
end
it 'returns an array with the version components without ending zeros' do
- expect(Version.new('2.4.0.0').components).to eq( [2, 4] )
+ expect(Version.new('2.4.0.0').components).to eq([2, 4])
- expect(Version.new('2.4.0.6.0').components).to eq( [2, 4, 0, 6] )
+ expect(Version.new('2.4.0.6.0').components).to eq([2, 4, 0, 6])
end
end
context 'Version#components with an argument' do
it 'returns an array with exact number of components' do
- expect(Version.new('3.5.8').components(3)).to eq( [3, 5, 8] )
+ expect(Version.new('3.5.8').components(3)).to eq([3, 5, 8])
end
it 'returns an array with more components' do
- expect(Version.new('3.5.8').components(5)).to eq( [3, 5, 8, 0, 0] )
+ expect(Version.new('3.5.8').components(5)).to eq([3, 5, 8, 0, 0])
end
it 'returns an array with less components' do
- expect(Version.new('3.5.8').components(2)).to eq( [3, 5] )
+ expect(Version.new('3.5.8').components(2)).to eq([3, 5])
end
end
end
describe 'Version::Range' do
describe 'Range#include?' do
it 'returns true if version is within range' do
range = Version::Range.new('1.0.0', '3.0.0')
version = Version.new('2.0.0')
expect(range.include?(version)).to eq true
range = Version::Range.new('1.3.5', '3.5.8')
version = Version.new('1.3.5')
expect(range.include?(version)).to eq true
range = Version::Range.new('1.0.0', '2')
version = Version.new('1.5')
expect(range.include?(version)).to be true
range = Version::Range.new('1.10.5', '2.3.6.1')
version = Version.new('2.3.5')
expect(range.include?(version)).to eq true
end
it 'returns false if version is not withing range' do
range = Version::Range.new('1.0.0', '2.0.0')
version = Version.new('3.0.0')
expect(range.include?(version)).to eq false
range = Version::Range.new('1.3.5', '1.3.5')
version = Version.new('1.3.5')
expect(range.include?(version)).to eq false
range = Version::Range.new('1.0.0', '2.0.0')
version = Version.new('2.0.0')
expect(range.include?(version)).to eq false
end
end
describe 'Range#to_a' do
context 'begining version is equal to ending version' do
it 'returns an empty array' do
version_1 = Version.new('3.5.8')
version_2 = Version.new('3.5.8')
range = Version::Range.new(version_1, version_2)
expect(range.to_a).to eq([])
version_1 = Version.new('3.0')
version_2 = Version.new('3.0.0')
range = Version::Range.new(version_1, version_2)
expect(range.to_a).to eq([])
end
end
context 'begining version is not equal to ending version' do
it 'returns an array with versions between' do
version_1 = Version.new('3.4.8')
version_2 = Version.new('3.5.8')
range = Version::Range.new(version_1, version_2)
result = [
'3.4.8', '3.4.9', '3.5.0', '3.5.1', '3.5.2',
'3.5.3', '3.5.4', '3.5.5', '3.5.6', '3.5.7'
]
expect(range.to_a).to eq(result)
version_1 = Version.new('3.9')
version_2 = Version.new('4')
range = Version::Range.new(version_1, version_2)
result = [
'3.9.0', '3.9.1', '3.9.2', '3.9.3', '3.9.4',
'3.9.5', '3.9.6', '3.9.7', '3.9.8', '3.9.9'
]
expect(range.to_a).to eq(result)
version_1 = Version.new('1.9.5')
version_2 = Version.new('2.0.3')
range = Version::Range.new(version_1, version_2)
result = [
'1.9.5', '1.9.6', '1.9.7', '1.9.8', '1.9.9',
'2.0.0', '2.0.1', '2.0.2'
]
expect(range.to_a).to eq(result)
end
end
end
end
end

Светослав обнови решението на 18.11.2016 22:30 (преди над 1 година)

RSpec.describe 'Version' do
+ describe 'Argument exception' do
+ it 'throws ArgumentError on wrong input' do
+ expect { Version.new('.3') }.to raise_error(ArgumentError)
+
+ expect { Version.new('1.3.4..') }.to raise_error(ArgumentError)
+
+ expect { Version.new('0..3') }.to raise_error(ArgumentError)
+
+ expect { Version.new('throwexception') }.to raise_error(ArgumentError)
+ end
+ end
describe 'Version comparison' do
it 'compares versions with same number of components' do
expect(Version.new('')).to eq Version.new
expect(Version.new('1.3.3')).to eq Version.new('1.3.3')
expect(Version.new('1.2.3')).to be < Version.new('1.3.3')
expect(Version.new('2.3.3')).to be > Version.new('1.4.3')
end
it 'compares versions with different number of components' do
expect(Version.new('1.3.3.0')).to eq Version.new('1.3.3')
expect(Version.new('0.5')).to_not eq Version.new('5')
expect(Version.new('1.3.3')).to be < Version.new('1.3.3.1')
expect(Version.new('1.3.3.0.1')).to be < Version.new('1.3.3.1')
expect(Version.new('1.3')).to be > Version.new('1.2.3')
expect(Version.new('3')).to be > Version.new('0.3')
end
end
describe 'Version#to_s' do
it 'transforms version to string' do
expect(Version.new('').to_s).to eq('')
expect(Version.new.to_s).to eq('')
expect(Version.new('30.5').to_s).to eq('30.5')
expect(Version.new('0.3.5').to_s).to eq('0.3.5')
expect(Version.new('0.0.5').to_s).to eq('0.0.5')
expect(Version.new('1.0.5').to_s).to eq('1.0.5')
end
it 'transforms version to string and removes ending zeros' do
expect(Version.new('1.3.0').to_s).to eq('1.3')
expect(Version.new('1.3.5.0.0').to_s).to eq('1.3.5')
end
end
describe 'Version#components' do
context 'Version#components without an argument' do
it 'returns an array with the version components' do
expect(Version.new('2.4.6').components).to eq([2, 4, 6])
expect(Version.new('0.4.6').components).to eq([0, 4, 6])
end
it 'returns an array with the version components without ending zeros' do
expect(Version.new('2.4.0.0').components).to eq([2, 4])
expect(Version.new('2.4.0.6.0').components).to eq([2, 4, 0, 6])
end
end
context 'Version#components with an argument' do
it 'returns an array with exact number of components' do
expect(Version.new('3.5.8').components(3)).to eq([3, 5, 8])
end
it 'returns an array with more components' do
expect(Version.new('3.5.8').components(5)).to eq([3, 5, 8, 0, 0])
end
it 'returns an array with less components' do
expect(Version.new('3.5.8').components(2)).to eq([3, 5])
end
end
end
describe 'Version::Range' do
describe 'Range#include?' do
it 'returns true if version is within range' do
range = Version::Range.new('1.0.0', '3.0.0')
version = Version.new('2.0.0')
expect(range.include?(version)).to eq true
range = Version::Range.new('1.3.5', '3.5.8')
version = Version.new('1.3.5')
expect(range.include?(version)).to eq true
range = Version::Range.new('1.0.0', '2')
version = Version.new('1.5')
expect(range.include?(version)).to be true
range = Version::Range.new('1.10.5', '2.3.6.1')
version = Version.new('2.3.5')
expect(range.include?(version)).to eq true
end
it 'returns false if version is not withing range' do
range = Version::Range.new('1.0.0', '2.0.0')
version = Version.new('3.0.0')
expect(range.include?(version)).to eq false
range = Version::Range.new('1.3.5', '1.3.5')
version = Version.new('1.3.5')
expect(range.include?(version)).to eq false
range = Version::Range.new('1.0.0', '2.0.0')
version = Version.new('2.0.0')
expect(range.include?(version)).to eq false
end
end
describe 'Range#to_a' do
context 'begining version is equal to ending version' do
it 'returns an empty array' do
version_1 = Version.new('3.5.8')
version_2 = Version.new('3.5.8')
range = Version::Range.new(version_1, version_2)
expect(range.to_a).to eq([])
version_1 = Version.new('3.0')
version_2 = Version.new('3.0.0')
range = Version::Range.new(version_1, version_2)
expect(range.to_a).to eq([])
end
end
context 'begining version is not equal to ending version' do
it 'returns an array with versions between' do
version_1 = Version.new('3.4.8')
version_2 = Version.new('3.5.8')
range = Version::Range.new(version_1, version_2)
result = [
'3.4.8', '3.4.9', '3.5.0', '3.5.1', '3.5.2',
'3.5.3', '3.5.4', '3.5.5', '3.5.6', '3.5.7'
]
expect(range.to_a).to eq(result)
version_1 = Version.new('3.9')
version_2 = Version.new('4')
range = Version::Range.new(version_1, version_2)
result = [
'3.9.0', '3.9.1', '3.9.2', '3.9.3', '3.9.4',
'3.9.5', '3.9.6', '3.9.7', '3.9.8', '3.9.9'
]
expect(range.to_a).to eq(result)
version_1 = Version.new('1.9.5')
version_2 = Version.new('2.0.3')
range = Version::Range.new(version_1, version_2)
result = [
'1.9.5', '1.9.6', '1.9.7', '1.9.8', '1.9.9',
'2.0.0', '2.0.1', '2.0.2'
]
expect(range.to_a).to eq(result)
end
end
end
end
end