Sha256: 477bda03d612b28d337bb4451ad5b5440f2905e412392d838cec4196295cfde2

Contents?: true

Size: 1.35 KB

Versions: 28

Compression:

Stored size: 1.35 KB

Contents

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

28 entries across 28 versions & 1 rubygems

Version Path
lhc-9.2.0 spec/request/ignore_errors_spec.rb
lhc-9.1.2 spec/request/ignore_errors_spec.rb
lhc-9.1.2.pre spec/request/ignore_errors_spec.rb
lhc-9.1.1 spec/request/ignore_errors_spec.rb
lhc-8.1.1 spec/request/ignore_errors_spec.rb
lhc-9.1.0 spec/request/ignore_errors_spec.rb
lhc-9.0.0 spec/request/ignore_errors_spec.rb
lhc-8.1.0 spec/request/ignore_errors_spec.rb
lhc-8.0.0 spec/request/ignore_errors_spec.rb
lhc-7.3.3 spec/request/ignore_errors_spec.rb
lhc-7.3.2 spec/request/ignore_errors_spec.rb
lhc-7.3.1 spec/request/ignore_errors_spec.rb
lhc-7.3.0 spec/request/ignore_errors_spec.rb
lhc-7.2.0 spec/request/ignore_errors_spec.rb
lhc-7.1.0 spec/request/ignore_errors_spec.rb
lhc-7.0.1 spec/request/ignore_errors_spec.rb
lhc-7.0.0 spec/request/ignore_errors_spec.rb
lhc-7.0.0.beta1 spec/request/ignore_errors_spec.rb
lhc-6.7.2 spec/request/ignore_errors_spec.rb
lhc-6.7.1 spec/request/ignore_errors_spec.rb