-
Notifications
You must be signed in to change notification settings - Fork 64
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
automock fails for method taking Option<&u32> #571
Comments
Have you tried adding a lifetime parameter, like this?
|
I can confirm this can be solved by desugaring the lifetimes as mentioned above. It would be nice if the automock macro can do this automatically. |
What if I want to mock a trait from another crate that I cannot simply add the lifetimes to? |
Then you'll have to manually write a mock function. You can wrap a Mockall function if you want, in order to get access to Mockall's expectations. |
Yes as noted, this can be manually solved even if the trait is from another crate, and that the failure appears to be general for pub trait SomeTrait {
fn insert(&self, description: Option<&str>);
} The natural solution using the mock! {
pub Platform {}
impl SomeTrait for Platform {
fn insert(&self, description: Option<&str>);
}
} The workaround will require creating the mocked mock! {
pub Platform {
pub fn some_trait_insert<'a>(&self, description: Option<&'a str>);
}
}
impl SomeTrait for MockPlatform {
fn insert(&self, description: Option<&str>) {
self.some_trait_insert(description)
}
} But yes, it would be great if this workaround isn't needed, or an error message be generated to recommend a workaround like so. |
Trying to mock the following trait fails:
with a confusing error message:
If there is some reason this can't be supported, the error message should at least be more helpful in explaining why.
The text was updated successfully, but these errors were encountered: