Sha256: 3492dd78a2f659d9326bc97db978cb0b1b8a7534dc4de9074965c05a8906e664

Contents?: true

Size: 803 Bytes

Versions: 2

Compression:

Stored size: 803 Bytes

Contents

RSpec.describe ViaCep::Service do
  it 'should have a base URL' do
    expect(ViaCep::Service::BASE_URL).not_to be_empty
  end

  describe '.fetch' do
    context 'when a small timeout is specified' do
      it 'raises Timeout::Error' do
        expect { ViaCep::Service.fetch('80210130', 0.001) }.
          to raise_error(Timeout::Error)
      end
    end

    context 'when a suficient timeout is specified' do
      subject(:response) { ViaCep::Service.fetch('80210130', 25) }

      it 'returns the response' do
        expect(response).not_to be_empty
      end
    end

    context 'when a invalid CEP is passed' do
      it 'raises ViaCep::ApiRequestError' do
        expect { ViaCep::Service.fetch('000000', nil) }.
          to raise_error(ViaCep::ApiRequestError)
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
viacep-2.0.2 spec/service_spec.rb
viacep-2.0.1 spec/service_spec.rb