Решение на Четвърта задача - Unit тестване от Ивайло Дончев

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

Към профила на Ивайло Дончев

Резултати

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

Код

describe Version do
describe '#initializing' do
it 'pass version starting with point raises argument error' do
expect { Version.new('.3') }.to raise_error(ArgumentError)
end
it 'pass version containing negative number raises argument error' do
expect { Version.new('-1.3') }.to raise_error(ArgumentError)
expect { Version.new('2.-1.3') }.to raise_error(ArgumentError)
end
it 'pass version containing letters raises argument error' do
expect { Version.new('1.a.3') }.to raise_error(ArgumentError)
expect { Version.new('1a.3') }.to raise_error(ArgumentError)
end
it 'pass version ending with zeros doesnt raise error' do
expect { Version.new('1.3.3.0') }.not_to raise_error(ArgumentError)
expect { Version.new('1.3.3.0.0') }.not_to raise_error(ArgumentError)
end
end
describe '# >' do
it 'test greater' do
expect( Version.new('2') > Version.new('1') ).to eq true
expect( Version.new('1') > Version.new('2') ).to eq false
version1 = Version.new('1.1.2')
version2 = Version.new('1.1.3')
version3 = version2
expect( version1 > version2 ).to eq false
expect( version2 > version1 ).to eq true
expect( version2 > version3 ).to eq false
end
end
describe '# <' do
it 'test second is greater' do
expect( Version.new('2') < Version.new('1') ).to eq false
expect( Version.new('1') < Version.new('2') ).to eq true
version1 = Version.new('1.1.2')
version2 = Version.new('1.1.3')
version3 = version2
expect( version1 < version2 ).to eq true
expect( version2 < version1 ).to eq false
expect( version2 < version3 ).to eq false
end
end
describe '# <=' do
it 'test second is greater or eq' do
expect( Version.new('2') <= Version.new('1') ).to eq false
expect( Version.new('1') <= Version.new('2') ).to eq true
version1 = Version.new('1.1.2')
version2 = Version.new('1.1.3')
version3 = version2
expect( version1 <= version2 ).to eq true
expect( version2 <= version1 ).to eq false
expect( version2 <= version3 ).to eq true
end
end
describe '# >=' do
it 'test second is greater or eq' do
expect( Version.new('1') >= Version.new('2') ).to eq false
expect( Version.new('2') >= Version.new('1') ).to eq true
version1 = Version.new('1.1.2')
version2 = Version.new('1.1.3')
version3 = version2
expect( version1 >= version2 ).to eq false
expect( version2 >= version1 ).to eq true
expect( version2 >= version3 ).to eq true
end
end
describe '# ==' do
it 'test second is greater or eq' do
version1 = Version.new('1.1.2')
version2 = Version.new('1.1.3')
version3 = version2
expect( version1 == version2 ).to eq false
expect( version2 == version1 ).to eq false
expect( version2 == version3 ).to eq true
end
end
describe '# <=>' do
it 'test rocked operator' do
version1 = Version.new('1.1.2')
version2 = Version.new('1.1.3')
version3 = version2
expect( version1 <=> version2 ).to eq -1
expect( version2 <=> version1 ).to eq 1
expect( version2 <=> version3 ).to eq 0
end
end
describe '#to_s' do
it 'stringify' do
expect(Version.new('1.3.3.0').to_s).to eq '1.3.3'
expect(Version.new('1.3.3.0.0.0').to_s).to eq '1.3.3'
end
end
describe '#components' do
it 'test components' do
expect(Version.new('1.3.3').components).to eq [1, 3, 3]
expect(Version.new('1.3.3.0').components).to eq [1, 3, 3]
expect(Version.new('1.3.3.0.0.0').components).to eq [1, 3, 3]
end
end
end
describe Range do
describe '# include?' do
it 'test components' do
range = Version::Range.new(Version.new('1.1'), Version.new('2.8'))
expect(
Version::Range.new(
Version.new('1'),
Version.new('2')
).include?(Version.new('1.5'))
).to(eq(true))
expect(range.include?(Version.new('1.0'))).to eq false
expect(range.include?(Version.new('1.1'))).to eq true
expect(range.include?(Version.new('1.1.3'))).to eq true
expect(range.include?(Version.new('2.7'))).to eq true
expect(range.include?(Version.new('2.8'))).to eq false
end
end
describe '#to_a' do
it 'test to_a' do
range = Version::Range.new(Version.new('1.8.8'), Version.new('1.9.1'))
expect(range.to_a ).to eq ['1.8.8', '1.8.9', '1.9.0']
end
end
end

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

Deprecation Warnings:

`expect { }.not_to raise_error(SpecificErrorClass)` is deprecated. Use `expect { }.not_to raise_error` (with no args) instead. Called from /tmp/d20161119-8853-1xo2jn6/solution_spec.rb:15:in `block (3 levels) in <top (required)>'.
`expect { }.not_to raise_error(SpecificErrorClass)` is deprecated. Use `expect { }.not_to raise_error` (with no args) instead. Called from /tmp/d20161119-8853-1xo2jn6/solution_spec.rb:16:in `block (3 levels) in <top (required)>'.


If you need more of the backtrace for any of these deprecations to
identify where to make the necessary changes, you can configure
`config.raise_errors_for_deprecations!`, and it will turn the
deprecation warnings into errors, giving you the full backtrace.

Deprecation Warnings:

`expect { }.not_to raise_error(SpecificErrorClass)` is deprecated. Use `expect { }.not_to raise_error` (with no args) instead. Called from /tmp/d20161119-8853-11ynpxc/solution_spec.rb:15:in `block (3 levels) in <top (required)>'.
`expect { }.not_to raise_error(SpecificErrorClass)` is deprecated. Use `expect { }.not_to raise_error` (with no args) instead. Called from /tmp/d20161119-8853-11ynpxc/solution_spec.rb:16:in `block (3 levels) in <top (required)>'.


If you need more of the backtrace for any of these deprecations to
identify where to make the necessary changes, you can configure
`config.raise_errors_for_deprecations!`, and it will turn the
deprecation warnings into errors, giving you the full backtrace.
.
Deprecation Warnings:

`expect { }.not_to raise_error(SpecificErrorClass)` is deprecated. Use `expect { }.not_to raise_error` (with no args) instead. Called from /tmp/d20161119-8853-rxmb8e/solution_spec.rb:15:in `block (3 levels) in <top (required)>'.
`expect { }.not_to raise_error(SpecificErrorClass)` is deprecated. Use `expect { }.not_to raise_error` (with no args) instead. Called from /tmp/d20161119-8853-rxmb8e/solution_spec.rb:16:in `block (3 levels) in <top (required)>'.


If you need more of the backtrace for any of these deprecations to
identify where to make the necessary changes, you can configure
`config.raise_errors_for_deprecations!`, and it will turn the
deprecation warnings into errors, giving you the full backtrace.
F
Deprecation Warnings:

`expect { }.not_to raise_error(SpecificErrorClass)` is deprecated. Use `expect { }.not_to raise_error` (with no args) instead. Called from /tmp/d20161119-8853-niim5k/solution_spec.rb:15:in `block (3 levels) in <top (required)>'.
`expect { }.not_to raise_error(SpecificErrorClass)` is deprecated. Use `expect { }.not_to raise_error` (with no args) instead. Called from /tmp/d20161119-8853-niim5k/solution_spec.rb:16:in `block (3 levels) in <top (required)>'.


If you need more of the backtrace for any of these deprecations to
identify where to make the necessary changes, you can configure
`config.raise_errors_for_deprecations!`, and it will turn the
deprecation warnings into errors, giving you the full backtrace.
.
Deprecation Warnings:

`expect { }.not_to raise_error(SpecificErrorClass)` is deprecated. Use `expect { }.not_to raise_error` (with no args) instead. Called from /tmp/d20161119-8853-1ubyuu3/solution_spec.rb:15:in `block (3 levels) in <top (required)>'.
`expect { }.not_to raise_error(SpecificErrorClass)` is deprecated. Use `expect { }.not_to raise_error` (with no args) instead. Called from /tmp/d20161119-8853-1ubyuu3/solution_spec.rb:16:in `block (3 levels) in <top (required)>'.


If you need more of the backtrace for any of these deprecations to
identify where to make the necessary changes, you can configure
`config.raise_errors_for_deprecations!`, and it will turn the
deprecation warnings into errors, giving you the full backtrace.
F
Deprecation Warnings:

`expect { }.not_to raise_error(SpecificErrorClass)` is deprecated. Use `expect { }.not_to raise_error` (with no args) instead. Called from /tmp/d20161119-8853-16uwjp3/solution_spec.rb:15:in `block (3 levels) in <top (required)>'.
`expect { }.not_to raise_error(SpecificErrorClass)` is deprecated. Use `expect { }.not_to raise_error` (with no args) instead. Called from /tmp/d20161119-8853-16uwjp3/solution_spec.rb:16:in `block (3 levels) in <top (required)>'.


If you need more of the backtrace for any of these deprecations to
identify where to make the necessary changes, you can configure
`config.raise_errors_for_deprecations!`, and it will turn the
deprecation warnings into errors, giving you the full backtrace.
F
Deprecation Warnings:

`expect { }.not_to raise_error(SpecificErrorClass)` is deprecated. Use `expect { }.not_to raise_error` (with no args) instead. Called from /tmp/d20161119-8853-nxi8t3/solution_spec.rb:15:in `block (3 levels) in <top (required)>'.
`expect { }.not_to raise_error(SpecificErrorClass)` is deprecated. Use `expect { }.not_to raise_error` (with no args) instead. Called from /tmp/d20161119-8853-nxi8t3/solution_spec.rb:16:in `block (3 levels) in <top (required)>'.


If you need more of the backtrace for any of these deprecations to
identify where to make the necessary changes, you can configure
`config.raise_errors_for_deprecations!`, and it will turn the
deprecation warnings into errors, giving you the full backtrace.

Deprecation Warnings:

`expect { }.not_to raise_error(SpecificErrorClass)` is deprecated. Use `expect { }.not_to raise_error` (with no args) instead. Called from /tmp/d20161119-8853-r1zxd3/solution_spec.rb:15:in `block (3 levels) in <top (required)>'.
`expect { }.not_to raise_error(SpecificErrorClass)` is deprecated. Use `expect { }.not_to raise_error` (with no args) instead. Called from /tmp/d20161119-8853-r1zxd3/solution_spec.rb:16:in `block (3 levels) in <top (required)>'.


If you need more of the backtrace for any of these deprecations to
identify where to make the necessary changes, you can configure
`config.raise_errors_for_deprecations!`, and it will turn the
deprecation warnings into errors, giving you the full backtrace.

Deprecation Warnings:

`expect { }.not_to raise_error(SpecificErrorClass)` is deprecated. Use `expect { }.not_to raise_error` (with no args) instead. Called from /tmp/d20161119-8853-gy8f1x/solution_spec.rb:15:in `block (3 levels) in <top (required)>'.
`expect { }.not_to raise_error(SpecificErrorClass)` is deprecated. Use `expect { }.not_to raise_error` (with no args) instead. Called from /tmp/d20161119-8853-gy8f1x/solution_spec.rb:16:in `block (3 levels) in <top (required)>'.


If you need more of the backtrace for any of these deprecations to
identify where to make the necessary changes, you can configure
`config.raise_errors_for_deprecations!`, and it will turn the
deprecation warnings into errors, giving you the full backtrace.

Deprecation Warnings:

