Sha256: c62ed23b8adc4125c763bb47071bacf287cf9b513cb8b0f36d57ff64633d3308

Contents?: true

Size: 1001 Bytes

Versions: 3

Compression:

Stored size: 1001 Bytes

Contents

# frozen_string_literal: true
RSpec.describe FinAppsCore::Middleware::RaiseError do
  let(:fake_app) { proc {|env| env } }
  Env = Struct.new(:status, :response_headers, :body)

  describe '#on_complete' do
    subject { FinAppsCore::Middleware::RaiseError.new(fake_app) }

    context 'for successful requests' do
      let(:env) { Env.new(200) }
      it { expect { subject.on_complete(env) }.not_to raise_error }
    end
    context 'for client errors' do
      let(:env) { Env.new(401, {}, '{"messages":["Invalid User Identifier or Credentials"]}') }
      error_message = 'the server responded with status 401'
      it { expect { subject.on_complete(env) }.to raise_error(Faraday::Error::ClientError, error_message) }
    end
    context 'for connection failed error' do
      let(:env) { Env.new(407) }
      error_message = '407 "Proxy Authentication Required"'
      it { expect { subject.on_complete(env) }.to raise_error(Faraday::Error::ConnectionFailed, error_message) }
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
finapps_core-2.0.4 spec/middleware/response/raise_error_spec.rb
finapps_core-2.0.3 spec/middleware/response/raise_error_spec.rb
finapps_core-2.0.2 spec/middleware/response/raise_error_spec.rb