From abcb408c6db6dfd19b5dc473acd9fdb6f28fc0d9 Mon Sep 17 00:00:00 2001 From: Sho Ikeda Date: Wed, 5 Jun 2019 10:13:28 +0900 Subject: [PATCH] Replace deprecated `Predicate.matches(_:failureMessage:)` and `Predicate.doesNotMatch(_:failureMessage:)` --- Sources/Nimble/Matchers/BeCloseTo.swift | 12 ++++++++---- Sources/Nimble/Matchers/PostNotification.swift | 14 +++++++++----- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/Sources/Nimble/Matchers/BeCloseTo.swift b/Sources/Nimble/Matchers/BeCloseTo.swift index d6fd1eed6..c82d1972e 100644 --- a/Sources/Nimble/Matchers/BeCloseTo.swift +++ b/Sources/Nimble/Matchers/BeCloseTo.swift @@ -51,10 +51,12 @@ public class NMBObjCBeCloseToMatcher: NSObject, NMBMatcher { return actualExpression() as? NMBDoubleConvertible }) let expr = Expression(expression: actualBlock, location: location) - let matcher = beCloseTo(self._expected, within: self._delta) + let predicate = beCloseTo(self._expected, within: self._delta) do { - return try matcher.matches(expr, failureMessage: failureMessage) + let result = try predicate.satisfies(expr) + result.message.update(failureMessage: failureMessage) + return result.toBoolean(expectation: .toMatch) } catch let error { failureMessage.stringValue = "unexpected error thrown: <\(error)>" return false @@ -66,10 +68,12 @@ public class NMBObjCBeCloseToMatcher: NSObject, NMBMatcher { return actualExpression() as? NMBDoubleConvertible }) let expr = Expression(expression: actualBlock, location: location) - let matcher = beCloseTo(self._expected, within: self._delta) + let predicate = beCloseTo(self._expected, within: self._delta) do { - return try matcher.doesNotMatch(expr, failureMessage: failureMessage) + let result = try predicate.satisfies(expr) + result.message.update(failureMessage: failureMessage) + return result.toBoolean(expectation: .toNotMatch) } catch let error { failureMessage.stringValue = "unexpected error thrown: <\(error)>" return false diff --git a/Sources/Nimble/Matchers/PostNotification.swift b/Sources/Nimble/Matchers/PostNotification.swift index 6ec3c0268..5e8bee3d5 100644 --- a/Sources/Nimble/Matchers/PostNotification.swift +++ b/Sources/Nimble/Matchers/PostNotification.swift @@ -51,14 +51,18 @@ public func postNotifications( _ = try actualExpression.evaluate() } - let failureMessage = FailureMessage() - let match = try predicate.matches(collectorNotificationsExpression, failureMessage: failureMessage) + let actualValue: String if collector.observedNotifications.isEmpty { - failureMessage.actualValue = "no notifications" + actualValue = "no notifications" } else { - failureMessage.actualValue = "<\(stringify(collector.observedNotifications))>" + actualValue = "<\(stringify(collector.observedNotifications))>" } - return PredicateResult(bool: match, message: failureMessage.toExpectationMessage()) + + var result = try predicate.satisfies(collectorNotificationsExpression) + result.message = result.message.replacedExpectation { message in + return .expectedCustomValueTo(message.expectedMessage, actualValue) + } + return result } }