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

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

Към профила на Антон Сотиров

Резултати

  • 3 точки от тестове
  • 0 бонус точки
  • 3 точки общо
  • 11 успешни тест(а)
  • 8 неуспешни тест(а)

Код

RSpec.describe 'Version' do
describe 'can initialize correctly' do
it 'default version' do
expect(Version.new).to eq ""
end
it 'throws an error if the data is incorrect' do
expect { Version.new('1.2.3.') }.to raise_error(ArgumentError)
expect { Version.new('.1') }.to raise_error(ArgumentError)
expect { Version.new('1..4') }.to raise_error(ArgumentError)
expect { Version.new('a.2.3') }.to raise_error(ArgumentError)
end
it 'correctly set up version' do
expect(Version.new('1.0.3').to_s).to eq '1.0.3'
expect(Version.new('5.0.0').to_s).to eq '5'
expect(Version.new('0.0.1').to_s).to eq '0.0.1'
end
end
describe 'can compare correctly' do
it 'compares simple versions' do
expect(Version.new('1') <=> Version.new('2')).to eq -1
end
it 'compares more complex versions' do
expect(Version.new('1.4.6.2') <=> Version.new('1.4.6.1')).to eq 1
expect(Version.new('1.2.0.0') <=> Version.new('1.2')).to eq 0
expect(Version.new('1.6.3.1') <=> Version.new('1.7.3.1')).to eq -1
end
end
describe 'can get the components of the version' do
it 'gets all the elements of the version' do
expect(Version.new('1.3.5.6').components).to eq [1, 3, 5, 6]
expect(Version.new('1.3.5.6').components).to_not eq [1, 3, 5, 6, 0]
end
it 'gets the first "n" components' do
expect(Version.new('1.2.3.4').components(3)).to eq [1, 2, 3]
expect(Version.new('1.2.3.4').components(6)).to eq [1, 2, 3, 4, 0, 0]
end
end
describe 'can convert the version back to string' do
it 'does it correctly' do
expect(Version.new('1.2.3.4').to_s).to eq '1.2.3.4'
end
end
describe 'Version::Range' do
let(:version1) { Version.new('1') }
let(:version2) { Version.new('2.0.6') }
let(:version3) { Version.new('2.1') }
let(:version_range12) { Version::Range.new(version1, version2) }
let(:version_range13) { Version::Range.new(version1, version3) }
let(:version_range23) { Version::Range.new(version2, version3) }
it 'can find version within a range using #include?' do
expect(version_range12.include?(Version.new('1.5'))).to eq true
expect(version_range12.include?(Version.new('1.234.0'))).to eq true
expect(version_range12.include?(Version.new('1'))).to eq true
expect(version_range12.include?(Version.new('1.9.99'))).to eq true
expect(version_range12.include?(Version.new('2'))).to eq true
end
it 'works with string instead of Version::Range' do
expect(Version::Range.new('1.1', '1.2.3').include?('1.2.2')).to eq true
end
it 'can generate correctly the range of all versions using #to_a' do
expect(version_range23.to_a).to eq ['2.0.6', '2.0.7', '2.0.8', '2.0.9']
end
it 'does not have the second parameter of the Version::Range #to_a' do
expect(version_range23.to_a).to_not include('2.1')
end
end
end

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

.F...FF...F.F.FFF..

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-3tugg3/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-3tugg3/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-3tugg3/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-3tugg3/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-3tugg3/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 smoke-tests include?
     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)
               true
             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-3tugg3/spec.rb:502: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)>'

  7) spec Version::Range tests include? with versions greater 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)
               @start_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-3tugg3/spec.rb:512: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)>'

  8) 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-3tugg3/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 13.93 seconds
19 examples, 8 failures

Failed examples:

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

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

Антон обнови решението на 17.11.2016 17:13 (преди над 7 години)

+RSpec.describe 'Version' do
+ describe 'can initialize correctly' do
+ it 'default version' do
+ expect(Version.new).to eq ""
+ end
+
+ it 'throws an error if the data is incorrect' do
+ expect { Version.new('1.2.3.') }.to raise_error(ArgumentError)
+ expect { Version.new('.1') }.to raise_error(ArgumentError)
+ expect { Version.new('1..4') }.to raise_error(ArgumentError)
+ expect { Version.new('a.2.3') }.to raise_error(ArgumentError)
+ end
+
+ it 'correctly set up version' do
+ expect(Version.new('1.0.3').to_s).to eq '1.0.3'
+ expect(Version.new('5.0.0').to_s).to eq '5'
+ expect(Version.new('0.0.1').to_s).to eq '0.0.1'
+ end
+ end
+
+ describe 'can compare correctly' do
+ it 'compares simple versions' do
+ expect(Version.new('1') <=> Version.new('2')).to eq -1
+ end
+
+ it 'compares more complex versions' do
+ expect(Version.new('1.4.6.2') <=> Version.new('1.4.6.1')).to eq 1
+ expect(Version.new('1.2.0.0') <=> Version.new('1.2')).to eq 0
+ expect(Version.new('1.6.3.1') <=> Version.new('1.7.3.1')).to eq -1
+ end
+ end
+
+ describe 'can get the components of the version' do
+ it 'gets all the elements of the version' do
+ expect(Version.new('1.3.5.6').components).to eq [1, 3, 5, 6]
+ expect(Version.new('1.3.5.6').components).to_not eq [1, 3, 5, 6, 0]
+ end
+ it 'gets the first "n" components' do
+ expect(Version.new('1.2.3.4').components(3)).to eq [1, 2, 3]
+ expect(Version.new('1.2.3.4').components(6)).to eq [1, 2, 3, 4, 0, 0]
+ end
+ end
+
+ describe 'can convert the version back to string' do
+ it 'does it correctly' do
+ expect(Version.new('1.2.3.4').to_s).to eq '1.2.3.4'
+ end
+ end
+
+ describe 'Version::Range' do
+ let(:version1) { Version.new('1') }
+ let(:version2) { Version.new('2.0.6') }
+ let(:version3) { Version.new('2.1') }
+ let(:version_range12) { Version::Range.new(version1, version2) }
+ let(:version_range13) { Version::Range.new(version1, version3) }
+ let(:version_range23) { Version::Range.new(version2, version3) }
+
+ it 'can find version within a range using #include?' do
+ expect(version_range12.include?(Version.new('1.5'))).to eq true
+ expect(version_range12.include?(Version.new('1.234.0'))).to eq true
+ expect(version_range12.include?(Version.new('1'))).to eq true
+ expect(version_range12.include?(Version.new('1.9.99'))).to eq true
+ expect(version_range12.include?(Version.new('2'))).to eq true
+ end
+
+ it 'works with string instead of Version::Range' do
+ expect(Version::Range.new('1.1', '1.2.3').include?('1.2.2')).to eq true
+ end
+
+ it 'can generate correctly the range of all versions using #to_a' do
+ expect(version_range23.to_a).to eq ['2.0.6', '2.0.7', '2.0.8', '2.0.9']
+ end
+
+ it 'does not have the second parameter of the Version::Range #to_a' do
+ expect(version_range23.to_a).to_not include('2.1')
+ end
+ end
+end