This repository has been archived by the owner on Mar 29, 2018. It is now read-only.
forked from kiwi-bdd/Kiwi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ExampleSpec.m
91 lines (71 loc) · 2.87 KB
/
ExampleSpec.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
79
80
81
82
83
84
85
86
87
88
89
90
91
//
// Licensed under the terms in License.txt
//
// Copyright 2010 Allen Ding. All rights reserved.
//
#import "KiwiTestConfiguration.h"
#import "TestClasses.h"
#import "Kiwi.h"
/**
* Due to the way the compiler works, in order to call dynamically created
* methods (like our custom matchers) directly without using performSelector:,
* the compiler needs to know that the method exists.
*
* We can encapsulate this requirement in a simple macro to forward-declare
* our custom matchers.
*/
registerMatcher(haveFighters)
#if KW_TESTS_ENABLED && KW_BLOCKS_ENABLED
SPEC_BEGIN(ExampleSpec)
describe(@"Cruiser", ^{
registerMatchers(@"KWT");
context(@"with fighters set", ^{
__block Cruiser *cruiser = nil;
beforeAll(^{
});
afterAll(^{
});
beforeEach(^{
cruiser = [Cruiser cruiser];
[cruiser stub:@selector(raiseShields) andReturn:theValue(NO)];
[cruiser setFighters:[NSArray arrayWithObjects:[Fighter fighterWithCallsign:@"Viper 1"],
[Fighter fighterWithCallsign:@"Viper 2"],
[Fighter fighterWithCallsign:@"Viper 3"], nil]];
});
pending(@"should be really big", nil);
it(@"should have fighters", ^{
[[[cruiser should] have:3] fighters];
[[cruiser.fighters shouldNot] beEmpty];
[Cruiser stub:@selector(classification) andReturn:@"Animal"];
});
it(@"should raise shields", ^{
[[[Cruiser classification] should] equal:@"Capital Ship"];
[[theValue([cruiser raiseShields]) should] beFalse];
[[cruiser should] receive:@selector(fighterWithCallsign:)];
[cruiser fighterWithCallsign:@"Apollo"];
});
it(@"should raise if asked", ^{
[[[Cruiser classification] should] equal:@"Capital Ship"];
[[lambda(^{
[cruiser raiseWithName:@"FooException" description:@"Foo"];
}) should] raiseWithName:@"FooException"];
});
defineMatcher(@"haveFighters", ^(KWUserDefinedMatcherBuilder *builder) {
[builder match:^(id subject) {
if (![subject isKindOfClass:[Cruiser class]]) {
return NO;
}
Cruiser *cruiser = subject;
return cruiser.fighters.count > 0;
}];
[builder failureMessageForShould:^(id subject) {
return [NSString stringWithFormat:@"%@ should have fighters", subject];
}];
});
it(@"should have fighters (using custom matcher)", ^{
[[cruiser should] haveFighters];
});
});
});
SPEC_END
#endif // #if KW_TESTS_ENABLED && KW_BLOCKS_ENABLED