*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'OCMockObject[Actor]: expected method was not invoked: perform'
Will result when executing the following code:
- Code: Select all
#import <Foundation/Foundation.h>
#import <OCMock/OCMock.h>
@interface Actor : NSObject
- (void)perform;
@end
@implementation Actor
- (void)perform
{
}
@end
@interface Director : NSObject
@property (nonatomic, copy) Actor* actor;
- (void)direct;
@end
@implementation Director
@synthesize actor;
- (id)init
{
self = [super init];
if (self) {
actor = [[Actor alloc] init];
}
return self;
}
- (void)direct
{
[actor perform];
// Actor* theActor = self.actor;
// [theActor perform];
}
@end
int main(int argc, const char * argv[])
{
@autoreleasepool {
Director* director = [[Director alloc] init];
id directorMock = [OCMockObject partialMockForObject:director];
id actor = [OCMockObject mockForClass:[Actor class]];
[[[directorMock stub] andReturn:actor] actor];
[[actor expect] perform];
[director direct];
[actor verify];
}
return 0;
}
If someone comments out the call to [actor perform] in the direct method and un-comments the lines that follow it, the program runs fine.
What is the reason that invoking the property directly is problematic and storing the property in a local variable works fine?