Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Test adapter constructor able to receive stubs as a keyword argument #1597

Closed
wants to merge 1 commit into from

Conversation

alanoliveira
Copy link

Description

This PR makes Test adapter constructor able to receive stubs as a keyword argument.

Details

The Test adapter expects to receive the stubs as a positional argument. It is great because in the most of cases we want to use it like

Faraday.new do |builder|
  builder.adapter :test, stubs
end

But it is not compatible with Faraday.default_adapter_options as it must to be a hash.

def build
raise_if_locked
block_given? ? yield(self) : request(:url_encoded)
adapter(Faraday.default_adapter, **Faraday.default_adapter_options) unless @adapter
end

So we can't do something like

RSpec.configure do |config|
  config.before :context, :stub_api do
    Faraday.default_adapter = :test
    Faraday.default_adapter_options = # must be a hash
  end
end

I changed the Test adapter constructor to also accept positional argument instead of change RackBuilder::Handler#builder method because the way to pass options to adapters is using hash.

@alanoliveira alanoliveira closed this by deleting the head repository Nov 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant