I think I know very basics of Objective-C for objective way.
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
| using namespace Cedar::Matchers;
using namespace Cedar::Doubles;
@interface Greeter : NSObject
- (id)initWithName:(NSString *)name;
- (NSString *)sayHello;
@property (copy) NSString *name;
@property (assign) NSString *helloWord;
@end
@interface Greeter ()
- (void)setWord;
@end
@implementation Greeter
- (id)initWithName:(NSString *)name {
self = [super init];
self.name = name;
return self;
}
- (NSString *)sayHello {
[self setWord];
return self.helloWord;
}
- (void)setWord {
NSMutableString *word = [NSMutableString stringWithString:@"hello"];
if (self.name != nil) {
[word appendString:@", "];
[word appendString:self.name];
} else {
[word appendString:@" !"];
}
self.helloWord = word;
}
@end
SPEC_BEGIN(Sandbox)
describe (@"Greeter", ^{
it (@"can be initialized with name", ^{
Greeter *man = [[Greeter alloc] initWithName:@"shin1ohno"];
man.name should equal(@"shin1ohno");
[man sayHello] should equal(@"hello, shin1ohno");
});
it (@"says hello", ^{
Greeter *man = [[Greeter alloc] init];
[man sayHello] should equal(@"hello !");
});
});
SPEC_END
|