-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathNSArray+Shoulda.m
64 lines (52 loc) · 1.38 KB
/
NSArray+Shoulda.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
//
// NSArray+Shoulda.m
// Headlights
//
// Created by Saul Mora on 7/4/10.
// Copyright 2010 Magical Panda Software LLC. All rights reserved.
//
#import "NSArray+Shoulda.h"
@implementation NSArray (Shoulda)
- (void) shouldContain:(id)expectedObject withReason:(NSString *)reason
{
[self runTestCase:(TestBlock)^{
return expectedObject != nil && [self containsObject:expectedObject];
} withDescription:(ExpressionBlock)^{
return [NSString stringWithFormat:@"%@ should contain %@", self, expectedObject];
} andReason:reason];
}
- (void) shouldBeEmptyWithReason:(NSString *)reason;
{
[self runTestCase:(TestBlock)^{
return [self count] == 0;
} withDescription:(ExpressionBlock)^{
return [NSString stringWithFormat:@"%@ should be empty", self];
} andReason:reason];
}
- (void) shouldNotBeEmptyWithReason:(NSString *)reason;
{
[self runTestCase:(TestBlock)^{
return [self count] > 0;
} withDescription:(ExpressionBlock)^{
return [NSString stringWithFormat:@"%@ should NOT be empty", self];
} andReason:reason];
}
- (NSNumber *) itemCount
{
return [NSNumber numberWithInt:[self count]];
}
@end
@implementation NSArray (SimpleShoulda)
- (void) shouldContain:(id)expectedObject;
{
[self shouldContain:expectedObject withReason:@""];
}
- (void) shouldBeEmpty;
{
[self shouldBeEmptyWithReason:@""];
}
- (void) shouldNotBeEmpty;
{
[self shouldNotBeEmptyWithReason:@""];
}
@end