Skip to content

Commit

Permalink
Merge pull request Quick#595 from Quick/replace-expressionMatches
Browse files Browse the repository at this point in the history
[7.x] Replace `expressionMatches` with `execute` in `to` and `toEventually`
  • Loading branch information
ikesyo authored Aug 19, 2018
2 parents c6fd742 + ecb2725 commit 17bd7dc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 23 deletions.
29 changes: 9 additions & 20 deletions Sources/Nimble/Expectation.swift
Original file line number Diff line number Diff line change
@@ -1,23 +1,5 @@
import Foundation

// Deprecated
internal func expressionMatches<T, U>(_ expression: Expression<T>, matcher: U, to: String, description: String?) -> (Bool, FailureMessage)
where U: Matcher, U.ValueType == T {
let msg = FailureMessage()
msg.userDescription = description
msg.to = to
do {
let pass = try matcher.matches(expression, failureMessage: msg)
if msg.actualValue == "" {
msg.actualValue = "<\(stringify(try expression.evaluate()))>"
}
return (pass, msg)
} catch let error {
msg.stringValue = "unexpected error thrown: <\(error)>"
return (false, msg)
}
}

// Deprecated
internal func expressionDoesNotMatch<T, U>(_ expression: Expression<T>, matcher: U, toNot: String, description: String?) -> (Bool, FailureMessage)
where U: Matcher, U.ValueType == T {
Expand Down Expand Up @@ -89,8 +71,15 @@ public struct Expectation<T> {
/// DEPRECATED: Tests the actual value using a matcher to match.
public func to<U>(_ matcher: U, description: String? = nil)
where U: Matcher, U.ValueType == T {
let (pass, msg) = expressionMatches(expression, matcher: matcher, to: "to", description: description)
verify(pass, msg)
let (pass, msg) = execute(
expression,
.toMatch,
matcher.predicate,
to: "to",
description: description,
captureExceptions: false
)
verify(pass, msg)
}

/// DEPRECATED: Tests the actual value using a matcher to not match.
Expand Down
8 changes: 5 additions & 3 deletions Sources/Nimble/Matchers/Async.swift
Original file line number Diff line number Diff line change
Expand Up @@ -113,17 +113,19 @@ extension Expectation {
public func toEventually<U>(_ matcher: U, timeout: TimeInterval = AsyncDefaults.Timeout, pollInterval: TimeInterval = AsyncDefaults.PollInterval, description: String? = nil)
where U: Matcher, U.ValueType == T {
if expression.isClosure {
let (pass, msg) = expressionMatches(
let (pass, msg) = execute(
expression,
matcher: async(
.toMatch,
async(
style: .toMatch,
predicate: matcher.predicate,
timeout: timeout,
poll: pollInterval,
fnName: "toEventually"
),
to: "to eventually",
description: description
description: description,
captureExceptions: false
)
verify(pass, msg)
} else {
Expand Down

0 comments on commit 17bd7dc

Please sign in to comment.