title: Unit tests don't call viewDidAppear method
body: <p>I am using Specta to create some tests but I don't seem to be able to get this basic one to pass. The app itself works fine but this test won't pass.</p>
  
  <p><strong>ViewController</strong></p>
  
  <pre><code>- (void)viewDidAppear:(BOOL)animated {
      [super viewDidAppear:animated];
      [self showLogin];
  }
  
  - (void)showLogin
  {
      [self presentViewController:[ETLoginVC new] animated:NO completion:nil];
      NSLog(@"PresentedVC: %@", [self.presentedViewController class]);
  }
  </code></pre>
  
  <p>This logs: <code>PresentedVC: ETLoginVC</code></p>
  
  <p><strong>Specs</strong></p>
  
  <pre><code>#import "Specs.h"
  
  #import "ETLoadingVC.h"
  #import "ETLoginVC.h"
  
  SpecBegin(ETLoadingVCSpec)
  
  describe(@"ETLoadingVC", ^{
      __block ETLoadingVC *loadingVC;
  
      beforeEach(^{
          loadingVC = [[ETLoadingVC alloc] initWithUserDefaults:nil];
      });
  
      afterEach(^{
          loadingVC = nil;
      });
  
      describe(@"no current user present", ^{
          it(@"should have a login view controller as the presented view controller", ^{
              expect(loadingVC.presentedViewController).to.beKindOf([ETLoginVC class]);
          });
      });
  });
  
  SpecEnd
  </code></pre>
  
  <p>This fails with: <code>the actual value is nil/null</code></p>
  
  <p>I've tried calling:</p>
  
  <p><code>[loadingVC view]</code></p>
  
  <p>I've even initiated a <code>UIWindow</code> and an <code>appDelegate</code> but I just can't get it working.</p>
  
  <p>My view controller is all written in code. No storyboards or nibs.</p>
  
  <hr>
  
  <p><strong>UPDATE</strong></p>
  
  <p>For now i've added an <code>NSString</code> property that gets updated with the class name that is about to be presented. I then check this string in my test. To get this working though, I had to change my <code>beforeEach</code> block to the following:</p>
  
  <pre><code>beforeEach(^{
      loadingVC = [[ETLoadingVC alloc] initWithUserDefaults:nil];
      [loadingVC viewDidAppear:NO];
  });
  </code></pre>
  
  <p>Although the test passes, I get the following message:</p>
  
  <pre><code>Warning: Attempt to present &lt;ETLoginVC: 0x7fcf34961940&gt; on &lt;ETLoadingVC: 0x7fcf34961280&gt; whose view is not in the window hierarchy!
  </code></pre>
  
  <p>I get that this is because i'm calling <code>viewDidAppear</code> before the current view has finished appearing. What I don't get is how I can test this a better way.</p>
  
  <p>I also don't understand why <code>loadingVC.presentedViewController</code> still equals nil even with this updated <code>beforeEach</code> block.</p>
  
  <hr>
  
  <p><strong>UPDATE 2</strong></p>
  
  <p>Changing the <code>beforeEach</code> to the below got rid of the warning message and now the <code>presentedViewController</code> is set correctly.</p>
  
  <pre><code>beforeEach(^{
      mockUserDefaults = mock([NSUserDefaults class]);
      loadingVC = [[ETLoadingVC alloc] initWithUserDefaults:mockUserDefaults];
  
      window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
      window.rootViewController = loadingVC;
      [window makeKeyAndVisible];
  
      [loadingVC viewDidAppear:NO];
  });
  </code></pre>