Sha256: 9a7d85cb6595e555754c5d93f0bced044d196be4ff6fa1e60838997a843afd90

Contents?: true

Size: 1.06 KB

Versions: 1

Compression:

Stored size: 1.06 KB

Contents

require "spec_helper"

describe Correios::CEP::AddressFinder do
  context "with invalid cep" do
    it "should raise ArgumentError when cep is nil" do
      expect{ subject.get(nil) }.to raise_error(ArgumentError)
    end

    it "should raise ArgumentError when cep does not have a valid format" do
      expect{ subject.get("542506-10") }.to raise_error(ArgumentError)
    end
  end

  context "with valid cep" do
    let(:cep) { '54250610' }
    let(:web_service_response) { "<end>Rua Fernando Amorim</end>" }
    let(:address) { { address: "Rua Fernando Amorim" } }

    before do
      allow_any_instance_of(Correios::CEP::WebService).to receive(:request).with(cep){ web_service_response }
      allow_any_instance_of(Correios::CEP::Parser).to receive(:address).with(web_service_response){ address }
    end

    describe "#get" do
      it "returns address" do
        expect(subject.get(cep)).to eql address
      end
    end

    describe ".get" do
      it "returns address" do
        expect(Correios::CEP::AddressFinder.get(cep)).to eql address
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
correios-cep-0.5.0 spec/correios/cep/address_finder_spec.rb