forked from kiwi-bdd/Kiwi
/
KWExistVerifier.m
78 lines (61 loc) · 2.17 KB
/
KWExistVerifier.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
//
// Licensed under the terms in License.txt
//
// Copyright 2010 Allen Ding. All rights reserved.
//
#import "KWExistVerifier.h"
#import "KWFailure.h"
#import "KWFormatter.h"
#import "KWReporting.h"
@interface KWExistVerifier()
#pragma mark -
#pragma mark Properties
@property (nonatomic, readonly) KWExpectationType expectationType;
@property (nonatomic, readonly) KWCallSite *callSite;
@property (nonatomic, readonly) id<KWReporting> reporter;
@end
@implementation KWExistVerifier
#pragma mark -
#pragma mark Initializing
- (id)initWithExpectationType:(KWExpectationType)anExpectationType callSite:(KWCallSite *)aCallSite reporter:(id<KWReporting>)aReporter {
if ((self = [super init])) {
expectationType = anExpectationType;
callSite = [aCallSite retain];
reporter = aReporter;
}
return self;
}
+ (id)existVerifierWithExpectationType:(KWExpectationType)anExpectationType callSite:(KWCallSite *)aCallSite reporter:(id<KWReporting>)aReporter {
return [[[self alloc] initWithExpectationType:anExpectationType callSite:aCallSite reporter:aReporter] autorelease];
}
- (void)dealloc {
[callSite release];
[subject release];
[super dealloc];
}
- (NSString *)descriptionForAnonymousItNode
{
if (self.expectationType == KWExpectationTypeShould) {
return @"should exist";
}
return @"should not exist";
}
#pragma mark -
#pragma mark Properties
@synthesize expectationType;
@synthesize callSite;
@synthesize reporter;
@synthesize subject;
#pragma mark -
#pragma mark Ending Examples
- (void)exampleWillEnd {
if (self.expectationType == KWExpectationTypeShould && self.subject == nil) {
KWFailure *failure = [KWFailure failureWithCallSite:self.callSite message:@"expected subject not to be nil"];
[self.reporter reportFailure:failure];
} else if (self.expectationType == KWExpectationTypeShouldNot && self.subject != nil) {
KWFailure *failure = [KWFailure failureWithCallSite:self.callSite format:@"expected subject to be nil, got %@",
[KWFormatter formatObject:self.subject]];
[self.reporter reportFailure:failure];
}
}
@end