Skip to content

Instantly share code, notes, and snippets.

@DenTelezhkin
Created March 25, 2014 15:59
Show Gist options
  • Save DenTelezhkin/9764954 to your computer and use it in GitHub Desktop.
Save DenTelezhkin/9764954 to your computer and use it in GitHub Desktop.
Testing networking with OHHTTPStubs and Expecta
@interface BitcoinLoaderSpecs : XCTestCase
@property (nonatomic, strong) RateModel * rate;
@end
@implementation BitcoinLoaderSpecs
- (void)setUp
{
[super setUp];
[OHHTTPStubs stubRequestsPassingTest:^BOOL(NSURLRequest * request)
{
return YES;
} withStubResponse:^OHHTTPStubsResponse *(NSURLRequest * request)
{
return [OHHTTPStubsResponse responseWithFileAtPath:OHPathForFileInBundle(@"bitcoin_rate.json", nil)
statusCode:200
headers:@{@"Content-Type":@"application/json"}];
}];
[BitcoinLoader loadBitcoinRateWithSuccess:^(NSURLSessionDataTask * task, id responseObject)
{
self.rate = responseObject;
} failure:^(NSURLSessionDataTask * task, NSError * error)
{
XCTFail();
}];
expect(self.rate).willNot.beNil();
}
- (void)tearDown
{
[OHHTTPStubs removeAllStubs];
[super tearDown];
}
-(void)testRateHasCorrectClass
{
expect([self.rate class]).to.equal([RateModel class]);
}
// Etc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment