I have an objective-c class X
with method turtle
that I would like to mock with OCMock to unit test a class T
.
//X.h
@interface X
-(void) turtle;
@end
Class T
includes a category and uses that to communicate with X
. The category method calls turtle
.
//X+utils.h:
@interface X(Utils)
-(void) catMethod;
@end
//X+utils.m:
@implementation X(Utils)
-(void) catMethod
{
[self turtle];
}
@end
//T.m
#import "X+utils.h"
@implementation T
-(void) useX:(X*) xInstance
{
[xInstance catMethod];
}
In the unit test, I setup the mock such that it expects a call to turtle
.
-(void) test
{
id mockX = [OCMockObject mockForClass:[X class]]
[[mockX expect] turtle];
[instanceOfT useX:mockX];
[mockX verify];
}
I don't setup the mock to expect a call to the method of the category, since I would like to give the implementation the freedom to pick any category it likes to use.
The call useX is fails since OCMock catches the "unexpected" call to catMethod
.
Can I configure OCMock to actually use the implementation of the category and only mock calls that are defined in the actual interface X
?