Code to pass the test.

This commit is contained in:
NicholasTD07
2014-03-09 13:12:49 +08:00
parent f80bc3a7be
commit db4e2d521a
5 changed files with 23 additions and 5 deletions

View File

@@ -36,14 +36,16 @@
- (void)performFetch
{
if (self.fetchedResultsController) {
[self.fetchedResultsController performFetch:nil];
if (![self.fetchedResultsController performFetch:nil]) {
[self logFetchFailure];
}
}
[self.tableView reloadData];
}
- (void)logFetchFailure
{
NSLog(@"[%@ %@] performFetch: failed", NSStringFromClass([self class]), NSStringFromSelector(_cmd));
}
#pragma mark - View Controller - Life Cycle

View File

@@ -64,8 +64,9 @@
// given
sut = [[NTDFakeCDTVC alloc] init];
sut.fetchedResultsController = [[NTDFakeFetchedResultsController alloc] init];
[(NTDFakeFetchedResultsController *)sut.fetchedResultsController setFetchWillSucceed:NO];
// when
[(NTDFakeCDTVC *)sut setFetchWillFail:NO];
[sut performFetch];
// then
XCTAssertTrue([(NTDFakeCDTVC *)sut loggedFailure]);

View File

@@ -10,7 +10,6 @@
@interface NTDFakeCDTVC : NTDCoreDataTableViewController
@property (nonatomic) BOOL fetchWillFail;
@property (nonatomic) BOOL loggedFailure;
@end

View File

@@ -10,6 +10,7 @@
@interface NTDFakeFetchedResultsController : NSFetchedResultsController
@property (nonatomic) BOOL fetchWillSucceed;
@property (nonatomic) BOOL performFetchIsCalled;
@end

View File

@@ -8,12 +8,27 @@
#import "NTDFakeFetchedResultsController.h"
@interface NTDFakeFetchedResultsController ()
@property (nonatomic) BOOL fakePerformFetchsReturnValue;
@end
@implementation NTDFakeFetchedResultsController
- (BOOL)performFetch:(NSError *__autoreleasing *)error
{
self.performFetchIsCalled = YES;
return [super performFetch:error];
if (self.fakePerformFetchsReturnValue) {
return self.fetchWillSucceed;
} else {
return [super performFetch:error];
}
}
- (void)setFetchWillSucceed:(BOOL)fetchWillSucceed
{
_fetchWillSucceed = fetchWillSucceed;
self.fakePerformFetchsReturnValue = YES;
}
@end