Skip to content

Commit 77d1692

Browse files
author
aquarioverde
committed
unit testing - SenTesting & Kiwi
1 parent 9f96d8a commit 77d1692

File tree

128 files changed

+8926
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

128 files changed

+8926
-0
lines changed

HelloNSCoder.xcodeproj/project.pbxproj

Lines changed: 388 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
//
2+
// NCEventLoaderTestSpec.m
3+
// HelloNSCoder
4+
//
5+
// Created by Pedro Santos on 5/25/11.
6+
// Copyright 2011 NSCoder_BCN. All rights
7+
8+
#import "NCArrayEventLoader.h"
9+
#import "NCEventLoaderDelegate.h"
10+
11+
#import "Kiwi.h"
12+
13+
SPEC_BEGIN(NCEventLoaderTestSpec)
14+
15+
describe(@"NCEventLoader", ^{
16+
context(@"when loadind data, delegate", ^{
17+
__block NCArrayEventLoader* eventLoader;
18+
__block id delegateMock;
19+
20+
beforeEach(^{
21+
delegateMock = [KWMock mockForProtocol:@protocol(NCEventLoaderDelegate)];
22+
});
23+
24+
afterEach(^{
25+
delegateMock = nil;
26+
});
27+
28+
it(@"will be called when finished loading from a provided nil array of events.", ^{
29+
30+
eventLoader = [[NCArrayEventLoader alloc] initWithEventList:nil];
31+
32+
[[[delegateMock should] receive] didFinishUpdatingData:nil];
33+
34+
eventLoader.delegate = delegateMock;
35+
[eventLoader loadEvents];
36+
});
37+
38+
it(@"will be called when finished loading from a provided empty array of events.", ^{
39+
NSMutableArray* eventList = [[NSMutableArray alloc] initWithObjects:(nil)];
40+
41+
eventLoader = [[NCArrayEventLoader alloc] initWithEventList:eventList];
42+
43+
[[[delegateMock should] receive] didFinishUpdatingData:[[NSArray alloc] init]];
44+
45+
eventLoader.delegate = delegateMock;
46+
[eventLoader loadEvents];
47+
});
48+
49+
it(@"will not be called if not set.", ^{
50+
51+
NCArrayEventLoader* eventLoader = [[NCArrayEventLoader alloc] initWithEventList:nil];
52+
53+
[[[delegateMock shouldNot] receive] didFinishUpdatingData:nil];
54+
55+
//eventLoader.delegate = delegateMock;
56+
[eventLoader loadEvents];
57+
});
58+
});
59+
60+
});
61+
62+
SPEC_END
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
//
2+
// NCEventTests.m
3+
// HelloNSCoder
4+
//
5+
// Created by Pedro Santos on 5/25/11.
6+
// Copyright 2011 NSCoder_BCN. All rights reserved.
7+
//
8+
9+
#import <SenTestingKit/SenTestingKit.h>
10+
#import "NCEvent.h"
11+
12+
@interface NCEventTests : SenTestCase {
13+
14+
NCEvent *instance;
15+
}
16+
17+
@end
18+
@implementation NCEventTests
19+
20+
- (void)setUp {
21+
[super setUp];
22+
23+
instance = [[NCEvent alloc] init];
24+
}
25+
26+
- (void)tearDown {
27+
28+
[instance release];
29+
instance = nil;
30+
31+
[super tearDown];
32+
}
33+
34+
- (void)testCanCreateInstance {
35+
36+
STAssertNotNil(instance, @"Cannot create instance");
37+
}
38+
39+
- (void)testCanSetName {
40+
instance.name = @"Test";
41+
42+
STAssertEquals(instance.name, @"Test", @"Cannot set name");
43+
}
44+
45+
- (void)testCanSetShortDescription {
46+
instance.shortDescription = @"Test";
47+
48+
STAssertEquals(instance.shortDescription, @"Test", @"Cannot set short description");
49+
}
50+
51+
- (void)testCanSetShortStartDate {
52+
NSDate* testDate = [NSDate date];
53+
instance.startDate = testDate;
54+
55+
STAssertEquals(instance.startDate, testDate, @"Cannot set start date");
56+
}
57+
58+
- (void)testCanSetShortLocation {
59+
instance.location = @"Test";
60+
61+
STAssertEquals(instance.location, @"Test", @"Cannot set short location");
62+
}
63+
64+
- (void)testCanSetShortFullDescription {
65+
instance.fullDescription = @"Test";
66+
67+
STAssertEquals(instance.fullDescription, @"Test", @"Cannot set full description");
68+
}
69+
70+
- (void)testCanSetShortLongitude {
71+
instance.longitude = 99.9f;
72+
73+
STAssertEquals(instance.longitude, 99.9f, @"Cannot set longitude");
74+
}
75+
76+
- (void)testCanSetShortLatitude {
77+
instance.latitude = 99.9f;
78+
79+
STAssertEquals(instance.latitude, 99.9f, @"Cannot set latitude");
80+
}
81+
82+
@end
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//
2+
// Licensed under the terms in License.txt
3+
//
4+
// Copyright 2010 Allen Ding. All rights reserved.
5+
//
6+
7+
#import "KiwiConfiguration.h"
8+
#import "KWBlockNode.h"
9+
#import "KWExampleNode.h"
10+
11+
#if KW_BLOCKS_ENABLED
12+
13+
@interface KWAfterAllNode : KWBlockNode<KWExampleNode>
14+
15+
#pragma mark -
16+
#pragma mark Initializing
17+
18+
+ (id)afterAllNodeWithCallSite:(KWCallSite *)aCallSite block:(KWVoidBlock)aBlock;
19+
20+
@end
21+
22+
#endif // #if KW_BLOCKS_ENABLED
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
//
2+
// Licensed under the terms in License.txt
3+
//
4+
// Copyright 2010 Allen Ding. All rights reserved.
5+
//
6+
7+
#import "KWAfterAllNode.h"
8+
#import "KWExampleNodeVisitor.h"
9+
10+
#if KW_BLOCKS_ENABLED
11+
12+
@implementation KWAfterAllNode
13+
14+
#pragma mark -
15+
#pragma mark Initializing
16+
17+
+ (id)afterAllNodeWithCallSite:(KWCallSite *)aCallSite block:(KWVoidBlock)aBlock {
18+
return [[[self alloc] initWithCallSite:aCallSite description:nil block:aBlock] autorelease];
19+
}
20+
21+
#pragma mark -
22+
#pragma mark Accepting Visitors
23+
24+
- (void)acceptExampleNodeVisitor:(id<KWExampleNodeVisitor>)aVisitor {
25+
[aVisitor visitAfterAllNode:self];
26+
}
27+
28+
@end
29+
30+
#endif // #if KW_BLOCKS_ENABLED
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//
2+
// Licensed under the terms in License.txt
3+
//
4+
// Copyright 2010 Allen Ding. All rights reserved.
5+
//
6+
7+
#import "KiwiConfiguration.h"
8+
#import "KWBlockNode.h"
9+
#import "KWExampleNode.h"
10+
11+
#if KW_BLOCKS_ENABLED
12+
13+
@interface KWAfterEachNode : KWBlockNode<KWExampleNode>
14+
15+
#pragma mark -
16+
#pragma mark Initializing
17+
18+
+ (id)afterEachNodeWithCallSite:(KWCallSite *)aCallSite block:(KWVoidBlock)aBlock;
19+
20+
@end
21+
22+
#endif // #if KW_BLOCKS_ENABLED
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
//
2+
// Licensed under the terms in License.txt
3+
//
4+
// Copyright 2010 Allen Ding. All rights reserved.
5+
//
6+
7+
#import "KWAfterEachNode.h"
8+
#import "KWExampleNodeVisitor.h"
9+
10+
#if KW_BLOCKS_ENABLED
11+
12+
@implementation KWAfterEachNode
13+
14+
#pragma mark -
15+
#pragma mark Initializing
16+
17+
+ (id)afterEachNodeWithCallSite:(KWCallSite *)aCallSite block:(KWVoidBlock)aBlock {
18+
return [[[self alloc] initWithCallSite:aCallSite description:nil block:aBlock] autorelease];
19+
}
20+
21+
#pragma mark -
22+
#pragma mark Accepting Visitors
23+
24+
- (void)acceptExampleNodeVisitor:(id<KWExampleNodeVisitor>)aVisitor {
25+
[aVisitor visitAfterEachNode:self];
26+
}
27+
28+
@end
29+
30+
#endif // #if KW_BLOCKS_ENABLED
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//
2+
// Licensed under the terms in License.txt
3+
//
4+
// Copyright 2010 Allen Ding. All rights reserved.
5+
//
6+
7+
#import "KiwiConfiguration.h"
8+
#import "KWMatcher.h"
9+
10+
@interface KWBeBetweenMatcher : KWMatcher {
11+
@private
12+
id lowerEndpoint;
13+
id upperEndpoint;
14+
}
15+
16+
#pragma mark -
17+
#pragma mark Configuring Matchers
18+
19+
// TODO: 'and' below is a reserved word in C++
20+
- (void)beBetween:(id)aLowerEndpoint and:(id)anUpperEndpoint;
21+
- (void)beInTheIntervalFrom:(id)aLowerEndpoint to:(id)anUpperEndpoint;
22+
23+
@end
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
//
2+
// Licensed under the terms in License.txt
3+
//
4+
// Copyright 2010 Allen Ding. All rights reserved.
5+
//
6+
7+
#import "KWBeBetweenMatcher.h"
8+
#import "KWFormatter.h"
9+
10+
@interface KWBeBetweenMatcher()
11+
12+
#pragma mark -
13+
#pragma mark Properties
14+
15+
@property (nonatomic, readwrite, retain) id lowerEndpoint;
16+
@property (nonatomic, readwrite, retain) id upperEndpoint;
17+
18+
@end
19+
20+
@implementation KWBeBetweenMatcher
21+
22+
#pragma mark -
23+
#pragma mark Initializing
24+
25+
- (void)dealloc {
26+
[lowerEndpoint release];
27+
[upperEndpoint release];
28+
[super dealloc];
29+
}
30+
31+
#pragma mark -
32+
#pragma mark Properties
33+
34+
@synthesize lowerEndpoint;
35+
@synthesize upperEndpoint;
36+
37+
#pragma mark -
38+
#pragma mark Getting Matcher Strings
39+
40+
+ (NSArray *)matcherStrings {
41+
return [NSArray arrayWithObjects:@"beBetween:and:", @"beInTheIntervalFrom:to:", nil];
42+
}
43+
44+
#pragma mark -
45+
#pragma mark Matching
46+
47+
- (BOOL)evaluate {
48+
if (![self.subject respondsToSelector:@selector(compare:)])
49+
[NSException raise:@"KWMatcherException" format:@"subject does not respond to -compare:"];
50+
51+
NSComparisonResult lowerResult = [self.subject compare:self.lowerEndpoint];
52+
NSComparisonResult upperResult = [self.subject compare:self.upperEndpoint];
53+
return (lowerResult == NSOrderedDescending || lowerResult == NSOrderedSame) &&
54+
(upperResult == NSOrderedAscending || upperResult == NSOrderedSame);
55+
}
56+
57+
#pragma mark -
58+
#pragma mark Getting Failure Messages
59+
60+
- (NSString *)failureMessageForShould {
61+
return [NSString stringWithFormat:@"expected subject to be in the interval [%@, %@], got %@",
62+
[KWFormatter formatObject:self.lowerEndpoint],
63+
[KWFormatter formatObject:self.upperEndpoint],
64+
[KWFormatter formatObject:self.subject]];
65+
}
66+
67+
#pragma mark -
68+
#pragma mark Configuring Matchers
69+
70+
- (void)beBetween:(id)aLowerEndpoint and:(id)anUpperEndpoint {
71+
[self beInTheIntervalFrom:aLowerEndpoint to:anUpperEndpoint];
72+
}
73+
74+
- (void)beInTheIntervalFrom:(id)aLowerEndpoint to:(id)anUpperEndpoint {
75+
self.lowerEndpoint = aLowerEndpoint;
76+
self.upperEndpoint = anUpperEndpoint;
77+
}
78+
79+
@end
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//
2+
// Licensed under the terms in License.txt
3+
//
4+
// Copyright 2010 Allen Ding. All rights reserved.
5+
//
6+
7+
#import "KiwiConfiguration.h"
8+
#import "KWMatcher.h"
9+
10+
@interface KWBeEmptyMatcher : KWMatcher {
11+
@private
12+
NSUInteger count;
13+
}
14+
15+
#pragma mark -
16+
#pragma mark Configuring Matchers
17+
18+
- (void)beEmpty;
19+
20+
@end

0 commit comments

Comments
 (0)