need a way to "reset" a mock object

Discussion of the OCMock framework. If you have patches we would prefer you to send them to the mailing list, but attaching them to a topic is possible, too.

need a way to "reset" a mock object

Postby yonix » 24 Nov 2011, 16:25

Wow, this forum is pretty dead isn't it?
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?
yonix
 
Posts: 2
Joined: 10 Nov 2011, 16:10

Return to OCMock