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

Would you be open to me contributing a #clear method in Faraday::Adapter::Test::Stubs? #1570

Open
Decker87 opened this issue Jun 24, 2024 · 1 comment

Comments

@Decker87
Copy link

Hey folks! I've recently stumbled upon a challenge similar to what's documented in #1041. That is, my application uses singleton classes with memoized methods to "cache" a Faraday instance. This works great in production but my tests will suffer from being unable to stub out different behaviors of the same URL/action in subsequent test examples.

I'm comfortable enough with the test adapter and stub code, and believe I could implement a method to clear the stubs reasonably well. Before I go off and spend time on that, could the maintainers of the project weigh in on whether such a thing would be in-line with the maintainers' goals and design philosophy?

Thanks in advance!

@iMacTia
Copy link
Member

iMacTia commented Jun 25, 2024

Hi @Decker87 and thank you so much for being considerate and asking before jumping into this.

When it comes to application code or API clients, my recommendation has always been to test using Webmock or VCR, as the test adapter was mostly conceived to help writing tests for Faraday middleware.

That said, there are multiple people who prefer using the test adapter for writing tests, and I completely agree the current suggestion of setting Faraday.default_connection = nil to reset stubs sounds more of a hack 🤔

I'd be open to introducing a clear method on Faraday::Adapter::Test::Stubs as you suggested and update the docs to suggest using that instead 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants