Quick / Nimble

A Matcher Framework for Swift and Objective-C
https://quick.github.io/Nimble/documentation/nimble/
Apache License 2.0
4.8k stars 601 forks source link

I can't get toEventually to work correctly after updating to Nimble 11.x #1015

Closed marcinpodeszwa-medcase closed 1 year ago

marcinpodeszwa-medcase commented 1 year ago

What did you do?

Consider following sample code:

class Sample {
    static var executed = false

    func execute() {
        DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
            Self.executed = true
        }
    }
}

I want to test it using Quick+Nimble, so I wrote following test:

class SampleTests: QuickSpec {
    override func spec() {
        describe("Sample") {
            it("sets executed") {
                Sample().execute()
                expect(Sample.executed).toEventually(beTrue())
            }
        }
    }
}

And it was working perfectly well on Quick 5.0.1 and Nimble 10.0.0

After updating Quick to 6.0.0 and Nimble to 11.1.0 I saw this warning (but the test was passing):

Screenshot 2022-11-07 at 15 24 07

I added keyword await (that's what I thought I need to do) and suddenly my test stopped passing:

Screenshot 2022-11-07 at 15 24 25

What did you expect to happen?

I expect this test to pass without warnings. Maybe there is something I don't understand, because I'm new to new swift's concurrency.

What actually happened instead?

Depending on if I add await or not, I get either a warning or a test failure.

Environment

List the software versions you're using:

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

Project that demonstrates the issue

Please link to a project we can download that reproduces the issue. Feel free to delete this section if it's not relevant to the issue (eg - feature request).

ToEventuallyTest.zip

The project should be short, self-contained, and correct example.

younata commented 1 year ago

Hey, thanks for the succinct bug report with reproducible sample!

The Self.executed = true line is getting executed. The static var is getting set. But it appears that Nimble is sending a cached value to the matcher?


Oops. I forgot to use uncachedExpression in the async-compatible version of toEventually.

younata commented 1 year ago

This fix is included in the just-released v11.1.1!

marcinpodeszwa-medcase commented 1 year ago

thanks @younata , works great now!