main
1//
2// Licensed under the terms in License.txt
3//
4// Copyright 2010 Allen Ding. All rights reserved.
5//
6
7#import "KWBeTrueMatcher.h"
8
9@interface KWBeTrueMatcher()
10
11#pragma mark -
12#pragma mark Properties
13
14@property (nonatomic, readwrite) BOOL expectedValue;
15
16@end
17
18@implementation KWBeTrueMatcher
19
20#pragma mark -
21#pragma mark Properties
22
23@synthesize expectedValue;
24
25#pragma mark -
26#pragma mark Getting Matcher Strings
27
28+ (NSArray *)matcherStrings {
29 return @[@"beTrue", @"beFalse", @"beYes", @"beNo"];
30}
31
32#pragma mark -
33#pragma mark Matching
34
35- (BOOL)evaluate {
36 if (![self.subject respondsToSelector:@selector(boolValue)])
37 [NSException raise:@"KWMatcherException" format:@"subject does not respond to -boolValue"];
38
39 return [self.subject boolValue] == self.expectedValue;
40}
41
42#pragma mark -
43#pragma mark Getting Failure Messages
44
45- (NSString *)failureMessageForShould {
46 return [NSString stringWithFormat:@"expected subject to be %@",
47 expectedValue ? @"true" : @"false"];
48}
49
50- (NSString *)description
51{
52 if (self.expectedValue == YES) {
53 return @"be true";
54 }
55 return @"be false";
56}
57
58#pragma mark -
59#pragma mark Configuring Matchers
60
61- (void)beTrue {
62 self.expectedValue = YES;
63}
64
65- (void)beFalse {
66 self.expectedValue = NO;
67}
68
69- (void)beYes {
70 self.expectedValue = YES;
71}
72
73- (void)beNo {
74 self.expectedValue = NO;
75}
76
77@end