Nimble: Test with Custom Validation is not compiled

Created on 15 Feb 2021  路  3Comments  路  Source: Quick/Nimble

What did you do?

I have updated Nimble from 8.1.2 to 9.0.0.

I have tests with Custom Validation like this

expect({
guard false else { return .failed(reason: "some reason") }
return .succeeded
}).to(succeed())

This test is not compiled. Errors:
Type '(() -> ToSucceedResult)? has no member 'failed'
Type '(() -> ToSucceedResult)? has no member 'succeeded'

At the same time test below is compiled successfully:
expect({ return .succeeded }).to(succeed())

I suppose it's related to changes in expect... methods signature regarding @autoclosure modifier.

Note:
I have tried to change signature of succeed function.
from:
public func succeed() -> Predicate<() -> ToSucceedResult>
to
public func succeed() -> Predicate<ToSucceedResult>

In this case tests are compiled successfully.

What did you expect to happen?

Test is compiled successfully

What actually happened instead?

I've got errors:
Type '(() -> ToSucceedResult)? has no member 'failed'
Type '(() -> ToSucceedResult)? has no member 'succeeded'

Environment

List the software versions you're using:

  • Quick: 3.1.2
  • Nimble: 9.0.0
  • Xcode Version: 12.1 (12A7403)
  • Swift Version: Xcode Default

Please also mention which package manager you used and its version. Delete the
other package managers in this list:

  • Cocoapods: 1.10.1

  • Project that demonstrates the issue

Screen Shot 2021-02-15 at 16 41 54

question / needs more details

Most helpful comment

Had the same problem, the error msg helps here however.
This works:

expect({
                    let result: (() -> ToSucceedResult)? = {
                        guard case let .loaded(questions) = subject.state else {
                            return .failed(reason: "wrong enum case")
                        }

                        if questions == [] {
                            return .succeeded
                        } else {
                            return .failed(reason: "wrong questions")
                        }
                    }

                    return result
                }).toEventually(succeed())

All 3 comments

Completely similar situation.

Had the same problem, the error msg helps here however.
This works:

expect({
                    let result: (() -> ToSucceedResult)? = {
                        guard case let .loaded(questions) = subject.state else {
                            return .failed(reason: "wrong enum case")
                        }

                        if questions == [] {
                            return .succeeded
                        } else {
                            return .failed(reason: "wrong questions")
                        }
                    }

                    return result
                }).toEventually(succeed())

It is expected to use trailing closure syntax for the succeed matcher to make type inference work correctly:

expect {
    guard false else { return .failed(reason: "some reason") }
    return .succeeded
}.to(succeed())

See #809 and #824 for the details.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kleiberjp picture kleiberjp  路  4Comments

sreddy100 picture sreddy100  路  4Comments

Blackjacx picture Blackjacx  路  7Comments

gapl picture gapl  路  5Comments

ikesyo picture ikesyo  路  4Comments