Sha256: 5255d8ff5696c90c05cb2febc01f032dd7458a90f4122425b51395ff679bed25

Contents?: true

Size: 1.38 KB

Versions: 4

Compression:

Stored size: 1.38 KB

Contents

# frozen_string_literal: true

require 'rails_helper'

describe LHC::Request do
  context 'ignoring LHC::NotFound' do
    let(:response) { LHC.get('http://local.ch', ignored_errors: [LHC::NotFound]) }

    before { stub_request(:get, 'http://local.ch').to_return(status: 404) }

    it 'does not raise an error' do
      expect { response }.not_to raise_error
    end

    it 'body is nil' do
      expect(response.body).to eq nil
    end

    it 'data is nil' do
      expect(response.data).to eq nil
    end

    it 'does raise an error for 500' do
      stub_request(:get, 'http://local.ch').to_return(status: 500)
      expect { response }.to raise_error LHC::InternalServerError
    end

    it 'provides the information if the error was ignored' do
      expect(response.error_ignored?).to eq true
      expect(response.request.error_ignored?).to eq true
    end
  end

  context 'inheritance when ignoring errors' do
    before { stub_request(:get, 'http://local.ch').to_return(status: 404) }

    it "does not raise an error when it's a subclass of the ignored error" do
      expect {
        LHC.get('http://local.ch', ignored_errors: [LHC::Error])
      }.not_to raise_error
    end

    it "does raise an error if it's not a subclass of the ignored error" do
      expect {
        LHC.get('http://local.ch', ignored_errors: [ArgumentError])
      }.to raise_error(LHC::NotFound)
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
lhc-10.1.7 spec/request/ignore_errors_spec.rb
lhc-10.1.6 spec/request/ignore_errors_spec.rb
lhc-10.1.5 spec/request/ignore_errors_spec.rb
lhc-10.1.3 spec/request/ignore_errors_spec.rb