Skip to content

Instantly share code, notes, and snippets.

@mbinna
Created April 5, 2013 05:36
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mbinna/5316890 to your computer and use it in GitHub Desktop.
Save mbinna/5316890 to your computer and use it in GitHub Desktop.
Stub RestKit network requests in Kiwi with Nocilla
#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