`expect { }.not_to raise_error(SpecificErrorClass)` is deprecated. Use `expect { }.not_to raise_error` (with no args) instead. Called from /tmp/d20161119-8853-ev7yy0/solution_spec.rb:15:in `block (3 levels) in <top (required)>'.
`expect { }.not_to raise_error(SpecificErrorClass)` is deprecated. Use `expect { }.not_to raise_error` (with no args) instead. Called from /tmp/d20161119-8853-ev7yy0/solution_spec.rb:16:in `block (3 levels) in <top (required)>'.


If you need more of the backtrace for any of these deprecations to
identify where to make the necessary changes, you can configure
`config.raise_errors_for_deprecations!`, and it will turn the
deprecation warnings into errors, giving you the full backtrace.
.
Deprecation Warnings:

`expect { }.not_to raise_error(SpecificErrorClass)` is deprecated. Use `expect { }.not_to raise_error` (with no args) instead. Called from /tmp/d20161119-8853-67unin/solution_spec.rb:15:in `block (3 levels) in <top (required)>'.
`expect { }.not_to raise_error(SpecificErrorClass)` is deprecated. Use `expect { }.not_to raise_error` (with no args) instead. Called from /tmp/d20161119-8853-67unin/solution_spec.rb:16:in `block (3 levels) in <top (required)>'.


If you need more of the backtrace for any of these deprecations to
identify where to make the necessary changes, you can configure
`config.raise_errors_for_deprecations!`, and it will turn the
deprecation warnings into errors, giving you the full backtrace.

Deprecation Warnings:

`expect { }.not_to raise_error(SpecificErrorClass)` is deprecated. Use `expect { }.not_to raise_error` (with no args) instead. Called from /tmp/d20161119-8853-2u0j3a/solution_spec.rb:15:in `block (3 levels) in <top (required)>'.
`expect { }.not_to raise_error(SpecificErrorClass)` is deprecated. Use `expect { }.not_to raise_error` (with no args) instead. Called from /tmp/d20161119-8853-2u0j3a/solution_spec.rb:16:in `block (3 levels) in <top (required)>'.


If you need more of the backtrace for any of these deprecations to
identify where to make the necessary changes, you can configure
`config.raise_errors_for_deprecations!`, and it will turn the
deprecation warnings into errors, giving you the full backtrace.

Deprecation Warnings:

`expect { }.not_to raise_error(SpecificErrorClass)` is deprecated. Use `expect { }.not_to raise_error` (with no args) instead. Called from /tmp/d20161119-8853-46pu94/solution_spec.rb:15:in `block (3 levels) in <top (required)>'.
`expect { }.not_to raise_error(SpecificErrorClass)` is deprecated. Use `expect { }.not_to raise_error` (with no args) instead. Called from /tmp/d20161119-8853-46pu94/solution_spec.rb:16:in `block (3 levels) in <top (required)>'.


If you need more of the backtrace for any of these deprecations to
identify where to make the necessary changes, you can configure
`config.raise_errors_for_deprecations!`, and it will turn the
deprecation warnings into errors, giving you the full backtrace.

Deprecation Warnings:

`expect { }.not_to raise_error(SpecificErrorClass)` is deprecated. Use `expect { }.not_to raise_error` (with no args) instead. Called from /tmp/d20161119-8853-1dwmlji/solution_spec.rb:15:in `block (3 levels) in <top (required)>'.
`expect { }.not_to raise_error(SpecificErrorClass)` is deprecated. Use `expect { }.not_to raise_error` (with no args) instead. Called from /tmp/d20161119-8853-1dwmlji/solution_spec.rb:16:in `block (3 levels) in <top (required)>'.


If you need more of the backtrace for any of these deprecations to
identify where to make the necessary changes, you can configure
`config.raise_errors_for_deprecations!`, and it will turn the
deprecation warnings into errors, giving you the full backtrace.
.
Deprecation Warnings:

`expect { }.not_to raise_error(SpecificErrorClass)` is deprecated. Use `expect { }.not_to raise_error` (with no args) instead. Called from /tmp/d20161119-8853-qb6c4o/solution_spec.rb:15:in `block (3 levels) in <top (required)>'.
`expect { }.not_to raise_error(SpecificErrorClass)` is deprecated. Use `expect { }.not_to raise_error` (with no args) instead. Called from /tmp/d20161119-8853-qb6c4o/solution_spec.rb:16:in `block (3 levels) in <top (required)>'.


If you need more of the backtrace for any of these deprecations to
identify where to make the necessary changes, you can configure
`config.raise_errors_for_deprecations!`, and it will turn the
deprecation warnings into errors, giving you the full backtrace.
.
Deprecation Warnings:

`expect { }.not_to raise_error(SpecificErrorClass)` is deprecated. Use `expect { }.not_to raise_error` (with no args) instead. Called from /tmp/d20161119-8853-j71jtx/solution_spec.rb:15:in `block (3 levels) in <top (required)>'.
`expect { }.not_to raise_error(SpecificErrorClass)` is deprecated. Use `expect { }.not_to raise_error` (with no args) instead. Called from /tmp/d20161119-8853-j71jtx/solution_spec.rb:16:in `block (3 levels) in <top (required)>'.


If you need more of the backtrace for any of these deprecations to
identify where to make the necessary changes, you can configure
`config.raise_errors_for_deprecations!`, and it will turn the
deprecation warnings into errors, giving you the full backtrace.
F
Deprecation Warnings:

`expect { }.not_to raise_error(SpecificErrorClass)` is deprecated. Use `expect { }.not_to raise_error` (with no args) instead. Called from /tmp/d20161119-8853-13xd1ya/solution_spec.rb:15:in `block (3 levels) in <top (required)>'.
`expect { }.not_to raise_error(SpecificErrorClass)` is deprecated. Use `expect { }.not_to raise_error` (with no args) instead. Called from /tmp/d20161119-8853-13xd1ya/solution_spec.rb:16:in `block (3 levels) in <top (required)>'.


If you need more of the backtrace for any of these deprecations to
identify where to make the necessary changes, you can configure
`config.raise_errors_for_deprecations!`, and it will turn the
deprecation warnings into errors, giving you the full backtrace.
F
Deprecation Warnings:

`expect { }.not_to raise_error(SpecificErrorClass)` is deprecated. Use `expect { }.not_to raise_error` (with no args) instead. Called from /tmp/d20161119-8853-1frxeho/solution_spec.rb:15:in `block (3 levels) in <top (required)>'.
`expect { }.not_to raise_error(SpecificErrorClass)` is deprecated. Use `expect { }.not_to raise_error` (with no args) instead. Called from /tmp/d20161119-8853-1frxeho/solution_spec.rb:16:in `block (3 levels) in <top (required)>'.


If you need more of the backtrace for any of these deprecations to
identify where to make the necessary changes, you can configure
`config.raise_errors_for_deprecations!`, and it will turn the
deprecation warnings into errors, giving you the full backtrace.
F
Deprecation Warnings:

`expect { }.not_to raise_error(SpecificErrorClass)` is deprecated. Use `expect { }.not_to raise_error` (with no args) instead. Called from /tmp/d20161119-8853-2jrtsd/solution_spec.rb:15:in `block (3 levels) in <top (required)>'.
`expect { }.not_to raise_error(SpecificErrorClass)` is deprecated. Use `expect { }.not_to raise_error` (with no args) instead. Called from /tmp/d20161119-8853-2jrtsd/solution_spec.rb:16:in `block (3 levels) in <top (required)>'.


If you need more of the backtrace for any of these deprecations to
identify where to make the necessary changes, you can configure
`config.raise_errors_for_deprecations!`, and it will turn the
deprecation warnings into errors, giving you the full backtrace.
.
Deprecation Warnings:

`expect { }.not_to raise_error(SpecificErrorClass)` is deprecated. Use `expect { }.not_to raise_error` (with no args) instead. Called from /tmp/d20161119-8853-savpnw/solution_spec.rb:15:in `block (3 levels) in <top (required)>'.
`expect { }.not_to raise_error(SpecificErrorClass)` is deprecated. Use `expect { }.not_to raise_error` (with no args) instead. Called from /tmp/d20161119-8853-savpnw/solution_spec.rb:16:in `block (3 levels) in <top (required)>'.


If you need more of the backtrace for any of these deprecations to
identify where to make the necessary changes, you can configure
`config.raise_errors_for_deprecations!`, and it will turn the
deprecation warnings into errors, giving you the full backtrace.
F
Deprecation Warnings:

`expect { }.not_to raise_error(SpecificErrorClass)` is deprecated. Use `expect { }.not_to raise_error` (with no args) instead. Called from /tmp/d20161119-8853-xotcn8/solution_spec.rb:15:in `block (3 levels) in <top (required)>'.
`expect { }.not_to raise_error(SpecificErrorClass)` is deprecated. Use `expect { }.not_to raise_error` (with no args) instead. Called from /tmp/d20161119-8853-xotcn8/solution_spec.rb:16:in `block (3 levels) in <top (required)>'.


If you need more of the backtrace for any of these deprecations to
identify where to make the necessary changes, you can configure
`config.raise_errors_for_deprecations!`, and it will turn the
deprecation warnings into errors, giving you the full backtrace.
.
Deprecation Warnings:

`expect { }.not_to raise_error(SpecificErrorClass)` is deprecated. Use `expect { }.not_to raise_error` (with no args) instead. Called from /tmp/d20161119-8853-18tz0wk/solution_spec.rb:15:in `block (3 levels) in <top (required)>'.
`expect { }.not_to raise_error(SpecificErrorClass)` is deprecated. Use `expect { }.not_to raise_error` (with no args) instead. Called from /tmp/d20161119-8853-18tz0wk/solution_spec.rb:16:in `block (3 levels) in <top (required)>'.


If you need more of the backtrace for any of these deprecations to
identify where to make the necessary changes, you can configure
`config.raise_errors_for_deprecations!`, and it will turn the
deprecation warnings into errors, giving you the full backtrace.
.
Deprecation Warnings:

`expect { }.not_to raise_error(SpecificErrorClass)` is deprecated. Use `expect { }.not_to raise_error` (with no args) instead. Called from /tmp/d20161119-8853-1430ssd/solution_spec.rb:15:in `block (3 levels) in <top (required)>'.
`expect { }.not_to raise_error(SpecificErrorClass)` is deprecated. Use `expect { }.not_to raise_error` (with no args) instead. Called from /tmp/d20161119-8853-1430ssd/solution_spec.rb:16:in `block (3 levels) in <top (required)>'.


If you need more of the backtrace for any of these deprecations to
identify where to make the necessary changes, you can configure
`config.raise_errors_for_deprecations!`, and it will turn the
deprecation warnings into errors, giving you the full backtrace.
.
Deprecation Warnings:

`expect { }.not_to raise_error(SpecificErrorClass)` is deprecated. Use `expect { }.not_to raise_error` (with no args) instead. Called from /tmp/d20161119-8853-1nscn2c/solution_spec.rb:15:in `block (3 levels) in <top (required)>'.
`expect { }.not_to raise_error(SpecificErrorClass)` is deprecated. Use `expect { }.not_to raise_error` (with no args) instead. Called from /tmp/d20161119-8853-1nscn2c/solution_spec.rb:16:in `block (3 levels) in <top (required)>'.


If you need more of the backtrace for any of these deprecations to
identify where to make the necessary changes, you can configure
`config.raise_errors_for_deprecations!`, and it will turn the
deprecation warnings into errors, giving you the full backtrace.
.
Deprecation Warnings:

`expect { }.not_to raise_error(SpecificErrorClass)` is deprecated. Use `expect { }.not_to raise_error` (with no args) instead. Called from /tmp/d20161119-8853-kvwxm5/solution_spec.rb:15:in `block (3 levels) in <top (required)>'.
`expect { }.not_to raise_error(SpecificErrorClass)` is deprecated. Use `expect { }.not_to raise_error` (with no args) instead. Called from /tmp/d20161119-8853-kvwxm5/solution_spec.rb:16:in `block (3 levels) in <top (required)>'.


