If an expectation has .called_once yet gets called more than once, it doesn't currently fail until the end of the test. This can be very confusing, especially if the following .returning statement has side effects. It would be best if the test failed immediately on the second call. For example:
fn times_once() {
pub trait A {
fn foo(&self) -> u32;
}
create_mock! {
impl A for AMock (self) {
expect_foo("foo"):
fn foo(&self) -> u32;
}
}
let mut mock = AMock::new();
let mut o = Some(0);
mock.expect_foo()
.called_once()
.returning(move |_| o.take().unwrap());
mock.foo();
mock.foo();
}
This code will fail with the error
panicked at 'called `Option::unwrap()` on a `None` value'
instead of something about foo being called too many times.
If an expectation has
.called_once
yet gets called more than once, it doesn't currently fail until the end of the test. This can be very confusing, especially if the following.returning
statement has side effects. It would be best if the test failed immediately on the second call. For example:This code will fail with the error
instead of something about
foo
being called too many times.