Sha256: 71a7a10467485ab883c4632e8d0a55ac02e363f3366965803bd52e081e403fd6

Contents?: true

Size: 987 Bytes

Versions: 12

Compression:

Stored size: 987 Bytes

Contents

require "spec_helper"

describe CpfValidator do
  before(:each) do
    @validator = CpfValidator.new(attributes: "cpf")
    @mock = double("model")
    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

  subject { @validator }

  context "when Cpf is valid" do
    it "doesn't add errors in model" do
      subject.validate_each(@mock, "cpf", "01233254120")
      expect(@mock.errors.messages).to be_empty
    end
  end

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

  context "when Cpf is invalid" do
    it "adds errors in model" do
      subject.validate_each(@mock, "cpf", "01233254121")
      expect(@mock.errors.messages).to_not be_empty
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
br_documents-0.1.3 spec/cpf_validator_spec.rb
br_documents-0.1.2 spec/cpf_validator_spec.rb
br_documents-0.1.1 spec/cpf_validator_spec.rb
br_documents-0.1.0 spec/cpf_validator_spec.rb
br_documents-0.0.15 spec/cpf_validator_spec.rb
br_documents-0.0.14 spec/cpf_validator_spec.rb
br_documents-0.0.13 spec/cpf_validator_spec.rb
br_documents-0.0.12 spec/cpf_validator_spec.rb
br_documents-0.0.11 spec/cpf_validator_spec.rb
br_documents-0.0.10 spec/cpf_validator_spec.rb
br_documents-0.0.9 spec/cpf_validator_spec.rb
br_documents-0.0.8 spec/cpf_validator_spec.rb