Sha256: de6ced80e9c3ebb3da780096e58f488be88dd579a4041891f5570967e5b84a74

Contents?: true

Size: 1.54 KB

Versions: 5

Compression:

Stored size: 1.54 KB

Contents

require 'spec_helper'

describe BrDocuments::CnpjCpf::Cpf do
  describe '#formatted' do
    it 'returns a formatted number' do
      cpf = described_class.new('11144477735')
      expect(cpf.formatted).to eq '111.444.777-35'
    end

    context 'when is invalid' do
      it 'returns an empty string' do
        cpf = described_class.new('123')
        expect(cpf.formatted).to eq ''
      end
    end
  end

  it 'is invalid with malformed number' do
    ['111.126.491.07', '482.261.15-663', '111444.777-35'].each do |number|
      cpf = described_class.new(number)
      expect(cpf).not_to be_valid
    end
  end

  it 'is invalid with a number longer than 11' do
    ['045.769.421-150', '308514217766'].each do |number|
      cpf = described_class.new(number)
      expect(cpf).not_to be_valid
    end
  end

  it 'is invalid with a number shorter than 11' do
    ['111.444.777-3', '1234567890'].each do |number|
      cpf = described_class.new(number)
      expect(cpf).not_to be_valid
    end
  end

  it 'is invalid with a sequence of the same number' do
    ['111.111.111-11', '22222222222'].each do |number|
      cpf = described_class.new(number)
      expect(cpf).not_to be_valid
    end
  end

  it 'is invalid with invalid check number' do
    ['111.111.111-22', '2222222233'].each do |number|
      cpf = described_class.new(number)
      expect(cpf).not_to be_valid
    end
  end

  it 'is valid with correct number' do
    ['111.444.777-35', '01233254120'].each do |number|
      cpf = described_class.new(number)
      expect(cpf).to be_valid
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
br_documents-0.2.5 spec/br_documents/cnpj_cpf/cpf_spec.rb
br_documents-0.2.4 spec/br_documents/cnpj_cpf/cpf_spec.rb
br_documents-0.2.3 spec/br_documents/cnpj_cpf/cpf_spec.rb
br_documents-0.2.2 spec/br_documents/cnpj_cpf/cpf_spec.rb
br_documents-0.2.1 spec/br_documents/cnpj_cpf/cpf_spec.rb