I have implemented example from Mocking Network Requests With OHHTTPStubs. Unfotunately I encountered EXC_BAD_ACCESS exception when matching my result in line:
[[expectFutureValue(origin) shouldEventuallyBeforeTimingOutAfter(3.0)] equal:@"111.222.333.444"];
Did anyone encountered this kind of problem? What could be possible solution?
Here is the full code:
#import "Kiwi.h"
#import "AFNetworking.h"
#import "OHHTTPStubs.h"
#import "OHHTTPStubsResponse.h"
SPEC_BEGIN(NetworkTest)
describe(@"The call to the external service", ^{
beforeEach(^{
[OHHTTPStubs addRequestHandler:^OHHTTPStubsResponse*(NSURLRequest *request, BOOL onlyCheck){
return [OHHTTPStubsResponse responseWithFile:@"test.json" contentType:@"text/json" responseTime:1.0];
}];
);
it(@"should return an IP address", ^{
__block NSString *origin;
NSURLRequest* request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://httpbin.org/ip"]];
AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
origin = [JSON valueForKeyPath:@"origin"];
} failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON) {
// no action
}];
[operation start];
[[expectFutureValue(origin) shouldEventuallyBeforeTimingOutAfter(3.0)] equal:@"111.222.333.444"];
});
});
SPEC_END