Rozważmy ten kod, który działa (metoda loginWithEmail dostaje Oczekuje się również, oczekiwany):OCMock, dlaczego nie mogę oczekiwać metody na protokole?
_authenticationService = [[OCMockObject mockForClass:[AuthenticationService class]] retain];
[[_authenticationService expect] loginWithEmail:[OCMArg any] andPassword:[OCMArg any]];
Versus ten kod:
_authenticationService = [[OCMockObject mockForProtocol:@protocol(AuthenticationServiceProtocol)] retain];
[[_authenticationService expect] loginWithEmail:[OCMArg any] andPassword:[OCMArg any]];
Drugi przykład kod nie działa na linii 2 z następujących błąd:
*** -[NSProxy doesNotRecognizeSelector:loginWithEmail:andPassword:] called! Unknown.m:0: error: -[MigratorTest methodRedacted] : ***
-[NSProxy doesNotRecognizeSelector:loginWithEmail:andPassword:] called!
AuthenticationServiceProtocol deklaruje metodę:
@protocol AuthenticationServiceProtocol <NSObject>
@property (nonatomic, retain) id<AuthenticationDelegate> authenticationDelegate;
- (void)loginWithEmail:(NSString *)email andPassword:(NSString *)password;
- (void)logout;
- (void)refreshToken;
@end
I to jest realizowane w klasie:
@interface AuthenticationService : NSObject <AuthenticationServiceProtocol>
ten korzysta OCMock dla iOS.
Dlaczego expect
kończy się niepowodzeniem, gdy próbą jest mockForProtocol
?
Budujesz OCMock ze źródła? Byłoby interesujące wstawienie punktu przerwania w metodzie 'methodSignatureForSelector:' obiektu 'OCProtocolMockObject'. –
Nie budując ze źródła, właśnie pobrałem bibliotekę statyczną. – driis
Czy możesz zamieścić rzeczywistą deklarację protokołu? –