Skip to content

Commit

Permalink
Merge pull request #965 from Quick/fix-succeed-matcher-type-inference…
Browse files Browse the repository at this point in the history
…-issue

Fix `succeed` matcher type inference issue
  • Loading branch information
ikesyo authored Mar 7, 2022
2 parents 692beb1 + f68e545 commit cabe966
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
8 changes: 4 additions & 4 deletions Sources/Nimble/Matchers/ToSucceed.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
Used by the `toSucceed` matcher.
Used by the `succeed` matcher.

This is the return type for the closure.
*/
Expand All @@ -14,14 +14,14 @@ public enum ToSucceedResult {
Return `.succeeded` when the validation succeeds.
Return `.failed` with a failure reason when the validation fails.
*/
public func succeed() -> Predicate<() -> ToSucceedResult> {
public func succeed() -> Predicate<ToSucceedResult> {
return Predicate.define { actualExpression in
let optActual = try actualExpression.evaluate()
guard let actual = optActual else {
return PredicateResult(status: .fail, message: .fail("expected a closure, got <nil>"))
return PredicateResult(status: .fail, message: .fail("expected a ToSucceedResult, got <nil>"))
}

switch actual() {
switch actual {
case .succeeded:
return PredicateResult(
bool: true,
Expand Down
25 changes: 15 additions & 10 deletions Tests/NimbleTests/Matchers/ToSucceedTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,33 @@ import Nimble

final class ToSucceedTest: XCTestCase {
func testToSucceed() {
expect({
expect {
return .succeeded
}).to(succeed())
}.to(succeed())

expect({
expect {
return .failed(reason: "")
}).toNot(succeed())
}.toNot(succeed())

failsWithErrorMessageForNil("expected a closure, got <nil>") {
expect(nil as (() -> ToSucceedResult)?).to(succeed())
expect {
let result = ToSucceedResult.succeeded
return result
}.to(succeed())

failsWithErrorMessageForNil("expected a ToSucceedResult, got <nil>") {
expect(nil).to(succeed())
}

failsWithErrorMessage("expected to succeed, got <failed> because <something went wrong>") {
expect({
expect {
.failed(reason: "something went wrong")
}).to(succeed())
}.to(succeed())
}

failsWithErrorMessage("expected to not succeed, got <succeeded>") {
expect({
expect {
return .succeeded
}).toNot(succeed())
}.toNot(succeed())
}
}
}

0 comments on commit cabe966

Please sign in to comment.