我正在编写一些 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
。
有什么明显的我遗漏的东西会阻止这个存根被调用吗?