This repository has been archived by the owner on Dec 2, 2019. It is now read-only.
forked from specta/expecta
/
EXPMatchers+raiseWithReasonTest.m
44 lines (34 loc) · 1.82 KB
/
EXPMatchers+raiseWithReasonTest.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
#import "TestHelper.h"
@interface EXPMatchers_raiseWithReasonTest : SenTestCase
@end
@implementation EXPMatchers_raiseWithReasonTest
- (void)test_raiseWithReason {
assertPass(test_expect(^{
[NSException raise:@"TestException" format:@"This is the reason"];
}).to.raiseWithReason(@"TestException", @"This is the reason"));
assertFail(test_expect(^{
// not raising...
}).to.raiseWithReason(@"TestException", @"This is the reason"), @"expected: TestException (This is the reason), got: no exception ()");
assertFail(test_expect(^{
NSException *exception = [NSException exceptionWithName:@"AnotherException" reason:@"This is the reason" userInfo:nil];
[exception raise];
}).to.raiseWithReason(@"TestException", @"This is the reason"), @"expected: TestException (This is the reason), got: AnotherException (This is the reason)");
}
- (void)test_toNot_raiseWithReason {
assertFail(test_expect(^{
[NSException raise:@"TestException" format:@"This is the reason"];
}).notTo.raiseWithReason(@"TestException", @"This is the reason"), @"expected: not TestException (not 'This is the reason'), got: TestException (This is the reason)");
assertPass(test_expect(^{
// Different reason text than expected
[NSException raise:@"TestException" format:@"A different reason"];
}).notTo.raiseWithReason(@"TestException", @"This is the reason"));
assertPass(test_expect(^{
// not raising...
}).notTo.raiseWithReason(@"TestException", @"This is the reason"));
assertPass(test_expect(^{
// Different exception class
NSException *exception = [NSException exceptionWithName:@"AnotherException" reason:nil userInfo:nil];
[exception raise];
}).notTo.raiseWithReason(@"TestException", @"This is the reason"));
}
@end