mockall
mockall copied to clipboard
Assume Times(1) by default for a return_once expectation
When creating an expectation with return_once(), I was expecting that Times(1) was the default, but it is not. So creating two expectations with return_once() (and no Times constraint) fails due to the first expectation being called twice.
BTW, Gmock does this: WillOnce implies Times(1) by default.
When creating an expectation with return_once(), I was expecting that Times(1) was the default, but it is not. So creating two expectations with return_once() (and no Times constraint) fails due to the first expectation being called twice.
Yes, I've sometimes thought that I should change that. This impact would be slight; just a different panic message mostly. But I didn't think about the user who sets multiple expectations, expecting them to be called in sequence, without adding a .times
constraint. That's the best argument I've heard for changing it.
BTW, Gmock does this: WillOnce implies Times(1) by default.
That's because in C++ non-copyable types are very rare and return by move is considered exotic. So Gmock has no need for a .return_once
method like Mockall does. With Mockall, it's essential because non-copy types are common. So the "once" doesn't really mean the exact same thing in GMock.