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

Mocking a return type without Clone #15

Open
plauche opened this issue Feb 28, 2018 · 2 comments
Open

Mocking a return type without Clone #15

plauche opened this issue Feb 28, 2018 · 2 comments

Comments

@plauche
Copy link

plauche commented Feb 28, 2018

I'm looking at using this crate for testing but have run into a bit of a road block. My trait is using the Error return type from the failure crate. Unfortunately it looks like this particular implementation of Error does not implement std::clone::Clone, which appears to be a requirement imposed by double.

Any thoughts on how to work around this? I don't think I can implement Clone myself on failure::Error since I'm using it as an external crate.

@luizdepra
Copy link

I'm stuck with a similar problem.

I need to mock Read trait. The read method receives a &mut [u8] and returns Result<usize, io::Error>, both not clonable.

The Mock documentation states:

/// Used for tracking function call arguments and specifying a predetermined
/// return value or mock function.
///
/// See the crate documentation for more substantial examples, including some
/// that demonstrate how to use `Mock` for methods that have multiple arguments
/// as well as methods with argument or return types that do not implement
/// `Clone`.

But I was unable to find anything about using double mocks with not clonable parameters and returns, only with missing default trait.

This is really possible?

@luizdepra
Copy link

I solved my problem.

There is an example showing how to handler io::Return here. An for &mut [u8], I converted it to Vec<u8>, but probably Box<[u8]> should work too.

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

2 participants