Sha256: dcf32b01b87fd33c1ea7fa4158d043c1d70cb55f5f2e4058c44547d45953ac88

Contents?: true

Size: 1.7 KB

Versions: 35

Compression:

Stored size: 1.7 KB

Contents

# frozen_string_literal: true

RSpec.describe Faraday::Middleware do
  subject { described_class.new(app) }
  let(:app) { double }

  describe 'options' do
    context 'when options are passed to the middleware' do
      subject { described_class.new(app, options) }
      let(:options) { { field: 'value' } }

      it 'accepts options when initialized' do
        expect(subject.options[:field]).to eq('value')
      end
    end
  end

  describe '#on_request' do
    subject do
      Class.new(described_class) do
        def on_request(env)
          # do nothing
        end
      end.new(app)
    end

    it 'is called by #call' do
      expect(app).to receive(:call).and_return(app)
      expect(app).to receive(:on_complete)
      is_expected.to receive(:call).and_call_original
      is_expected.to receive(:on_request)
      subject.call(double)
    end
  end

  describe '#on_error' do
    subject do
      Class.new(described_class) do
        def on_error(error)
          # do nothing
        end
      end.new(app)
    end

    it 'is called by #call' do
      expect(app).to receive(:call).and_raise(Faraday::ConnectionFailed)
      is_expected.to receive(:call).and_call_original
      is_expected.to receive(:on_error)

      expect { subject.call(double) }.to raise_error(Faraday::ConnectionFailed)
    end
  end

  describe '#close' do
    context "with app that doesn't support \#close" do
      it 'should issue warning' do
        is_expected.to receive(:warn)
        subject.close
      end
    end

    context "with app that supports \#close" do
      it 'should issue warning' do
        expect(app).to receive(:close)
        is_expected.to_not receive(:warn)
        subject.close
      end
    end
  end
end

Version data entries

35 entries across 35 versions & 3 rubygems

Version Path
moneykit-0.1.0.alpha.1 vendor/bundle/ruby/3.2.0/gems/faraday-2.7.12/spec/faraday/middleware_spec.rb
faraday-2.7.12 spec/faraday/middleware_spec.rb
faraday-2.7.11 spec/faraday/middleware_spec.rb
faraday-2.7.10 spec/faraday/middleware_spec.rb
faraday-2.7.9 spec/faraday/middleware_spec.rb
faraday-2.7.8 spec/faraday/middleware_spec.rb
faraday-2.7.7 spec/faraday/middleware_spec.rb
faraday-2.7.6 spec/faraday/middleware_spec.rb
faraday-2.7.5 spec/faraday/middleware_spec.rb
fluent-plugin-google-cloud-logging-on-prem-0.1.0 vendor/ruby/3.1.0/gems/faraday-2.7.4/spec/faraday/middleware_spec.rb
faraday-2.7.4 spec/faraday/middleware_spec.rb
faraday-2.7.3 spec/faraday/middleware_spec.rb
faraday-2.7.2 spec/faraday/middleware_spec.rb
faraday-2.7.1 spec/faraday/middleware_spec.rb
faraday-2.7.0 spec/faraday/middleware_spec.rb