double icon indicating copy to clipboard operation
double copied to clipboard

Mocking a return type without Clone

Open plauche opened this issue 7 years ago • 2 comments

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.

plauche avatar Feb 28 '18 23:02 plauche

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 avatar Aug 07 '18 00:08 luizdepra

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.

luizdepra avatar Aug 09 '18 13:08 luizdepra