ドキュメントとこの SO 投稿で示されているようにパッチャーを実装しようとしています: Typhoon: How to get an instance conforming to a protocol for production, and another for tests? .
ブロック アセンブリを使用していますが、次のエラーが表示されます。
[WPAnalyticsClientImplementation key]: unrecognized selector sent to instance 0x9eb01d0
でTyphoonPatcher.m: 46
。
私のクラスの実装は、このセレクターに応答しません。それはすべきですか?キーはパッチ適用プロセスにどのように関連していますか?
context(@"when the controller does something", ^{
it(@"should work", ^{
// This is an application test, so the factory has already been set in the app delegate.
TyphoonComponentFactory *factory = [TyphoonComponentFactory defaultFactory];
TyphoonPatcher* patcher = [[TyphoonPatcher alloc] init];
[patcher patchDefinition:[factory componentForType:@protocol(WPAnalyticsClient)] withObject:^id
{
id mockAnalytics = [KWMock mockForProtocol:@protocol(WPAnalyticsClient)];
[[mockAnalytics should] conformToProtocol:@protocol(WPAnalyticsClient)];
[mockAnalytics stub:@selector(getSomeString) andReturn:theValue(@"fake implementation")];
return mockAnalytics;
}];
[factory attachPostProcessor:patcher];
// The default factory should now return the mocked client.
id <WPAnalyticsClient> client = [factory componentForType:@protocol(WPAnalyticsClient)];
NSLog(@"conforms: %i", [client conformsToProtocol:@protocol(WPAnalyticsClient)]);
NSString *actualValue = [client getSomeString];
NSLog(@"someString: %@", actualValue);
[[theValue([actualValue isEqualToString:@"fake implementation"]) should] equal:theValue(YES)];
});
});
AppDelegate.m
TyphoonComponentFactory *factory = ([[TyphoonBlockComponentFactory alloc] initWithAssembly:[WPAssembly assembly]]);
[factory makeDefault];