1

I'm writing some Kiwi specs to test the authentication system in my app, specifically loading a set of stored credentials. The example works by stubbing methods in NSUserDefaults and SSKeychain to return fixed data, which the authentication class then uses to configure my API client. The code looks something like this:

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];
});

However, this example fails, and I've managed to track the reason why down to my stubbed implementation of +passwordForService:account: not being called on SSKeychain.

Is there something obvious I'm missing that would prevent this stub from being called?

rpowell
  • 1,464
  • 2
  • 16
  • 29
  • Are you stubbing the SSKeychain in other parts of the tests also? Multiple stubs of class methods might bring you problems, myself I try to avoid as much as possible stubs for class methods. – Cristik Apr 02 '15 at 05:01

0 Answers0