Skip to content

Commit 28a319b

Browse files
committed
improve poll progress message when polling a cosnistently that has been passing
1 parent a84e340 commit 28a319b

File tree

2 files changed

+30
-5
lines changed

2 files changed

+30
-5
lines changed

internal/async_assertion.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -425,10 +425,18 @@ func (assertion *AsyncAssertion) match(matcher types.GomegaMatcher, desiredMatch
425425

426426
if actualErr == nil {
427427
if matcherErr == nil {
428-
if desiredMatch {
429-
message += matcher.FailureMessage(actual)
428+
if desiredMatch != matches {
429+
if desiredMatch {
430+
message += matcher.FailureMessage(actual)
431+
} else {
432+
message += matcher.NegatedFailureMessage(actual)
433+
}
430434
} else {
431-
message += matcher.NegatedFailureMessage(actual)
435+
if assertion.asyncType == AsyncAssertionTypeConsistently {
436+
message += "There is no failure as the matcher passed to Consistently has not yet failed"
437+
} else {
438+
message += "There is no failure as the matcher passed to Eventually succeeded on its most recent iteration"
439+
}
432440
}
433441
} else {
434442
var fgErr formattedGomegaError

internal/async_assertion_test.go

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ var _ = Describe("Asynchronous Assertions", func() {
272272
return MATCH
273273
}, time.Hour).WithContext(ctx).Should(SpecMatch())
274274
Ω(ig.FailureMessage).Should(ContainSubstring("Context was cancelled after"))
275-
Ω(ig.FailureMessage).Should(ContainSubstring("positive: match"))
275+
Ω(ig.FailureMessage).Should(ContainSubstring("There is no failure as the matcher passed to Consistently has not yet failed"))
276276
})
277277
})
278278

@@ -291,6 +291,23 @@ var _ = Describe("Asynchronous Assertions", func() {
291291
Ω(message).Should(Equal("Expected\n <string>: no match\nto equal\n <string>: match"))
292292
Ω(fakeSpecContext.Cancelled).Should(BeTrue())
293293
})
294+
295+
Context("when used with consistently", func() {
296+
It("returns a useful message that does not invoke the matcher's failure handlers", func() {
297+
fakeSpecContext := &FakeGinkgoSpecContext{}
298+
var message string
299+
ctx := context.WithValue(context.Background(), "GINKGO_SPEC_CONTEXT", fakeSpecContext)
300+
ig.G.Consistently(func() error {
301+
if fakeSpecContext.Attached != nil {
302+
message = fakeSpecContext.Attached()
303+
}
304+
return nil
305+
}).WithTimeout(time.Millisecond * 20).WithContext(ctx).ShouldNot(HaveOccurred())
306+
307+
Ω(message).Should(Equal("There is no failure as the matcher passed to Consistently has not yet failed"))
308+
Ω(fakeSpecContext.Cancelled).Should(BeTrue())
309+
})
310+
})
294311
})
295312

296313
Describe("the interaction between the context and the timeout", func() {
@@ -461,7 +478,7 @@ var _ = Describe("Asynchronous Assertions", func() {
461478
return MATCH
462479
}, time.Hour).WithContext(ctx).Should(SpecMatch())
463480
Ω(ig.FailureMessage).Should(ContainSubstring("Context was cancelled after"))
464-
Ω(ig.FailureMessage).Should(ContainSubstring("positive: match"))
481+
Ω(ig.FailureMessage).Should(ContainSubstring("There is no failure as the matcher passed to Consistently has not yet failed"))
465482
})
466483
})
467484

0 commit comments

Comments
 (0)