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.15 vendor/bundle/ruby/3.2.0/gems/faraday-2.7.12/spec/faraday/middleware_spec.rb
moneykit-0.1.14 vendor/bundle/ruby/3.2.0/gems/faraday-2.7.12/spec/faraday/middleware_spec.rb
moneykit-0.1.13 vendor/bundle/ruby/3.2.0/gems/faraday-2.7.12/spec/faraday/middleware_spec.rb
moneykit-0.1.12 vendor/bundle/ruby/3.2.0/gems/faraday-2.7.12/spec/faraday/middleware_spec.rb
moneykit-0.1.11 vendor/bundle/ruby/3.2.0/gems/faraday-2.7.12/spec/faraday/middleware_spec.rb
faraday-2.9.2 spec/faraday/middleware_spec.rb
faraday-2.9.1 spec/faraday/middleware_spec.rb
moneykit-0.1.10 vendor/bundle/ruby/3.2.0/gems/faraday-2.7.12/spec/faraday/middleware_spec.rb
moneykit-0.1.9 vendor/bundle/ruby/3.2.0/gems/faraday-2.7.12/spec/faraday/middleware_spec.rb
moneykit-0.1.6 vendor/bundle/ruby/3.2.0/gems/faraday-2.7.12/spec/faraday/middleware_spec.rb
moneykit-0.1.5 vendor/bundle/ruby/3.2.0/gems/faraday-2.7.12/spec/faraday/middleware_spec.rb
moneykit-0.1.4 vendor/bundle/ruby/3.2.0/gems/faraday-2.7.12/spec/faraday/middleware_spec.rb
moneykit-0.1.3 vendor/bundle/ruby/3.2.0/gems/faraday-2.7.12/spec/faraday/middleware_spec.rb
faraday-2.9.0 spec/faraday/middleware_spec.rb
faraday-2.8.1 spec/faraday/middleware_spec.rb
moneykit-0.1.2 vendor/bundle/ruby/3.2.0/gems/faraday-2.7.12/spec/faraday/middleware_spec.rb
faraday-2.8.0 spec/faraday/middleware_spec.rb
moneykit-0.1.1 vendor/bundle/ruby/3.2.0/gems/faraday-2.7.12/spec/faraday/middleware_spec.rb
moneykit-0.1.0 vendor/bundle/ruby/3.2.0/gems/faraday-2.7.12/spec/faraday/middleware_spec.rb
moneykit-0.1.0.alpha.2 vendor/bundle/ruby/3.2.0/gems/faraday-2.7.12/spec/faraday/middleware_spec.rb