Sha256: 8b401b7771c7c4cc6756288d9c7e315dd8c88ca289274fa8b0ce7a96b3762d4b

Contents?: true

Size: 1.01 KB

Versions: 2

Compression:

Stored size: 1.01 KB

Contents

require 'spec_helper'
require 'semantic/core_ext'

# rubocop:disable Metrics/BlockLength
describe 'Core Extensions' do
  context 'String#to_version' do
    before(:each) do
      @test_versions = [
        '1.0.0',
        '12.45.182',
        '0.0.1-pre.1',
        '1.0.1-pre.5+build.123.5',
        '1.1.1+123',
        '0.0.0+hello',
        '1.2.3-1'
      ]

      @bad_versions = [
        'a.b.c',
        '1.a.3',
        'a.3.4',
        '5.2.a',
        'pre3-1.5.3'
      ]
    end

    it 'extends String with a #to_version method' do
      expect('').to respond_to(:to_version)
    end

    it 'converts the String into a Version object' do
      @test_versions.each do |v|
        expect { v.to_version }.to_not raise_error
        expect(v.to_version).to be_a(Semantic::Version)
      end
    end

    it 'raises an error on invalid strings' do
      @bad_versions.each do |v|
        expect { v.to_version }.to raise_error(
          ArgumentError,
          /not a valid SemVer/
        )
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
semantic-1.6.0 spec/core_ext_spec.rb
semantic-1.5.0 spec/core_ext_spec.rb