3

Is there some reason my Kiwi unit tests are failing with these two lines:

[[theValue([editAuthorViewController class] == [EditAuthorViewController class]) should] beYes];

[[theValue([editAuthorViewController isKindOfClass:[EditAuthorViewController class]]) should] beYes];

While this line passes?

NSString *classString = NSStringFromClass([editAuthorViewController class]);
[[classString should] equal:@"EditAuthorViewController"];
Mike Buss
  • 980
  • 9
  • 25

1 Answers1

6

Turns out there's a Kiwi expression to test this I wasn't aware of.

[[editAuthorViewController should] beKindOfClass:[EditAuthorViewController class]];

This failed initially because my EditAuthorViewController.m file was added to my test target. Since [EditAuthorViewController class] was returning a different pointer when called from inside the test bundle, the comparison failed.

To fix this, I had to remove EditAuthorViewController.m from my Compile Sources in my test target.

Mike Buss
  • 980
  • 9
  • 25
  • I haven't ever used Kiwi, but from what I infer from above... it should work as isKindOfClass returns a BOOL, same as the above line. – Grady Player Dec 22 '13 at 06:39
  • I was able to get all of the above lines working by removing `EditAuthorViewController.m` from my Compile Sources in my test target. There's a great explanation of the problem and solution here: http://www.objc.io/issue-1/testing-view-controllers.html under "Side Note About Classes and Injection". – Mike Buss Dec 23 '13 at 05:44