Last active
December 13, 2015 18:08
-
-
Save timd/4953078 to your computer and use it in GitHub Desktop.
Example of Kiwi test involving Magical Record and view controllers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import "Kiwi.h" | |
#import "MyController.h" | |
#import "Record.h" | |
#import "MyModel.h" | |
// Category on class under test to expose private properties / methods | |
@interface MyController(MyTest) | |
@property (nonatomic, strong) NSDictionary *aDictionary; | |
@property (weak, nonatomic) IBOutlet UIButton *aButton; | |
- (void)someMethod; | |
@end | |
SPEC_BEGIN(MyTest) | |
describe(@"When testing something", ^{ | |
beforeEach(^{ | |
[MagicalRecord setDefaultModelFromClass:[self class]]; | |
[MagicalRecord setupCoreDataStackWithInMemoryStore]; | |
}); | |
context(@"something should work and", ^{ | |
beforeEach(^{ | |
}); | |
it(@"should do something", ^{ | |
}); | |
afterEach(^{ | |
}); | |
}); | |
context(@"when successfully firing the didTapUploadButton method", ^{ | |
beforeEach(^{ | |
record = [Record MR_createEntity]; | |
[record setRecordId:@"99-12345"]; | |
Customer *customer = [Customer MR_createEntity]; | |
[customer setRecord:record]; | |
Agreement *agreementOne = [Agreement MR_createEntity]; | |
[agreementOne setPaymentRequiredValue:YES]; | |
[agreementOne setEntryId:@"12345"]; | |
[agreementOne setRowversion:@12345]; | |
[agreementOne setCustomer:customer]; | |
Payment *paymentOne = [Payment MR_createEntity]; | |
[paymentOne setAgreement:agreementOne]; | |
[paymentOne setPaymentAmount:@12.34]; | |
[paymentOne setTimestamp:[NSDate date]]; | |
Agreement *agreementTwo = [Agreement MR_createEntity]; | |
[agreementTwo setPaymentRequiredValue:YES]; | |
[agreementTwo setEntryId:@"23456"]; | |
[agreementTwo setRowversion:@23456]; | |
[agreementTwo setCustomer:customer]; | |
Payment *paymentTwo = [Payment MR_createEntity]; | |
[paymentTwo setAgreement:agreementTwo]; | |
[paymentTwo setPaymentAmount:@23.45]; | |
[paymentTwo setTimestamp:[NSDate date]]; | |
[myController setupScreen]; | |
}); | |
it(@"should call the setupScreen method on load", ^{ | |
[[myController should] receive:@selector(setupScreen)]; | |
[myController loadView]; | |
[myController viewWillAppear:YES]; | |
}); | |
it(@"should mark the payments for this clip as uploaded once the update has completed successfully", ^{ | |
[myController didUpdateSingleRecord:@"54-12345"]; | |
NSArray *paymentsArray = [Payment findByAttribute:@"uploaded" withValue:@1]; | |
[[paymentsArray should] haveCountOf:2]; | |
}); | |
it(@"should mark all the agreements as paymentMade once the update has completed successfully", ^{ | |
NSArray *agreements = [Agreement MR_findByAttribute:@"paymentRequired" withValue:@1]; | |
NSIndexSet *indexSet = [agreements indexesOfObjectsPassingTest:^BOOL(Agreement *agreement, NSUInteger idx, BOOL *stop) { | |
return (![[agreement paymentMade] isEqual: @1]); | |
}]; | |
[[indexSet should] haveCountOf:2]; | |
[myController didUpdateSingleRecord:@"54-12345"]; | |
NSIndexSet *secondIndexSet = [agreements indexesOfObjectsPassingTest:^BOOL(Agreement *agreement, NSUInteger idx, BOOL *stop) { | |
return ([[agreement paymentMade] isEqual: @0]); | |
}]; | |
[[secondIndexSet should] haveCountOf:0]; | |
}); | |
afterEach(^{ | |
[Record MR_truncateAll]; | |
[Customer MR_truncateAll]; | |
[Agreement MR_truncateAll]; | |
[Payment MR_truncateAll]; | |
}); | |
}); | |
afterAll(^{ | |
[MagicalRecord cleanUp]; | |
}); | |
}); | |
SPEC_END |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment