Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I ended up solving this problem using another library, <code>OHHTTPStubs</code>. One can easily return mock objects through <code>AFNetworking</code>, stub out certain requests &amp; vary response/ request times. It is well documented <a href="http://cocoadocs.org/docsets/OHHTTPStubs/2.0.0/Classes/OHHTTPStubs.html" rel="nofollow">here</a>. Also here is the <a href="https://github.com/AliSoftware/OHHTTPStubs" rel="nofollow">github page</a>. A stub is removed like this: </p> <pre><code>[OHHTTPStubs removeStub:stub]; </code></pre> <p>Here is some sample code:</p> <pre><code>// A mockJSON file is loaded here NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0]; NSString *filePath = [NSString stringWithFormat:@"%@/%@", documentsDirectory,@"sampleJSON18.json"]; NSData* data = [NSData dataWithContentsOfFile:filePath]; NSError* error = nil; id mockJSON = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&amp;error]; //*** stub out AFNetworkingRequestOperation and return custom NSDictionary "mockJSON", in order to see how it is handled id&lt;OHHTTPStubsDescriptor&gt; stub = nil; stub = [OHHTTPStubs stubRequestsPassingTest:^BOOL(NSURLRequest *request) { return [[request.URL path]isEqualToString:@"/v1/epg/packages/59/broadcasts"]; // this means that any request which is equal to the above string is stubbed, return YES to stub *all* requests } withStubResponse:^OHHTTPStubsResponse*(NSURLRequest *request) { // The `stubbing` procedure occurs in this block. return [[OHHTTPStubsResponse responseWithJSONObject:mockJSON statusCode:200 headers:nil] requestTime:1.0f responseTime:5.0f]; // one can vary the request/responseTime here }]; stub.name = @"getChannelsWithBroadcastsForDay"; AFHTTPRequestOperation *operation = [self HTTPRequestOperationWithRequest:request success:^(AFHTTPRequestOperation *operation, id responseObject) { // The response object is now the mockJSON object, i.e. the original request is stubbed out } failure:^(AFHTTPRequestOperation *operation, NSError *error) { // handle failure } }]; [self enqueueHTTPRequestOperation:operation]; return operation; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload