Sha256: f0d77e9efe7cebfc0c4d35cd74bd4206e7cd830ccbc1ad847e51157e89ac7bd7

Contents?: true

Size: 1.22 KB

Versions: 1

Compression:

Stored size: 1.22 KB

Contents

require 'spec_helper'

describe BrDocuments::Gtin do
  describe '#valid?' do
    context 'when the checksum is valid' do
      context 'when the GTIN has 8 digits' do
        subject { described_class.new('12345618') }

        it { is_expected.to be_valid }
      end

      context 'when the GTIN has 12 digits' do
        subject { described_class.new('114567854874') }

        it { is_expected.to be_valid }
      end

      context 'when the GTIN has 13 digits' do
        subject { described_class.new('1145678548719') }

        it { is_expected.to be_valid }
      end

      context 'when the GTIN has 14 digits' do
        subject { described_class.new('1234567891125') }

        it { is_expected.to be_valid }
      end

      context 'when the final digit is zero' do
        subject { described_class.new('7898417964120') }

        it { is_expected.to be_valid }
      end

      context 'when the number of digits is different of 8, 13 or 14' do
        subject { described_class.new('12345678901234560') }

        it { is_expected.to_not be_valid }
      end
    end

    context 'when the checksum is invald' do
      subject { described_class.new('1145678548712') }

      it { is_expected.to_not be_valid }
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
br_documents-0.2.0 spec/gtin/gtin_spec.rb