Created
March 25, 2014 15:59
-
-
Save DenTelezhkin/9764954 to your computer and use it in GitHub Desktop.
Testing networking with OHHTTPStubs and Expecta
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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