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];
});
Written by Adam Yanalunas
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#