Skip to content

Commit 515471b

Browse files
authored
Merge pull request #578 from Quick/refactor-raiseexception-matcher
[7.x] Refactor `raiseException` matcher using `Predicate.init`
2 parents 51afbff + 563cab8 commit 515471b

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

Sources/Nimble/Matchers/RaisesException.swift

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,17 @@ public func raiseException(
1717
reason: String? = nil,
1818
userInfo: NSDictionary? = nil,
1919
closure: ((NSException) -> Void)? = nil) -> Predicate<Any> {
20-
return Predicate.fromDeprecatedClosure { actualExpression, failureMessage in
21-
20+
return Predicate { actualExpression in
2221
var exception: NSException?
2322
let capture = NMBExceptionCapture(handler: ({ e in
2423
exception = e
2524
}), finally: nil)
2625

2726
capture.tryBlock {
2827
_ = try! actualExpression.evaluate()
29-
return
3028
}
3129

30+
let failureMessage = FailureMessage()
3231
setFailureMessageForException(
3332
failureMessage,
3433
exception: exception,
@@ -37,13 +36,15 @@ public func raiseException(
3736
userInfo: userInfo,
3837
closure: closure
3938
)
40-
return exceptionMatchesNonNilFieldsOrClosure(
39+
40+
let matches = exceptionMatchesNonNilFieldsOrClosure(
4141
exception,
4242
named: named,
4343
reason: reason,
4444
userInfo: userInfo,
4545
closure: closure
4646
)
47+
return PredicateResult(bool: matches, message: failureMessage.toExpectationMessage())
4748
}
4849
}
4950

0 commit comments

Comments
 (0)