Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This avoids leaking the class definition.
- Loading branch information
1 parent
be93a4c
commit 3829c48
Showing
1 changed file
with
10 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |