注意:我正在使用OCMock 3.0.2和Xcode 5.1.1。
我有一个对象作为它拥有的另一个对象的Facade。我构建它的方式是在我想要暴露的方法的自有对象中创建一个协议:
@protocol SyncEngineProtocol <NSObject>
- (void) updateAllGroups;
... more methods....
@end
@interface CoreDataSyncEngine : NSObject <SyncEngineProtocol>
@end
然后在Facade中,我创建了一个符合此协议的类别,但我没有实现该类别。相反,我将这些调用转发给拥有的对象:
@interface ModelManager (SyncMethods) <SyncEngineProtocol>
@end
@implementation ModelManager
...
- (id) forwardingTargetForSelector:(SEL)aSelector{
if ([_syncEngine respondsToSelector:aSelector]){
return _syncEngine;
}
return nil;
}
...
@end
我遇到两个问题,我不知道它们是否相关:
0 0x00000001020c2973 in objc_exception_throw ()
...
5 0x0000000102352ead in +[NSMethodSignature signatureWithObjCTypes:] ()
6 0x000000010dc128ac in +[NSObject(OCMAdditions) instanceMethodForwarderForSelector:] at /tmp/ocmock.13557/Source/Source/OCMock/NSObject+OCMAdditions.m:29
7 0x000000010dc11fbb in -[OCClassMockObject setupForwarderForClassMethodSelector:] at /tmp/ocmock.13557/Source/Source/OCMock/OCClassMockObject.m:110
8 0x000000010dc1292e in +[NSObject(OCMAdditions) enumerateMethodsInClass:usingBlock:] at /tmp/ocmock.13557/Source/Source/OCMock/NSObject+OCMAdditions.m:48
9 0x000000010dc11e63 in -[OCClassMockObject prepareClassForClassMethodMocking] at /tmp/ocmock.13557/Source/Source/OCMock/OCClassMockObject.m:97
10 0x000000010dc11b5b in -[OCClassMockObject initWithClass:] at /tmp/ocmock.13557/Source/Source/OCMock/OCClassMockObject.m:31
11 0x000000010dc1316f in +[OCMockObject mockForClass:] at /tmp/ocmock.13557/Source/Source/OCMock/OCMockObject.m:48
12 0x000000010dc13231 in +[OCMockObject niceMockForClass:] at /tmp/ocmock.13557/Source/Source/OCMock/OCMockObject.m:64
13 0x000000010dc06abb in +[CSGroupControllerTests setUp] at /Users/aaron/Dropbox/Client Projects/CrowdSporting/Codebase/crowdsportingTests/CSGroupControllerTests.m:56
14 0x000000010dee148b in -[XCTestSuite performTest:] ()
15 0x000000010dee2a75 in -[XCTest run] ()
16 0x000000010dee14df in -[XCTestSuite performTest:] ()
17 0x000000010dee2a75 in -[XCTest run] ()
18 0x000000010dee14df in -[XCTestSuite performTest:] ()
19 0x000000010dee2a75 in -[XCTest run] ()
20 0x000000010dee41b4 in +[XCTestProbe runTests:] ()
...
27 0x0000000100b52e33 in UIApplicationMain ()
我不认为这两者是相关的,但由于我同时遇到问题,我不能忽视时机。
任何帮助都将不胜感激。
我降级到OCMock 2.2.4并且OCMock框架中抛出的所有异常都没有了,哪种情况很糟糕,因为我更喜欢3.0中的新语法。
我仍然不能嘲笑门面。似乎OCMock要求实现所有方法......没有动态转发。当然,我可以这样做,但这很痛苦。