diff --git a/lib/faraday/adapter/test.rb b/lib/faraday/adapter/test.rb index c637d139a..f5c82c7ef 100644 --- a/lib/faraday/adapter/test.rb +++ b/lib/faraday/adapter/test.rb @@ -255,8 +255,9 @@ def to_s end end - def initialize(app, stubs = nil, &block) + def initialize(app, stubs_or_options = nil, &block) super(app) + stubs = stubs_or_options.is_a?(Hash) ? stubs_or_options[:stubs] : stubs_or_options @stubs = stubs || Stubs.new configure(&block) if block end diff --git a/spec/faraday/adapter/test_spec.rb b/spec/faraday/adapter/test_spec.rb index 117bb7899..cabc2db34 100644 --- a/spec/faraday/adapter/test_spec.rb +++ b/spec/faraday/adapter/test_spec.rb @@ -41,6 +41,14 @@ let(:response) { connection.get('/hello') } + it 'can receive stubs as a positional argument' do + expect(described_class.new(dummy_rack_app, stubs).stubs).to be stubs + end + + it 'can receive stubs as a keyword argument' do + expect(described_class.new(dummy_rack_app, stubs: stubs).stubs).to be stubs + end + context 'with simple path sets status' do subject { response.status } diff --git a/spec/support/helper_methods.rb b/spec/support/helper_methods.rb index 0f5d4f5a5..48770d4d0 100644 --- a/spec/support/helper_methods.rb +++ b/spec/support/helper_methods.rb @@ -92,5 +92,9 @@ def big_string kb = 1024 (32..126).map(&:chr).cycle.take(50 * kb).join end + + def dummy_rack_app + ->(_env) { [200, { 'content-type' => 'text/plain' }, ['Hello World']] } + end end end