Created
April 5, 2013 05:36
-
-
Save mbinna/5316890 to your computer and use it in GitHub Desktop.
Stub RestKit network requests in Kiwi with Nocilla
This file contains hidden or 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
#import "MBAEntityFetcher.h" | |
#import "MBAAPIBaseURL.h" | |
#import "MBAResponseDescriptorProvider.h" | |
#import <Kiwi/Kiwi.h> | |
#import <Nocilla/LSNocilla.h> | |
#import <RestKit/RestKit.h> | |
#import <RestKit/Testing.h> | |
SPEC_BEGIN(MBAEntityFetcherSpec) | |
describe(@"MBAEntityFetcher", ^{ | |
__block MBAEntityFetcher *entityFetcher; | |
beforeAll(^{ | |
[[LSNocilla sharedInstance] start]; | |
[RKTestFixture setFixtureBundle:[NSBundle bundleForClass:[self class]]]; | |
RKObjectManager *objectManager = [RKObjectManager managerWithBaseURL:MBAAPIBaseURL()]; | |
[objectManager addResponseDescriptorsFromArray:[MBAResponseDescriptorProvider allResponseDescriptors]]; | |
[RKObjectManager setSharedManager:objectManager]; | |
}); | |
afterAll(^{ | |
[[LSNocilla sharedInstance] stop]; | |
[RKObjectManager setSharedManager:nil]; | |
}); | |
beforeEach(^{ | |
entityFetcher = [[MBAEntityFetcher alloc] init]; | |
}); | |
afterEach(^{ | |
[[LSNocilla sharedInstance] clearStubs]; | |
}); | |
context(@"when fetching entitites from the fixture", ^{ | |
beforeEach(^{ | |
NSURL *url = [NSURL URLWithString:@"entities.json" relativeToURL:MBAAPIBaseURL()]; | |
NSString *jsonString = [RKTestFixture stringWithContentsOfFixture:@"getEntities.json"]; | |
stubRequest(@"GET", [url absoluteString]). | |
andReturn(200). | |
withHeaders(@{ @"Content-Type": @"application/json" }). | |
withBody(jsonString); | |
}); | |
it(@"creates the 9 entities from the fixture", ^{ | |
__block NSArray *entities; | |
[entityFetcher fetchEntitiesWithCompletionHandler:^(NSArray *fetchedEntities, NSError *error) { | |
entities = fetchedEntities; | |
}]; | |
[[expectFutureValue(entities) shouldEventually] haveCountOf:9]; | |
}); | |
}); | |
}); | |
SPEC_END |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment