我正在编写一些Kiwi规范来测试我的应用中的身份验证系统,特别是加载一组存储的凭据。该示例通过在NSUserDefaults
和SSKeychain
中存根方法来返回固定数据,然后由身份验证类用于配置我的API客户端。代码看起来像这样:
it(@"authenticates the client with saved credentials", ^{
[NSUserDefaults stub:@selector(standardUserDefaults) andReturn:@{MoneyBrilliantActiveAccountKey: @"mock@example.com"}];
[SSKeychain stub:@selector(passwordForService:account:) andReturn:@"fooBarBaz"];
[[mockRequestSerializer should] receive:@selector(setValue:forHTTPHeaderField:) withCount:2];
MyAuthManager *newAuthManager = [[MyAuthManager alloc] initWithAPIClient:mockAPIClient];
[[theValue([newAuthManager isAuthenticated]) should] beNo];
[[theValue([newAuthManager authenticateClientWithSavedCredentials]) should] beYes];
[[theValue([newAuthManager isAuthenticated]) should] beYes];
});
但是,此示例失败了,我已设法跟踪+passwordForService:account:
未调用SSKeychain
的存根实施的原因。
是否有一些显而易见的东西可以防止这个存根被调用?