Staged allows you to easily mock View Controllers presentations and dismissals, so you don't have to create a window just to test them.
Just import #import <Staged/STGViewControllerVerifier.h>
and use like this:
STGViewControllerVerifier *verifier = [[STGViewControllerVerifier alloc] init];
UIViewController *viewController = [[UIViewController alloc] init];
// sut is the system under test
[sut presentSomeOtherControllerOn:viewController];
expect(verifier.presenterViewController).to.equal(viewController);
expect(verifier.presentedViewController).to.beKindOf([SomeCoolViewController class]);
expect(verifier.presentedAnimated).to.beTruthy();
expect(verifier.presentedCount).to.equal(1);
This is using Expecta matchers, but you can be boring and use the default ones as well.
You can also check if a view controller was dismissed:
STGViewControllerVerifier *verifier = [[STGViewControllerVerifier alloc] init];
[sut doSomethingThatShouldDismissAViewController];
expect(verifier.dismissedViewController).to.beKindOf([SomeCoolViewController class]);
expect(verifier.dimissedAnimated).to.beFalsy();
expect(verifier.dismissedCount).to.equal(1);
iOS 8
Staged is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod "Staged"
Marcelo Fabri, @marcelofabri_
- Jon Reid for creating MockUIAlertController, from which I borrowed the idea and the initial implementation.
Please submit an issue on GitHub and provide information about your setup.
Staged is available under the MIT license. See the LICENSE file for more info.