Last Updated: February 25, 2016
·
1.839K
· adamyanalunas

Kiwi + Nocilla + AFNetworking = Mind your ordering

Having trouble getting your success or failure blocks to be called in Kiwi tests when stubbing out AFNetworking requests using Nocilla? Make sure you call your Kiwi expectations after you call your network request code. Sounds wrong but, trust me, it is the only way things will end up working as you expect.

CODE!

it(@"should return the proper JSON when calling someMethodWith…", ^{
    stubRequest(@"GET", requestPath).
    andReturn(201).
    withHeaders(@{@"Content-Type": @"application/json"}).
    withBody(jsonFixtureData);

    __block NSDictionary *returnedJSON = @{};

    AFHTTPRequestOperation *operation = [SomeClass someMethodWithSuccessBLock:^(NSDictionary *JSON) {
        returnedJSON = JSON;
    } andFailureBlock:^(NSError *error) {
        NSLog(@"U HAZ ERRD: %@", error);
    }];

    [[returnedJSON shouldEventually] equal:jsonFixtureData];
});