-
Notifications
You must be signed in to change notification settings - Fork 78
Open
Labels
questionUsage questionUsage question
Description
Hi!
First of all - thank you for your crate, really helpful and easy to use.
I want the ability to write tests like this:
struct Foo;
impl Foo {
pub fn work(&self) { self.extra_work(); }
fn extra_work(&self) {}
}
#[cfg(test)]
mod tests {
fn work_calls_extra_work() {
// Arrange
let foo = FooMock::new();
// Act
foo.work();
// Assert
foo.expect_extra_work.times(1);
}
}However this will not currently work because foo.work() would call mock's implementation that does nothing. To fix it I imagine we'd need something like this:
fn work_calls_extra_work() {
// Arrange
let foo = FooMock::new();
foo.work().call_impl(); // tell mockall that this method must call real method's implementation
// Act
foo.work();
// Assert
foo.expect_extra_work.times(1);
}Is it possible to add something like that? I would gladly help to implement it if you think that it can be done.
I imagine it would require storing _impl: Option<Foo> in FooMock and also adding some way to pass Foos constructor arguments to FooMock::new().
This is analog to CallBase() method from C#'s mocking framework Moq. (https://stackoverflow.com/a/31968342)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
questionUsage questionUsage question