# encoding: UTF-8 require 'spec_helper' describe Correios::CEP::Parser do describe '#address' do let(:expected_address) do { address: 'Rua Fernando Amorim', neighborhood: 'Cavaleiro', city: 'Jaboatão dos Guararapes', state: 'PE', zipcode: '54250610', complement: '' } end context 'when address is found' do context 'and does not have complement' do let(:xml) do '' + '' + '' + '' + 'Cavaleiro' + '54250610' + 'Jaboatão dos Guararapes' + '' + '' + 'Rua Fernando Amorim' + '0' + 'PE' + '' + '' + '' + '' end it 'returns address' do expect(subject.address(xml)).to eq expected_address end end context 'and has one complement' do let(:xml) do '' + '' + '' + '' + 'Cavaleiro' + '54250610' + 'Jaboatão dos Guararapes' + 'de 1500 até o fim' + '' + 'Rua Fernando Amorim' + '0' + 'PE' + '' + '' + '' + '' end it 'returns address' do expected_address[:complement] = 'de 1500 até o fim' expect(subject.address(xml)).to eq expected_address end end context 'and has two complements' do let(:xml) do '' + '' + '' + '' + 'Cavaleiro' + '54250610' + 'Jaboatão dos Guararapes' + 'de 1500 até o fim' + '(zona mista)' + 'Rua Fernando Amorim' + '0' + 'PE' + '' + '' + '' + '' end it 'returns address' do expected_address[:complement] = 'de 1500 até o fim (zona mista)' expect(subject.address(xml)).to eq expected_address end end end context 'when address is not found' do let(:xml) do '' + '' + '' + 'soap:Server' + 'CEP NAO ENCONTRADO' + '' + 'CEP NAO ENCONTRADO' + '' + '' + '' + '' end it 'returns empty hash' do expect(subject.address(xml)).to eq({}) end end end end