mirror of
https://github.com/lostisland/faraday.git
synced 2025-10-04 00:02:03 -04:00
Refactor test
This avoids leaking the class definition.
This commit is contained in:
parent
85dfdf824c
commit
46f3b678f0
@ -1,30 +1,31 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class CustomMiddleware < Faraday::Middleware
|
||||
end
|
||||
|
||||
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: CustomMiddleware)
|
||||
expect(dummy.lookup_middleware(:custom)).to eq(CustomMiddleware)
|
||||
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(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(CustomMiddleware)
|
||||
expect(dummy.lookup_middleware(:custom)).to eq(custom_middleware_klass)
|
||||
end
|
||||
|
||||
it 'allows to register with Proc' do
|
||||
dummy.register_middleware(custom: -> { CustomMiddleware })
|
||||
expect(dummy.lookup_middleware(:custom)).to eq(CustomMiddleware)
|
||||
dummy.register_middleware(custom: -> { custom_middleware_klass })
|
||||
expect(dummy.lookup_middleware(:custom)).to eq(custom_middleware_klass)
|
||||
end
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user