Skip to content

Commit

Permalink
Merge pull request #581 from Quick/refactor-postnotifications-matcher
Browse files Browse the repository at this point in the history
[7.x] Refactor `postNotifications` matcher using `Predicate.init`
  • Loading branch information
ikesyo authored Jul 28, 2018
2 parents 470bc20 + 32390fd commit 51afbff
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions Sources/Nimble/Matchers/PostNotification.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ public func postNotifications<T>(
let collector = NotificationCollector(notificationCenter: center)
collector.startObserving()
var once: Bool = false
return Predicate.fromDeprecatedClosure { actualExpression, failureMessage in

return Predicate { actualExpression in
let collectorNotificationsExpression = Expression(memoizedExpression: { _ in
return collector.observedNotifications
}, location: actualExpression.location, withoutCaching: true)
Expand All @@ -85,12 +86,13 @@ public func postNotifications<T>(
_ = try actualExpression.evaluate()
}

let failureMessage = FailureMessage()
let match = try notificationsMatcher.matches(collectorNotificationsExpression, failureMessage: failureMessage)
if collector.observedNotifications.isEmpty {
failureMessage.actualValue = "no notifications"
} else {
failureMessage.actualValue = "<\(stringify(collector.observedNotifications))>"
}
return match
return PredicateResult(bool: match, message: failureMessage.toExpectationMessage())
}
}

0 comments on commit 51afbff

Please sign in to comment.