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
Derived/Auto traits on mocks #17
Comments
I feel fairly strongly that Hash, Ord/PartialOrd, and Copy are out. Those are traits that apply to data and mocking data is... weird. My philosophy of mocking is to mock behavior which wouldn't have a concept or Ord/Hash/Copy in my opinion. I feel similarly but less strongly about Eq and PartialEq. Clone is more gray. It also feel like it is meant for data but.... you could clone behavior (i.e., clone your HTTP client). But perhaps for those cases they would not be auto-derived? Default... 🤷♂️ |
I've found cases where I need to have structs that I can |
It's worth pointing out that there is a workaround, albeit a bit naff, for
|
That makes sense. My concern with allowing auto-deriving for let service = UserService::faux();
when!(service.fetch).safe_then(/* do something*/)
let cloned_service = service.clone(); Ideally, I think, I could clear all the stored mocks but I fear that might be confusing. I might need to juggle this in my brain a bit and decide an okay path. Thanks for bringing this up though, and please let me know if you have any preferences or ideas (: |
A downside is that it won't work even if you don't need to use the traits in testing. What I mean is if you don't want to clone explicitly like in your example above, but the library code needs these traits to be implemented. It sure is a problem if the closure is does not implement Clone. The others can maybe just be passed through to the inner object? Maybe require the closure to be clone if the inner object has a clone derive? #[cfg_attr(test, faux::create)]
#[ derive( Debug, Clone, PartialEq, Eq ) ]
//
pub struct WireFormat
{
bytes: Bytes
} This won't compile, but changing it the other way around won't compile either because attribute macros have to be before derive macros. |
I think a step forward, at least to allow things to compile without load-bearing I can always change the behavior (i.e., make it not panic) without it being a breaking change. |
this will be addressed in the next release: 0a0577e I am holding releasing for a bit since I am updating the minimum stable rust version to 1.45.0 |
I have also implemented Closing. If there is need for other derivable traits those can be their own issues. |
What traits should the mocks support deriving?
aa18c66 added support for Sync/Send/Debug.
What about Eq, PartialEq, Ord, PartialOrd, Clone, Copy, Hash, Default?
The text was updated successfully, but these errors were encountered: