Skip to content

Commit

Permalink
Merge branch 'coverage'
Browse files Browse the repository at this point in the history
  • Loading branch information
jhersh committed Feb 22, 2015
2 parents 13bfad1 + 5163d9f commit 4feb919
Show file tree
Hide file tree
Showing 10 changed files with 269 additions and 8 deletions.
6 changes: 6 additions & 0 deletions .slather.yml
@@ -0,0 +1,6 @@
coverage_service: coveralls
xcodeproj: Example/ExampleSSDataSources.xcodeproj
source_directory: SSDataSources
ignore:
- Example/ExampleSSDataSourcesTests

5 changes: 3 additions & 2 deletions .travis.yml
@@ -1,17 +1,18 @@
osx_image: xcode611
language: objective-c
before_install:
- gem install cocoapods xcpretty obcd -N
- gem install cocoapods xcpretty obcd slather -N
cache: cocoapods
podfile: Example/Podfile
env:
- LC_CTYPE=en_US.UTF-8 LANG=en_US.UTF-8
script:
- set -o pipefail && xcodebuild -workspace Example/ExampleSSDataSources.xcworkspace
-scheme ExampleSSDataSources -sdk iphonesimulator -destination "platform=iOS Simulator,name=iPhone 6"
clean test | xcpretty -c
GCC_INSTRUMENT_PROGRAM_FLOW_ARCS=YES GCC_GENERATE_TEST_COVERAGE_FILES=YES clean test | xcpretty -c
- pod lib lint --quick
- obcd --path SSDataSources find HeaderStyle
notifications:
slack:
secure: Lu0j1+59o9FCSe/sM7Pf8Qx0aD7akVXaYjstbta8vGJxaW4a3w20Em1N1KHapYCYOiVHKiBOHRVcMdO+4yfA7TREinVf1sUUskgZu3Ou18Tx0bB53fRFnhE8Wz+zOYzeL89K20hEvSzHVj13/DLCwIcERXIkBKwoAjJIH8HiKi8=
after_success: slather
4 changes: 4 additions & 0 deletions Example/ExampleSSDataSources.xcodeproj/project.pbxproj
Expand Up @@ -503,6 +503,8 @@
COPY_PHASE_STRIP = NO;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_DYNAMIC_NO_PIC = NO;
GCC_GENERATE_TEST_COVERAGE_FILES = YES;
GCC_INSTRUMENT_PROGRAM_FLOW_ARCS = YES;
GCC_OPTIMIZATION_LEVEL = 0;
GCC_PREPROCESSOR_DEFINITIONS = (
"DEBUG=1",
Expand Down Expand Up @@ -535,6 +537,8 @@
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
COPY_PHASE_STRIP = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_GENERATE_TEST_COVERAGE_FILES = YES;
GCC_INSTRUMENT_PROGRAM_FLOW_ARCS = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
Expand Down
71 changes: 69 additions & 2 deletions Example/ExampleSSDataSourcesTests/SSArrayDataSourceTests.m
@@ -1,5 +1,6 @@
#import "SSTestHelper.h"
#import <SSDataSources.h>
#import "Wizard.h"

@interface SSArrayDataSourceTests : XCTestCase
@end
Expand All @@ -8,14 +9,25 @@ @implementation SSArrayDataSourceTests
{
UITableView *tableView;
UICollectionView *collectionView;
SSArrayDataSource *dataSource;
}

- (void)setUp
{
[super setUp];

[MagicalRecord setupCoreDataStackWithInMemoryStore];

tableView = [OCMockObject niceMockForClass:UITableView.class];
collectionView = [OCMockObject niceMockForClass:UICollectionView.class];
dataSource = [[SSArrayDataSource alloc] initWithItems:nil];
}

- (void)tearDown
{
[super tearDown];

[Wizard MR_truncateAll];
}

- (void)testInitializable
Expand Down Expand Up @@ -43,6 +55,16 @@ - (void)testImplementsCollectionViewSectionCounting
}).toNot.raiseAny();
}

- (void)testNilIndexPathAccess
{
expect([dataSource itemAtIndexPath:nil]).to.beNil();
}

- (void)testOutOfBoundsIndexPathAccess
{
expect([dataSource itemAtIndexPath:[NSIndexPath indexPathForItem:10 inSection:0]]).to.beNil();
}

#pragma mark UITableViewDataSource

- (void)testSingleTableSectionForItems
Expand Down Expand Up @@ -119,6 +141,12 @@ - (void)testClearingTableItems

[ds clearItems];
expect(ds.numberOfItems).to.equal(0);

[ds appendItem:@"Item"];
expect(ds.numberOfItems).to.equal(1);

[ds removeAllItems];
expect(ds.numberOfItems).to.equal(0);
}

- (void)testClearingCollectionItems
Expand Down Expand Up @@ -216,6 +244,12 @@ - (void)testInsertingItems
expect(ds.allItems).to.equal((@[@"baz", @"foo"]));
}

- (void)testInsertingItemsGuard
{
[dataSource insertItems:@[] atIndexes:nil];
expect(dataSource.numberOfItems).to.equal(0);
}

- (void)testInsertingItemsInsertsRowsIntoDataSourceTableView
{
SSArrayDataSource *ds = [[SSArrayDataSource alloc] initWithItems:@[@"foo"]];
Expand Down Expand Up @@ -537,15 +571,48 @@ - (void)testForwardCommitEditingStyleToDeletionBlock

expect(ds.numberOfItems).to.equal(@3);

ds.tableDeletionBlock = ^(SSArrayDataSource *dataSource,
ds.tableDeletionBlock = ^(SSArrayDataSource *dsds,
UITableView *tableView,
NSIndexPath *indexPath) {

[dataSource removeItemAtIndex:(NSUInteger)indexPath.row];
[dsds removeItemAtIndex:(NSUInteger)indexPath.row];
};

[ds tableView:tableView commitEditingStyle:UITableViewCellEditingStyleDelete forRowAtIndexPath:indexPath];
expect(ds.numberOfItems).to.equal(@2);
}

#pragma mark - Core Data

- (void)testFindingManagedObjectById
{
Wizard *wizard = [Wizard wizardWithName:@"Gandalf" realm:@"Middle-Earth"];
Wizard *wizard2 = [Wizard wizardWithName:@"Merlyn" realm:@"Arthurian"];

[dataSource appendItem:wizard];

expect([dataSource indexPathForItemWithId:[wizard objectID]]).to.equal([NSIndexPath indexPathForItem:0 inSection:0]);
expect([dataSource indexPathForItemWithId:[wizard2 objectID]]).to.beNil();
}

#pragma mark - Empty View

- (void)testEmptyView
{
UIView *emptyView = [UIView new];

dataSource.tableView = (UITableView *)tableView;
dataSource.emptyView = emptyView;

expect(emptyView.hidden).to.beFalsy();

[dataSource appendItem:@"Item"];

expect(emptyView.hidden).to.beTruthy();

dataSource.emptyView = emptyView;

expect(emptyView.frame).toNot.equal(CGRectZero);
}

@end
7 changes: 7 additions & 0 deletions Example/ExampleSSDataSourcesTests/SSBaseDataSourceTests.m
Expand Up @@ -35,6 +35,13 @@ - (void)testRequiresSubclassesToImplementItemRetrieval
}).to.raiseAny();
}

- (void)testRequiresSubclassesToImplementSectionCount
{
expect(^{
[ds numberOfSections];
}).to.raiseAny();
}

- (void)testRequiresSubclassesToImplementCollectionViewSectionCounting
{
expect(^{
Expand Down
45 changes: 42 additions & 3 deletions Example/ExampleSSDataSourcesTests/SSCoreDataSourceTests.m
Expand Up @@ -41,6 +41,8 @@ - (void)tearDown
[super tearDown];

[Wizard MR_truncateAll];

dataSource = nil;
}

- (void)testRetrievesItems
Expand Down Expand Up @@ -93,6 +95,33 @@ - (void)testInsertingItemInsertsRow
[mockTable verify];
}

- (void)testInsertingSectionInsertsSection
{
id mockTable = tableView;
dataSource = [[SSCoreDataSource alloc] initWithFetchRequest:[Wizard MR_requestAllSortedBy:@"name" ascending:YES]
inContext:[NSManagedObjectContext MR_defaultContext]
sectionNameKeyPath:@"name"];
dataSource.tableView = tableView;
dataSource.rowAnimation = UITableViewRowAnimationLeft;

[MagicalRecord saveWithBlockAndWait:^(NSManagedObjectContext *context) {
[Wizard MR_truncateAllInContext:context];
}];

expect([dataSource numberOfSections]).to.equal(0);

[[mockTable expect] insertSections:[NSIndexSet indexSetWithIndex:0]
withRowAnimation:dataSource.rowAnimation];

[MagicalRecord saveWithBlockAndWait:^(NSManagedObjectContext *context) {
Wizard *w = [Wizard MR_createInContext:context];
w.name = @"Name";
w.realm = @"Realm";
}];

[mockTable verify];
}

- (void)testDeletingItemDeletesRow
{
id mockTable = tableView;
Expand Down Expand Up @@ -153,10 +182,11 @@ - (void)testForwardsMovesToMoveBlock

[[NSManagedObjectContext MR_contextForCurrentThread] MR_saveToPersistentStoreAndWait];

[tableView moveRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]
toIndexPath:[NSIndexPath indexPathForRow:1 inSection:0]];
[dataSource tableView:dataSource.tableView
moveRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]
toIndexPath:[NSIndexPath indexPathForRow:1 inSection:0]];

expect(didMove).to.beTruthy;
expect(didMove).to.beTruthy();
}

- (void)testFindingManagedObjects
Expand All @@ -166,6 +196,15 @@ - (void)testFindingManagedObjects
[[NSManagedObjectContext MR_contextForCurrentThread] MR_saveToPersistentStoreAndWait];

expect([dataSource indexPathForItem:aWizard]).to.equal([NSIndexPath indexPathForRow:0 inSection:0]);

expect([dataSource indexPathForItemWithId:[aWizard objectID]]).to.equal([NSIndexPath indexPathForRow:0 inSection:0]);
}

#pragma mark - NSFetchedResultsControllerDelegate

- (void)testSectionIndexTitles
{
expect([dataSource controller:dataSource.controller sectionIndexTitleForSectionName:@"Section"]).to.equal(@"Section");
}

@end
22 changes: 22 additions & 0 deletions Example/ExampleSSDataSourcesTests/SSExpandingDataSourceTests.m
Expand Up @@ -203,6 +203,28 @@ - (void)testExpandingSection {
[mockTable verify];
}

- (void)testSectionToggle
{
ds = [[SSExpandingDataSource alloc] initWithItems:@[ @1, @2 ]];
ds.collapsedSectionCountBlock = ^NSInteger(SSSection *sec, NSInteger sectionIndex) {
return 1;
};

expect([ds numberOfItemsInSection:0]).to.equal(2);
[ds toggleSectionAtIndex:0];
expect([ds numberOfItemsInSection:0]).to.equal(1);
SSSection *section = [ds sectionAtIndex:0];
[ds setSection:section expanded:NO];
[ds setSection:nil expanded:NO];
expect([ds numberOfItemsInSection:0]).to.equal(1);
[ds replaceItemAtIndexPath:[NSIndexPath indexPathForItem:0 inSection:0] withItem:@2];
expect([ds itemAtIndexPath:[NSIndexPath indexPathForItem:0 inSection:0]]).to.equal(@2);
[ds removeItemAtIndexPath:[NSIndexPath indexPathForItem:0 inSection:0]];
expect([ds numberOfItemsInSection:0]).to.equal(1);
[ds insertItem:@3 atIndexPath:[NSIndexPath indexPathForItem:0 inSection:0]];
expect([ds numberOfItemsInSection:0]).to.equal(1);
}

- (void)testMovingSection {
ds = [[SSExpandingDataSource alloc] initWithItems:@[ @1, @2, @3 ]];
ds.collapsedSectionCountBlock = ^NSInteger(SSSection *sec, NSInteger sectionIndex) {
Expand Down

0 comments on commit 4feb919

Please sign in to comment.