KWBeTrueMatcher.m 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. //
  2. // Licensed under the terms in License.txt
  3. //
  4. // Copyright 2010 Allen Ding. All rights reserved.
  5. //
  6. #import "KWBeTrueMatcher.h"
  7. @interface KWBeTrueMatcher()
  8. @property (nonatomic, readwrite) BOOL expectedValue;
  9. @end
  10. @implementation KWBeTrueMatcher
  11. #pragma mark - Getting Matcher Strings
  12. + (NSArray *)matcherStrings {
  13. return @[@"beTrue", @"beFalse", @"beYes", @"beNo"];
  14. }
  15. #pragma mark - Matching
  16. - (BOOL)evaluate {
  17. if (![self.subject respondsToSelector:@selector(boolValue)])
  18. [NSException raise:@"KWMatcherException" format:@"subject does not respond to -boolValue"];
  19. return [self.subject boolValue] == self.expectedValue;
  20. }
  21. #pragma mark - Getting Failure Messages
  22. - (NSString *)failureMessageForShould {
  23. return [NSString stringWithFormat:@"expected subject to be %@",
  24. self.expectedValue ? @"true" : @"false"];
  25. }
  26. - (NSString *)description {
  27. if (self.expectedValue == YES) {
  28. return @"be true";
  29. }
  30. return @"be false";
  31. }
  32. #pragma mark - Configuring Matchers
  33. - (void)beTrue {
  34. self.expectedValue = YES;
  35. }
  36. - (void)beFalse {
  37. self.expectedValue = NO;
  38. }
  39. - (void)beYes {
  40. self.expectedValue = YES;
  41. }
  42. - (void)beNo {
  43. self.expectedValue = NO;
  44. }
  45. @end