-
Notifications
You must be signed in to change notification settings - Fork 63
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
Support default implementation #454
Comments
I think you can already achieve what you want by using trait Foo {
fn bar(&self) -> i32;
fn foo(&self) -> i32 {
self.bar() + 1
}
}
mock!{
Foo {}
impl Foo for Foo {
fn bar(&self) -> i32;
}
} Also, if I were to add a new feature for this, I wouldn't use the |
what about detecting if a trait method Then if the user wants, they can simply call the default impl in the expectation for the method let mock = MockSomeTrait::new()
mock.expect_some_method().returning(MockSomeTrait::some_method__default) That way we don't have to have multiple usages of mock!, or no_mock, mock_all can just stash the default under some well-known name. I could see some issues around complicated lifetimes and other things Mockall currently deals with tho. |
No, that wouldn't work. It might work for a few simple cases, but it would be too fragile, because:
|
I would like to be able to use the default implementation of a method. In #94 you had a valid point that every method must be driven by expectations, however maybe a
Expectation::default_fn
can be introduced.This is an example:
What do you think?
The text was updated successfully, but these errors were encountered: