*Edit - I originally wanted to test AFNetworking
using Nocilla
but ended up using OHHTTPStubs
to do the job. I've answered the original question below, using OHHTTPStubs
*
Original Question:
I want to test the APIClient of our app - the bare bones of one of methods which needs to be tested is detailed below. So I need to mimic the HTTPRequestOperationWithRequest:
call from AFNetworking
. Nocilla
seems like an option to do this (more suitable than OCMock
).
I've checked out the github page which deals with Nocilla
and AFNetworking
but I'm not sure how to apply it to my problem - the syntax isn't very familiar.
- So my wondering if someone could give me a hint as to how I might use
Nocilla
in this case? - Also, must one use
Kiwi
withNocilla
?
Thanks in advance :)
-(AFHTTPRequestOperation *)getBroadcastsForChannel:(TINChannel *)channel
startTime:(NSDate *)date
limit:(NSNumber *)limit
pastLimit:(NSNumber *)pastLimit
fields:(NSArray *)fieldsArray
interval:(TINBroadcastsInterval)interval
completionBlock:(void (^)(NSArray *broadcasts, NSError *error))block {
// Some setup here
NSURLRequest *request = [self requestWithMethod:@"GET" path:path parameters:params];
AFHTTPRequestOperation *operation = [self HTTPRequestOperationWithRequest:request success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSError *error;
NSDictionary *responseDic = [self parseResponse:responseObject error:&error];
if (error) {
if (block) {
block([NSArray array], error);
}
return;
}
// Parse the response object here
if (block) {
block([NSArray arrayWithArray:broadcastsOutput], nil);
}
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
if (block) {
block([NSArray array], error);
}
}];
[self enqueueHTTPRequestOperation:operation];
return operation;
}