I'll just post anyway - in the worst case I wasted a few minutes of my time and no one wil ever read it.
I think there should be a way to "reset" a mock object - meaning to reset all the stubs/expectations/rejections.
This would allow easier code reuse between tests (I can have a stub for the common case in my setUp, and if needed - reset and re-stub it in a specific test).
Also, this is the only way of doing something like this:
- Code: Select all
// mock is a nice mock
[[mock reject] foo];
[bar doSomethingThatShouldntCallFooOnMock];
// now i would like to reset my nice mock
[bar doSomethingThatCallsFooOnMockAndWeDontCareAboutIt];
// check other stuff...
For now I did it in a category:
- Code: Select all
@implementation OCMockObject (MyExtensions)
- (void)reset
{
[rejections removeAllObjects];
[expectations removeAllObjects];
[recorders removeAllObjects];
}
@end
Any better built-in way?