Sha256: 6abc9c765172dd9a6c3873d40557d012d512ffddb53102341efab6c955f97f30

Contents?: true

Size: 1.91 KB

Versions: 80

Compression:

Stored size: 1.91 KB

Contents

# frozen_string_literal: true

RSpec.describe Faraday::Request::Instrumentation do
  class FakeInstrumenter
    attr_reader :instrumentations

    def initialize
      @instrumentations = []
    end

    def instrument(name, env)
      @instrumentations << [name, env]
      yield
    end
  end

  let(:config) { {} }
  let(:options) { Faraday::Request::Instrumentation::Options.from config }
  let(:instrumenter) { FakeInstrumenter.new }
  let(:conn) do
    Faraday.new do |f|
      f.request :instrumentation, config.merge(instrumenter: instrumenter)
      f.adapter :test do |stub|
        stub.get '/' do
          [200, {}, 'ok']
        end
      end
    end
  end

  it { expect(options.name).to eq('request.faraday') }
  it 'defaults to ActiveSupport::Notifications' do
    begin
      res = options.instrumenter
    rescue NameError => e
      expect(e.to_s).to match('ActiveSupport')
    else
      expect(res).to eq(ActiveSupport::Notifications)
    end
  end

  it 'instruments with default name' do
    expect(instrumenter.instrumentations.size).to eq(0)

    res = conn.get '/'
    expect(res.body).to eq('ok')
    expect(instrumenter.instrumentations.size).to eq(1)

    name, env = instrumenter.instrumentations.first
    expect(name).to eq('request.faraday')
    expect(env[:url].path).to eq('/')
  end

  context 'with custom name' do
    let(:config) { { name: 'custom' } }

    it { expect(options.name).to eq('custom') }
    it 'instruments with custom name' do
      expect(instrumenter.instrumentations.size).to eq(0)

      res = conn.get '/'
      expect(res.body).to eq('ok')
      expect(instrumenter.instrumentations.size).to eq(1)

      name, env = instrumenter.instrumentations.first
      expect(name).to eq('custom')
      expect(env[:url].path).to eq('/')
    end
  end

  context 'with custom instrumenter' do
    let(:config) { { instrumenter: :custom } }

    it { expect(options.instrumenter).to eq(:custom) }
  end
end

Version data entries

80 entries across 67 versions & 16 rubygems

Version Path
avalara_sdk-24.12.2 vendor/bundle/ruby/2.7.0/gems/faraday-1.10.4/spec/faraday/request/instrumentation_spec.rb
avalara_sdk-24.12.1 vendor/bundle/ruby/2.7.0/gems/faraday-1.10.4/spec/faraday/request/instrumentation_spec.rb
avalara_sdk-24.12.0 vendor/bundle/ruby/2.7.0/gems/faraday-1.10.4/spec/faraday/request/instrumentation_spec.rb
minato_ruby_api_client-0.2.2 vendor/bundle/ruby/3.2.0/gems/faraday-1.10.3/spec/faraday/request/instrumentation_spec.rb
faraday-1.10.4 spec/faraday/request/instrumentation_spec.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/faraday-1.2.0/spec/faraday/request/instrumentation_spec.rb
avalara_sdk-24.2.29 vendor/bundle/ruby/2.7.0/gems/faraday-1.10.3/spec/faraday/request/instrumentation_spec.rb
faraday-1.10.3 spec/faraday/request/instrumentation_spec.rb
faraday-1.10.2 spec/faraday/request/instrumentation_spec.rb
faraday-1.10.1 spec/faraday/request/instrumentation_spec.rb
alloy_sdk-0.1.0 vendor/bundle/ruby/3.0.0/gems/faraday-1.0.1/spec/faraday/request/instrumentation_spec.rb
op_connect-0.1.2 vendor/bundle/ruby/3.1.0/gems/faraday-1.10.0/spec/faraday/request/instrumentation_spec.rb
plaid-14.13.0 vendor/bundle/ruby/3.0.0/gems/faraday-1.10.0/spec/faraday/request/instrumentation_spec.rb
tdiary-5.2.1 vendor/bundle/ruby/3.1.0/gems/faraday-1.10.0/spec/faraday/request/instrumentation_spec.rb
faraday-1.10.0 spec/faraday/request/instrumentation_spec.rb
plaid-14.12.1 vendor/bundle/ruby/3.0.0/gems/faraday-1.9.3/spec/faraday/request/instrumentation_spec.rb
plaid-14.12.0 vendor/bundle/ruby/2.6.0/gems/faraday-1.9.3/spec/faraday/request/instrumentation_spec.rb
plaid-14.12.0 vendor/bundle/ruby/2.6.0/gems/faraday-1.8.0/spec/faraday/request/instrumentation_spec.rb
plaid-14.11.1 vendor/bundle/ruby/2.6.0/gems/faraday-1.9.3/spec/faraday/request/instrumentation_spec.rb
faraday-1.9.3 spec/faraday/request/instrumentation_spec.rb