diff --git a/internal/async_assertion.go b/internal/async_assertion.go index 7f6226968..baa28d4ad 100644 --- a/internal/async_assertion.go +++ b/internal/async_assertion.go @@ -425,10 +425,18 @@ func (assertion *AsyncAssertion) match(matcher types.GomegaMatcher, desiredMatch if actualErr == nil { if matcherErr == nil { - if desiredMatch { - message += matcher.FailureMessage(actual) + if desiredMatch != matches { + if desiredMatch { + message += matcher.FailureMessage(actual) + } else { + message += matcher.NegatedFailureMessage(actual) + } } else { - message += matcher.NegatedFailureMessage(actual) + if assertion.asyncType == AsyncAssertionTypeConsistently { + message += "There is no failure as the matcher passed to Consistently has not yet failed" + } else { + message += "There is no failure as the matcher passed to Eventually succeeded on its most recent iteration" + } } } else { var fgErr formattedGomegaError diff --git a/internal/async_assertion_test.go b/internal/async_assertion_test.go index aa238bf88..a0cea738b 100644 --- a/internal/async_assertion_test.go +++ b/internal/async_assertion_test.go @@ -272,7 +272,7 @@ var _ = Describe("Asynchronous Assertions", func() { return MATCH }, time.Hour).WithContext(ctx).Should(SpecMatch()) Ω(ig.FailureMessage).Should(ContainSubstring("Context was cancelled after")) - Ω(ig.FailureMessage).Should(ContainSubstring("positive: match")) + Ω(ig.FailureMessage).Should(ContainSubstring("There is no failure as the matcher passed to Consistently has not yet failed")) }) }) @@ -291,6 +291,23 @@ var _ = Describe("Asynchronous Assertions", func() { Ω(message).Should(Equal("Expected\n : no match\nto equal\n : match")) Ω(fakeSpecContext.Cancelled).Should(BeTrue()) }) + + Context("when used with consistently", func() { + It("returns a useful message that does not invoke the matcher's failure handlers", func() { + fakeSpecContext := &FakeGinkgoSpecContext{} + var message string + ctx := context.WithValue(context.Background(), "GINKGO_SPEC_CONTEXT", fakeSpecContext) + ig.G.Consistently(func() error { + if fakeSpecContext.Attached != nil { + message = fakeSpecContext.Attached() + } + return nil + }).WithTimeout(time.Millisecond * 20).WithContext(ctx).ShouldNot(HaveOccurred()) + + Ω(message).Should(Equal("There is no failure as the matcher passed to Consistently has not yet failed")) + Ω(fakeSpecContext.Cancelled).Should(BeTrue()) + }) + }) }) Describe("the interaction between the context and the timeout", func() { @@ -461,7 +478,7 @@ var _ = Describe("Asynchronous Assertions", func() { return MATCH }, time.Hour).WithContext(ctx).Should(SpecMatch()) Ω(ig.FailureMessage).Should(ContainSubstring("Context was cancelled after")) - Ω(ig.FailureMessage).Should(ContainSubstring("positive: match")) + Ω(ig.FailureMessage).Should(ContainSubstring("There is no failure as the matcher passed to Consistently has not yet failed")) }) })