このコードを考えてみてください。これは機能します(loginWithEmailメソッドは期待どおりに期待されます)。
_authenticationService = [[OCMockObject mockForClass:[AuthenticationService class]] retain];
[[_authenticationService expect] loginWithEmail:[OCMArg any] andPassword:[OCMArg any]];
このコードに対して:
_authenticationService = [[OCMockObject mockForProtocol:@protocol(AuthenticationServiceProtocol)] retain];
[[_authenticationService expect] loginWithEmail:[OCMArg any] andPassword:[OCMArg any]];
2番目のコード例は、2行目で次のエラーで失敗します。
*** -[NSProxy doesNotRecognizeSelector:loginWithEmail:andPassword:] called! Unknown.m:0: error: -[MigratorTest methodRedacted] : ***
-[NSProxy doesNotRecognizeSelector:loginWithEmail:andPassword:] called!
AuthenticationServiceProtocolはメソッドを宣言します:
@protocol AuthenticationServiceProtocol <NSObject>
@property (nonatomic, retain) id<AuthenticationDelegate> authenticationDelegate;
- (void)loginWithEmail:(NSString *)email andPassword:(NSString *)password;
- (void)logout;
- (void)refreshToken;
@end
そしてそれはクラスに実装されています:
@interface AuthenticationService : NSObject <AuthenticationServiceProtocol>
これはiOS用のOCMockを使用しています。
expect
モックが失敗するのはなぜmockForProtocol
ですか?