This repository has been archived by the owner on Dec 2, 2019. It is now read-only.
forked from specta/expecta
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'petejkim/master'
- Loading branch information
Showing
11 changed files
with
127 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#import "Expecta.h" | ||
|
||
EXPMatcherInterface(raiseWithReason, (NSString *expectedExceptionName, NSString *expectedReason)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#import "EXPMatchers+raiseWithReason.h" | ||
#import "EXPDefines.h" | ||
|
||
EXPMatcherImplementationBegin(raiseWithReason, (NSString *expectedExceptionName, NSString *expectedReason)) { | ||
__block NSException *exceptionCaught = nil; | ||
|
||
match(^BOOL{ | ||
BOOL expectedExceptionCaught = NO; | ||
@try { | ||
((EXPBasicBlock)actual)(); | ||
} @catch(NSException *e) { | ||
exceptionCaught = e; | ||
expectedExceptionCaught = (((expectedExceptionName == nil) || [[exceptionCaught name] isEqualToString:expectedExceptionName]) && | ||
((expectedReason == nil) || ([[exceptionCaught reason] isEqualToString:expectedReason]))); | ||
} | ||
return expectedExceptionCaught; | ||
}); | ||
|
||
failureMessageForTo(^NSString *{ | ||
return [NSString stringWithFormat:@"expected: %@ (%@), got: %@ (%@)", | ||
expectedExceptionName ?: @"any exception", | ||
expectedReason ?: @"any reason", | ||
exceptionCaught ? [exceptionCaught name] : @"no exception", | ||
exceptionCaught ? [exceptionCaught reason] : @""]; | ||
}); | ||
|
||
failureMessageForNotTo(^NSString *{ | ||
return [NSString stringWithFormat:@"expected: %@ (%@), got: %@ (%@)", | ||
expectedExceptionName ? [NSString stringWithFormat:@"not %@", expectedExceptionName] : @"no exception", | ||
expectedReason ? [NSString stringWithFormat:@"not '%@'", expectedReason] : @"no reason", | ||
exceptionCaught ? [exceptionCaught name] : @"no exception", | ||
exceptionCaught ? [exceptionCaught reason] : @"no reason"]; | ||
}); | ||
} | ||
EXPMatcherImplementationEnd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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 |