Skip to content

Instantly share code, notes, and snippets.

@nenadvulic
Last active August 29, 2015 13:57
Show Gist options
  • Save nenadvulic/9600443 to your computer and use it in GitHub Desktop.
Save nenadvulic/9600443 to your computer and use it in GitHub Desktop.
Fake network data using with OHHTTPStubs.
#import "MyViewController.h"
#import <OHHTTPStubs/OHHTTPStubs.h>
@interface FLUSubscribeViewController(){
id<OHHTTPStubsDescriptor> _stub;
}
@end
@implementation FLUSubscribeViewController
-(void)stubWithFile:(NSString*)filename{
_stub = [OHHTTPStubs stubRequestsPassingTest:^BOOL(NSURLRequest *request) {
//you can do the job only for particular route for exemple /new/user
return YES;
} withStubResponse:^OHHTTPStubsResponse*(NSURLRequest *request) {
//here you can handle with status code and headers
return [OHHTTPStubsResponse responseWithFileAtPath:OHPathForFileInBundle(filename, nil)
statusCode:200 headers:@{@"Content-Type":@"text/json"}];
}];
}
- (void) viewDidAppear:(BOOL)animated{
[super viewDidAppear:animated];
[self stubWithFile:@"my_response_json.json"];
}
- (void) viewDidDisappear:(BOOL)animated{
[super viewDidDisappear:animated];
if ( _stub ){
[OHHTTPStubs removeStub:_stub];
}
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment