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

How to mock external traits? #26

Open
vigenere23 opened this issue Nov 17, 2022 · 0 comments
Open

How to mock external traits? #26

vigenere23 opened this issue Nov 17, 2022 · 0 comments

Comments

@vigenere23
Copy link

vigenere23 commented Nov 17, 2022

Let's say I use an external library that provides an HTTP Client, like a trait SpotifyClient with some basic implementations. I want to mock the responses of the client and verify the requests made in order to test some logic that my code does (as a large integration test).

Currently, from the examples, you can only add mocks using the #[mock_it] or #[cfg_attr(mock_it)] directives, which cannot be added on external code...

Is there any other utilities I can use from this library to overcome this issue? Because I really like the simplicity and directness of the API 😄


Would the solution be to create an implementation classe, like struct FakeSpotifyClient, that implements the SpotifyClient trait but with todo!()s, and add the #[mock_it] directive to it?

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

No branches or pull requests

1 participant