Skip to content

Commit

Permalink
improve poll progress message when polling a cosnistently that has be…
Browse files Browse the repository at this point in the history
…en passing
  • Loading branch information
onsi committed Feb 28, 2023
1 parent a84e340 commit 28a319b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
14 changes: 11 additions & 3 deletions internal/async_assertion.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 19 additions & 2 deletions internal/async_assertion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
})
})

Expand All @@ -291,6 +291,23 @@ var _ = Describe("Asynchronous Assertions", func() {
Ω(message).Should(Equal("Expected\n <string>: no match\nto equal\n <string>: 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() {
Expand Down Expand Up @@ -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"))
})
})

Expand Down

0 comments on commit 28a319b

Please sign in to comment.