Skip to content

Instantly share code, notes, and snippets.

@bonkowski
Created January 17, 2012 18:04
Show Gist options
  • Save bonkowski/1627868 to your computer and use it in GitHub Desktop.
Save bonkowski/1627868 to your computer and use it in GitHub Desktop.
Kiwi sample
#import "Kiwi.h"
#import "AdProvider.h"
#import "RowSet.h"
#import "AdFetcher.h"
static NSArray* fetchNumberOfAds(NSInteger numberOfAds) {
NSMutableArray *ads = [[NSMutableArray alloc] init];
for (int i = 0; i < numberOfAds; i++) {
[ads addObject:[[NSObject alloc] init]];
}
return ads;
}
SPEC_BEGIN(AdProviderSpec)
__block AdProvider *provider = nil;
__block id adFetcher = nil;
beforeAll(^{
provider = [[AdProvider alloc] initWithCellsForLandscape:8 portrait:6];
provider.chunkSize = 5;
adFetcher = [KWMock mockForClass:[AdFetcher class]];
provider.delegate = adFetcher;
});
describe(@"AdProvider", ^{
it(@"should provide correct number of ads for a given orientation", ^{
[[adFetcher should] receive:@selector(fetchNumberOfAds:) withCountAtLeast:1];
[adFetcher stub:@selector(fetchNumberOfAds:) andReturn:fetchNumberOfAds(11)];
RowSet *portraitRowSet = [provider getRowSetAtIndex:0 forOrientation:UIInterfaceOrientationPortrait];
[[theValue(portraitRowSet.numberOfAds) should] equal:theValue((uint) 6)];
[adFetcher stub:@selector(fetchNumberOfAds:) andReturn:fetchNumberOfAds(8)];
RowSet *landscapeRowSet = [provider getRowSetAtIndex:0 forOrientation:UIInterfaceOrientationLandscapeLeft];
[[theValue(landscapeRowSet.numberOfAds) should] equal:theValue((uint) 8)];
});
it(@"should fetch more ads when number of available ads is below a threshold value", ^{
[[adFetcher should] receive:@selector(fetchNumberOfAds:) withCountAtLeast:2];
[adFetcher stub:@selector(fetchNumberOfAds:) andReturn:fetchNumberOfAds(11)];
[provider getRowSetAtIndex:0 forOrientation:UIInterfaceOrientationPortrait];
[adFetcher stub:@selector(fetchNumberOfAds:) andReturn:fetchNumberOfAds(42)];
[provider getRowSetAtIndex:5 forOrientation:UIInterfaceOrientationLandscapeLeft];
});
it(@"should return valid a RowSet if number of ads is less than asked for", ^{
[adFetcher stub:@selector(fetchNumberOfAds:) andReturn:fetchNumberOfAds(3)];
RowSet *rowSet = [provider getRowSetAtIndex:0 forOrientation:UIInterfaceOrientationPortrait];
[[theValue(rowSet.numberOfAds) should] equal:theValue((uint) 3)];
});
});
SPEC_END
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment