Skip to content

Instantly share code, notes, and snippets.

@mbinna mbinna/gist:5316890
Created Apr 5, 2013

Embed
What would you like to do?
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
You can’t perform that action at this time.