I have class method to test with dependant object (Keys object)
+ (NSURL*)apiURLWithPath:(NSString*)path {
MyKeys *keys = [MyKeys new];
NSString *url = [NSString stringWithFormat:@"%@?api_key=%@", path, [keys APIKey]];
return [NSURL URLWithString:url];
}
I am trying to partially mock this Keys object and return "MY_API_KEY" value but the test method fails and returns real API key (e.g. as78d687as6d7das8da).
describe(@"APIRouter", ^{
it(@"should return url for api", ^{
Keys *keys = [Keys new];
id keysPartialMock = OCMPartialMock(keys);
OCMStub([keysPartialMock APIKey]).andReturn(@"MY_API_KEY");
NSURL *url = [APIRouter apiURLWithPath:@"http://ift.tt/1Q4Z61E"];
expect([url absoluteString]).to.equal([NSString stringWithFormat:@"http://ift.tt/1Q4Z3TI"]);
});
});
Aucun commentaire:
Enregistrer un commentaire