If you need more of the backtrace for any of these deprecations to
identify where to make the necessary changes, you can configure
`config.raise_errors_for_deprecations!`, and it will turn the
deprecation warnings into errors, giving you the full backtrace.
.
Deprecation Warnings:

`expect { }.not_to raise_error(SpecificErrorClass)` is deprecated. Use `expect { }.not_to raise_error` (with no args) instead. Called from /tmp/d20161119-8853-19ocgae/solution_spec.rb:15:in `block (3 levels) in <top (required)>'.
`expect { }.not_to raise_error(SpecificErrorClass)` is deprecated. Use `expect { }.not_to raise_error` (with no args) instead. Called from /tmp/d20161119-8853-19ocgae/solution_spec.rb:16:in `block (3 levels) in <top (required)>'.


If you need more of the backtrace for any of these deprecations to
identify where to make the necessary changes, you can configure
`config.raise_errors_for_deprecations!`, and it will turn the
deprecation warnings into errors, giving you the full backtrace.
.

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-lz1pyk/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 that initialize can be given an empty string
     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 /\A[0-9]+(\.[0-9]+)*\z/.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-lz1pyk/spec.rb:295: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 that initialize can be given no arguments
     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) < 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-lz1pyk/spec.rb:314: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 #components with less components than present
     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
               [42, 42, 42, 42, 42]
             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-lz1pyk/spec.rb:420: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 tests #components with more components than present
     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
               [42, 42, 42, 42, 42]
             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-lz1pyk/spec.rb:438: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 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-lz1pyk/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)>'

  7) 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-lz1pyk/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)>'

Finished in 18.37 seconds
19 examples, 7 failures

Failed examples:

rspec /tmp/d20161119-19072-lz1pyk/spec.rb:241 # spec Version checks for ArgumentError with the correct message
rspec /tmp/d20161119-19072-lz1pyk/spec.rb:279 # spec Version checks that initialize can be given an empty string
rspec /tmp/d20161119-19072-lz1pyk/spec.rb:298 # spec Version checks that initialize can be given no arguments
rspec /tmp/d20161119-19072-lz1pyk/spec.rb:405 # spec Version tests #components with less components than present
rspec /tmp/d20161119-19072-lz1pyk/spec.rb:423 # spec Version tests #components with more components than present
rspec /tmp/d20161119-19072-lz1pyk/spec.rb:441 # spec Version tests that #components cannot be used to modify the version
rspec /tmp/d20161119-19072-lz1pyk/spec.rb:471 # spec Version::Range tests constructing ranges with strings

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

Ивайло обнови решението на 18.11.2016 23:15 (преди над 7 години)

+describe Version do
+ describe '#initializing' do
+ it 'pass version starting with point raises argument error' do
+ expect { Version.new('.3') }.to raise_error(ArgumentError)
+ end
+ it 'pass version containing negative number raises argument error' do
+ expect { Version.new('-1.3') }.to raise_error(ArgumentError)
+ expect { Version.new('2.-1.3') }.to raise_error(ArgumentError)
+ end
+ it 'pass version containing letters raises argument error' do
+ expect { Version.new('1.a.3') }.to raise_error(ArgumentError)
+ expect { Version.new('1a.3') }.to raise_error(ArgumentError)
+ end
+ it 'pass version ending with zeros doesnt raise error' do
+ expect { Version.new('1.3.3.0') }.not_to raise_error(ArgumentError)
+ expect { Version.new('1.3.3.0.0') }.not_to raise_error(ArgumentError)
+ end
+ end
+ describe '# >' do
+ it 'test greater' do
+ expect( Version.new('2') > Version.new('1') ).to eq true
+ expect( Version.new('1') > Version.new('2') ).to eq false
+
+ version1 = Version.new('1.1.2')
+ version2 = Version.new('1.1.3')
+ version3 = version2
+
+ expect( version1 > version2 ).to eq false
+ expect( version2 > version1 ).to eq true
+ expect( version2 > version3 ).to eq false
+ end
+ end
+ describe '# <' do
+ it 'test second is greater' do
+ expect( Version.new('2') < Version.new('1') ).to eq false
+ expect( Version.new('1') < Version.new('2') ).to eq true
+
+ version1 = Version.new('1.1.2')
+ version2 = Version.new('1.1.3')
+ version3 = version2
+
+ expect( version1 < version2 ).to eq true
+ expect( version2 < version1 ).to eq false
+ expect( version2 < version3 ).to eq false
+ end
+ end
+ describe '# <=' do
+ it 'test second is greater or eq' do
+ expect( Version.new('2') <= Version.new('1') ).to eq false
+ expect( Version.new('1') <= Version.new('2') ).to eq true
+
+ version1 = Version.new('1.1.2')
+ version2 = Version.new('1.1.3')
+ version3 = version2
+
+ expect( version1 <= version2 ).to eq true
+ expect( version2 <= version1 ).to eq false
+ expect( version2 <= version3 ).to eq true
+ end
+ end
+ describe '# >=' do
+ it 'test second is greater or eq' do
+ expect( Version.new('1') >= Version.new('2') ).to eq false
+ expect( Version.new('2') >= Version.new('1') ).to eq true
+
+ version1 = Version.new('1.1.2')
+ version2 = Version.new('1.1.3')
+ version3 = version2
+
+ expect( version1 >= version2 ).to eq false
+ expect( version2 >= version1 ).to eq true
+ expect( version2 >= version3 ).to eq true
+ end
+ end
+ describe '# ==' do
+ it 'test second is greater or eq' do
+ version1 = Version.new('1.1.2')
+ version2 = Version.new('1.1.3')
+ version3 = version2
+
+ expect( version1 == version2 ).to eq false
+ expect( version2 == version1 ).to eq false
+ expect( version2 == version3 ).to eq true
+ end
+ end
+ describe '# <=>' do
+ it 'test rocked operator' do
+ version1 = Version.new('1.1.2')
+ version2 = Version.new('1.1.3')
+ version3 = version2
+
+ expect( version1 <=> version2 ).to eq -1
+ expect( version2 <=> version1 ).to eq 1
+ expect( version2 <=> version3 ).to eq 0
+ end
+ end
+
+ describe '#to_s' do
+ it 'stringify' do
+ expect(Version.new('1.3.3.0').to_s).to eq '1.3.3'
+ expect(Version.new('1.3.3.0.0.0').to_s).to eq '1.3.3'
+ end
+ end
+
+ describe '#components' do
+ it 'test components' do
+ expect(Version.new('1.3.3').components).to eq [1, 3, 3]
+ expect(Version.new('1.3.3.0').components).to eq [1, 3, 3]
+ expect(Version.new('1.3.3.0.0.0').components).to eq [1, 3, 3]
+ end
+ end
+end
+
+describe Range do
+ describe '# include?' do
+ it 'test components' do
+ range = Version::Range.new(Version.new('1.1'), Version.new('2.8'))
+ expect(
+ Version::Range.new(
+ Version.new('1'),
+ Version.new('2')
+ ).include?(Version.new('1.5'))
+ ).to(eq(true))
+ expect(range.include?(Version.new('1.0'))).to eq false
+ expect(range.include?(Version.new('1.1'))).to eq true
+ expect(range.include?(Version.new('1.1.3'))).to eq true
+ expect(range.include?(Version.new('2.7'))).to eq true
+ expect(range.include?(Version.new('2.8'))).to eq false
+ end
+ end
+ describe '#to_a' do
+ it 'test to_a' do
+ range = Version::Range.new(Version.new('1.8.8'), Version.new('1.9.1'))
+ expect(range.to_a ).to eq ['1.8.8', '1.8.9', '1.9.0']
+ end
+ end
+end