Sha256: 45f85a7f615a7307bf9b455db8a4297da58b131a489a7fe262aa98cd77512ffb

Contents?: true

Size: 986 Bytes

Versions: 5

Compression:

Stored size: 986 Bytes

Contents

require 'spec_helper'

describe SuframaValidator do
  subject { described_class.new(attributes: 'suframa') }

  let(:mock) { instance_double('mode') }

  before do
    allow(mock).to receive(:errors).and_return([])
    allow(mock.errors).to receive(:messages).and_return({})
    allow(mock.errors).to receive(:add) do |attribute, error|
      mock.errors.messages[attribute] = [error]
    end
  end

  context 'when SUFRAMA is valid' do
    it "doesn't add errors in model" do
      subject.validate_each(mock, 'suframa', '600215105')
      expect(mock.errors.messages).to be_empty
    end
  end

  context 'when SUFRAMA is blank' do
    it "doesn't add errors in model" do
      subject.validate_each(mock, 'suframa', '')
      expect(mock.errors.messages).to be_empty
    end
  end

  context 'when SUFRAMA is invalid' do
    it 'adds errors in model' do
      subject.validate_each(mock, 'suframa', '01233254121')
      expect(mock.errors.messages).not_to be_empty
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

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