File: middleware_registry_spec.rb

package info (click to toggle)
ruby-faraday 2.14.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,008 kB
  • sloc: ruby: 6,509; sh: 10; makefile: 8
file content (31 lines) | stat: -rw-r--r-- 1,087 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# frozen_string_literal: true

RSpec.describe Faraday::MiddlewareRegistry do
  before do
    stub_const('CustomMiddleware', custom_middleware_klass)
  end
  let(:custom_middleware_klass) { Class.new(Faraday::Middleware) }
  let(:dummy) { Class.new { extend Faraday::MiddlewareRegistry } }

  after { dummy.unregister_middleware(:custom) }

  it 'allows to register with constant' do
    dummy.register_middleware(custom: custom_middleware_klass)
    expect(dummy.lookup_middleware(:custom)).to eq(custom_middleware_klass)
  end

  it 'allows to register with symbol' do
    dummy.register_middleware(custom: :CustomMiddleware)
    expect(dummy.lookup_middleware(:custom)).to eq(custom_middleware_klass)
  end

  it 'allows to register with string' do
    dummy.register_middleware(custom: 'CustomMiddleware')
    expect(dummy.lookup_middleware(:custom)).to eq(custom_middleware_klass)
  end

  it 'allows to register with Proc' do
    dummy.register_middleware(custom: -> { custom_middleware_klass })
    expect(dummy.lookup_middleware(:custom)).to eq(custom_middleware_klass)
  end
end