Created
August 27, 2013 07:29
-
-
Save HHuckebein/6350657 to your computer and use it in GitHub Desktop.
This file contains 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
@implementation DocumentsBrowserTest | |
{ | |
BOOL _isPad; | |
SEL realPrepareForSegue, testPrepareForSegue; | |
} | |
- (void)setUp | |
{ | |
[super setUp]; | |
_isPad = UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad; | |
realPrepareForSegue = @selector(prepareForSegue:sender:); | |
testPrepareForSegue = @selector(documentsBrowserTest_prepareForSegue:sender:); | |
UIStoryboard *storyboard = nil; | |
if (_isPad) { | |
storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPad" bundle:nil]; | |
} | |
else { | |
storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone" bundle:nil]; | |
} | |
UINavigationController *navController = [storyboard instantiateInitialViewController]; | |
if (_isPad) { | |
self.sut = (DocumentsBrowserVC *)[navController.viewControllers[0] topViewController]; | |
self.documentsDetailsVC = (DocumentsDetailVC *)[navController.viewControllers[1] topViewController]; | |
[self.documentsDetailsVC view]; | |
} | |
else { | |
self.sut = (DocumentsBrowserVC *)navController.topViewController; | |
} | |
[self.sut view]; | |
} | |
- (void)tearDown | |
{ | |
objc_removeAssociatedObjects(_sut); | |
_sut = nil; | |
[super tearDown]; | |
} | |
- (void)test_testForCorrectlyManuallyTriggeredSegue | |
{ | |
[YourViewControllerTest swapInstanceMethodsForClass:[YourViewController class] | |
selector:realPrepareForSegue | |
andSelector:testPrepareForSegue]; | |
// when | |
[self.sut performSelector:@selector(theMethodWhichDecidesAboutWhichSegueToTrigger:) withObject:nil]; | |
// then | |
assertThat(NSStringFromClass([objc_getAssociatedObject(self.sut, storyboardSegueKey) class]), is(equalTo(@"UIStoryboardModalSegue"))); | |
assertThatBool([[objc_getAssociatedObject(self.sut, storyboardSegueKey) destinationViewController] isKindOfClass:[YourDestionationViewController class]], is(equalToBool(TRUE))); | |
assertThat(objc_getAssociatedObject(self.sut, senderKey), is(equalTo(self.sut))); | |
[DocumentsBrowserTest swapInstanceMethodsForClass:[DocumentsBrowserVC class] | |
selector:realPrepareForSegue | |
andSelector:testPrepareForSegue]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment