This repository has been archived by the owner on Aug 17, 2019. It is now read-only.
forked from kiwi-bdd/Kiwi
/
KWCaptureTest.m
76 lines (54 loc) · 2.24 KB
/
KWCaptureTest.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
//
// Licensed under the terms in License.txt
//
// Copyright 2010 Allen Ding. All rights reserved.
//
#import "Kiwi.h"
#import "KiwiTestConfiguration.h"
#import "TestClasses.h"
#import "KWIntercept.h"
#import "NSMethodSignature+KiwiAdditions.h"
#import "KWMock.h"
#if KW_TESTS_ENABLED
@interface KWCaptureTest : SenTestCase
@end
@implementation KWCaptureTest
- (void)testShouldBeAbleToCaptureBlocks {
id robotMock = [KWMock nullMockForClass:[Robot class]];
KWCaptureSpy *spy = [robotMock captureArgument:@selector(speak:afterDelay:whenDone:) atIndex:2];
__block BOOL didCall = NO;
[robotMock speak:@"Hello" afterDelay:2 whenDone:^{
didCall = YES;
}];
void (^block)(void) = spy.argument;
block();
STAssertTrue(didCall, @"Should have captured and invoked block");
}
- (void)testShouldBeAbleToCaptureObjects {
id robotMock = [KWMock nullMockForClass:[Robot class]];
KWCaptureSpy *spy = [robotMock captureArgument:@selector(speak:afterDelay:whenDone:) atIndex:0];
[robotMock speak:@"Hello" afterDelay:2 whenDone:^{}];
STAssertEqualObjects(spy.argument, @"Hello", @"Captured argument should be equal to 'Hello'");
}
- (void)testShouldBeAbleToCaptureValues {
id robotMock = [KWMock nullMockForClass:[Robot class]];
KWCaptureSpy *spy = [robotMock captureArgument:@selector(speak:afterDelay:whenDone:) atIndex:1];
[robotMock speak:@"Hello" afterDelay:2 whenDone:^{}];
STAssertEqualObjects(spy.argument, [KWValue valueWithDouble:2], @"Captured argument should be equal to '2'");
}
- (void)testShouldBeAbleToCaptureNils {
id robotMock = [KWMock nullMockForClass:[Robot class]];
KWCaptureSpy *spy = [robotMock captureArgument:@selector(speak:afterDelay:whenDone:) atIndex:0];
[robotMock speak:nil afterDelay:2 whenDone:^{}];
STAssertNil(spy.argument, @"Captured argument should be nil");
}
- (void)testShouldRaiseAnExceptionIfArgumentHasNotBeenCaptured {
id robotMock = [KWMock nullMockForClass:[Robot class]];
KWCaptureSpy *spy = [robotMock captureArgument:@selector(speak:afterDelay:whenDone:) atIndex:1];
STAssertThrows([spy argument], @"Should have raised an exception");
}
- (void)tearDown {
KWClearStubsAndSpies();
}
@end
#endif