Skip to content

Commit 51afbff

Browse files
authored
Merge pull request #581 from Quick/refactor-postnotifications-matcher
[7.x] Refactor `postNotifications` matcher using `Predicate.init`
2 parents 470bc20 + 32390fd commit 51afbff

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

Sources/Nimble/Matchers/PostNotification.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ public func postNotifications<T>(
7474
let collector = NotificationCollector(notificationCenter: center)
7575
collector.startObserving()
7676
var once: Bool = false
77-
return Predicate.fromDeprecatedClosure { actualExpression, failureMessage in
77+
78+
return Predicate { actualExpression in
7879
let collectorNotificationsExpression = Expression(memoizedExpression: { _ in
7980
return collector.observedNotifications
8081
}, location: actualExpression.location, withoutCaching: true)
@@ -85,12 +86,13 @@ public func postNotifications<T>(
8586
_ = try actualExpression.evaluate()
8687
}
8788

89+
let failureMessage = FailureMessage()
8890
let match = try notificationsMatcher.matches(collectorNotificationsExpression, failureMessage: failureMessage)
8991
if collector.observedNotifications.isEmpty {
9092
failureMessage.actualValue = "no notifications"
9193
} else {
9294
failureMessage.actualValue = "<\(stringify(collector.observedNotifications))>"
9395
}
94-
return match
96+
return PredicateResult(bool: match, message: failureMessage.toExpectationMessage())
9597
}
9698
}

0 commit comments

Comments
 (0)