Skip to content

Commit

Permalink
HaveExactElement should not call FailureMessage if a submatcher retur…
Browse files Browse the repository at this point in the history
…ned an error

Fixes #668
  • Loading branch information
onsi committed Jun 7, 2023
1 parent 8884bee commit 096f392
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
7 changes: 6 additions & 1 deletion matchers/have_exact_elements.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,12 @@ func (matcher *HaveExactElementsMatcher) Match(actual interface{}) (success bool

elemMatcher := matchers[i].(omegaMatcher)
match, err := elemMatcher.Match(values[i])
if err != nil || !match {
if err != nil {
matcher.mismatchFailures = append(matcher.mismatchFailures, mismatchFailure{
index: i,
failure: err.Error(),
})
} else if !match {
matcher.mismatchFailures = append(matcher.mismatchFailures, mismatchFailure{
index: i,
failure: elemMatcher.FailureMessage(values[i]),
Expand Down
8 changes: 8 additions & 0 deletions matchers/have_exact_elements_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,14 @@ var _ = Describe("HaveExactElements", func() {
Expect([]string{"foo", "bar", "baz"}).ShouldNot(HaveExactElements(BeFalse(), "bar", "baz"))
Expect([]interface{}{"foo", "bar", false}).Should(HaveExactElements(ContainSubstring("foo"), "bar", BeFalse()))
})

It("should include the error message, not the failure message", func() {
failures := InterceptGomegaFailures(func() {
Expect([]string{"foo", "bar", "baz"}).Should(HaveExactElements("foo", BeFalse(), "bar"))
})
Ω(failures[0]).ShouldNot(ContainSubstring("to be false"))
Ω(failures[0]).Should(ContainSubstring("1: Expected a boolean. Got:\n <string>: bar"))
})
})
})

Expand Down

0 comments on commit 096f392

Please sign in to comment.