Sha256: a396637722a16e89cf3431ce0380234de13281a4573ea134011f6b0b2a00ee68

Contents?: true

Size: 1.91 KB

Versions: 18

Compression:

Stored size: 1.91 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

  context 'does not raise exception if ignored errors is set to nil' do
    before { stub_request(:get, 'http://local.ch').to_return(status: 404) }

    it "does not raise an error when ignored errors is set to array with nil" do
      expect {
        LHC.get('http://local.ch', ignored_errors: [nil])
      }.to raise_error(LHC::NotFound)
    end

    it "does not raise an error when ignored errors is set to nil" do
      expect {
        LHC.get('http://local.ch', ignored_errors: nil)
      }.to raise_error(LHC::NotFound)
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
lhc-11.1.1 spec/request/ignore_errors_spec.rb
lhc-11.1.0 spec/request/ignore_errors_spec.rb
lhc-11.0.2 spec/request/ignore_errors_spec.rb
lhc-11.0.1 spec/request/ignore_errors_spec.rb
lhc-11.0.0 spec/request/ignore_errors_spec.rb
lhc-10.5.4 spec/request/ignore_errors_spec.rb
lhc-10.5.3 spec/request/ignore_errors_spec.rb
lhc-10.5.2 spec/request/ignore_errors_spec.rb
lhc-10.5.1 spec/request/ignore_errors_spec.rb
lhc-10.5.0 spec/request/ignore_errors_spec.rb
lhc-10.4.3 spec/request/ignore_errors_spec.rb
lhc-10.4.2 spec/request/ignore_errors_spec.rb
lhc-10.4.1 spec/request/ignore_errors_spec.rb
lhc-10.4.0 spec/request/ignore_errors_spec.rb
lhc-10.3.0 spec/request/ignore_errors_spec.rb
lhc-10.2.1 spec/request/ignore_errors_spec.rb
lhc-10.2.0 spec/request/ignore_errors_spec.rb
lhc-10.1.8 spec/request/ignore_errors_spec.rb