Sha256: 45f9636c1d8342645b9da1597933ac53c9c0c14fe3ab43afe2b7629462937670

Contents?: true

Size: 1.71 KB

Versions: 32

Compression:

Stored size: 1.71 KB

Contents

# frozen_string_literal: true

RSpec.describe Faraday::ClientError do
  describe '.initialize' do
    subject { described_class.new(exception, response) }
    let(:response) { nil }

    context 'with exception only' do
      let(:exception) { RuntimeError.new('test') }

      it { expect(subject.wrapped_exception).to eq(exception) }
      it { expect(subject.response).to be_nil }
      it { expect(subject.message).to eq(exception.message) }
      it { expect(subject.backtrace).to eq(exception.backtrace) }
      it { expect(subject.inspect).to eq('#<Faraday::ClientError wrapped=#<RuntimeError: test>>') }
    end

    context 'with response hash' do
      let(:exception) { { status: 400 } }

      it { expect(subject.wrapped_exception).to be_nil }
      it { expect(subject.response).to eq(exception) }
      it { expect(subject.message).to eq('the server responded with status 400') }
      it { expect(subject.inspect).to eq('#<Faraday::ClientError response={:status=>400}>') }
    end

    context 'with string' do
      let(:exception) { 'custom message' }

      it { expect(subject.wrapped_exception).to be_nil }
      it { expect(subject.response).to be_nil }
      it { expect(subject.message).to eq('custom message') }
      it { expect(subject.inspect).to eq('#<Faraday::ClientError #<Faraday::ClientError: custom message>>') }
    end

    context 'with anything else #to_s' do
      let(:exception) { %w[error1 error2] }

      it { expect(subject.wrapped_exception).to be_nil }
      it { expect(subject.response).to be_nil }
      it { expect(subject.message).to eq('["error1", "error2"]') }
      it { expect(subject.inspect).to eq('#<Faraday::ClientError #<Faraday::ClientError: ["error1", "error2"]>>') }
    end
  end
end

Version data entries

32 entries across 27 versions & 9 rubygems

Version Path
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/faraday-1.2.0/spec/faraday/error_spec.rb
alloy_sdk-0.1.0 vendor/bundle/ruby/3.0.0/gems/faraday-1.0.1/spec/faraday/error_spec.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/tdiary-5.1.5/vendor/bundle/ruby/3.0.0/gems/faraday-1.2.0/spec/faraday/error_spec.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/tdiary-5.1.5/vendor/bundle/ruby/3.0.0/gems/tdiary-5.1.4/vendor/bundle/ruby/2.7.0/gems/faraday-1.1.0/spec/faraday/error_spec.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/tdiary-5.1.5/vendor/bundle/ruby/3.0.0/gems/faraday-1.1.0/spec/faraday/error_spec.rb
tdiary-5.1.5 vendor/bundle/ruby/3.0.0/gems/tdiary-5.1.4/vendor/bundle/ruby/2.7.0/gems/faraday-1.1.0/spec/faraday/error_spec.rb
tdiary-5.1.5 vendor/bundle/ruby/3.0.0/gems/faraday-1.1.0/spec/faraday/error_spec.rb
tdiary-5.1.5 vendor/bundle/ruby/3.0.0/gems/faraday-1.2.0/spec/faraday/error_spec.rb
faraday-1.2.0 spec/faraday/error_spec.rb
tdiary-5.1.4 vendor/bundle/ruby/2.7.0/gems/faraday-1.1.0/spec/faraday/error_spec.rb
passbase-1.2.0 vendor/bundle/ruby/2.7.0/gems/faraday-1.1.0/spec/faraday/error_spec.rb
passbase-1.1.0 vendor/bundle/ruby/2.7.0/gems/faraday-1.1.0/spec/faraday/error_spec.rb
passbase-1.0.3 vendor/bundle/ruby/2.7.0/gems/faraday-1.1.0/spec/faraday/error_spec.rb
faraday-1.1.0 spec/faraday/error_spec.rb
passbase-1.0.2 vendor/bundle/ruby/2.7.0/gems/faraday-1.0.1/spec/faraday/error_spec.rb
passbase-1.0.1 vendor/bundle/ruby/2.7.0/gems/faraday-1.0.1/spec/faraday/error_spec.rb
passbase-1.0.0 vendor/bundle/ruby/2.7.0/gems/faraday-1.0.1/spec/faraday/error_spec.rb
logstash-filter-csharp-0.2.1 vendor/bundle/jruby/2.5.0/gems/faraday-1.0.1/spec/faraday/error_spec.rb
logstash-filter-csharp-0.2.0 vendor/bundle/jruby/2.5.0/gems/faraday-1.0.1/spec/faraday/error_spec.rb
tdiary-5.1.3 vendor/bundle/ruby/2.6.0/gems/faraday-1.0.1/spec/faraday/error_spec.rb