Skip to content

Commit 096f392

Browse files
committed
HaveExactElement should not call FailureMessage if a submatcher returned an error
Fixes #668
1 parent 8884bee commit 096f392

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

matchers/have_exact_elements.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,12 @@ func (matcher *HaveExactElementsMatcher) Match(actual interface{}) (success bool
4444

4545
elemMatcher := matchers[i].(omegaMatcher)
4646
match, err := elemMatcher.Match(values[i])
47-
if err != nil || !match {
47+
if err != nil {
48+
matcher.mismatchFailures = append(matcher.mismatchFailures, mismatchFailure{
49+
index: i,
50+
failure: err.Error(),
51+
})
52+
} else if !match {
4853
matcher.mismatchFailures = append(matcher.mismatchFailures, mismatchFailure{
4954
index: i,
5055
failure: elemMatcher.FailureMessage(values[i]),

matchers/have_exact_elements_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,14 @@ var _ = Describe("HaveExactElements", func() {
5858
Expect([]string{"foo", "bar", "baz"}).ShouldNot(HaveExactElements(BeFalse(), "bar", "baz"))
5959
Expect([]interface{}{"foo", "bar", false}).Should(HaveExactElements(ContainSubstring("foo"), "bar", BeFalse()))
6060
})
61+
62+
It("should include the error message, not the failure message", func() {
63+
failures := InterceptGomegaFailures(func() {
64+
Expect([]string{"foo", "bar", "baz"}).Should(HaveExactElements("foo", BeFalse(), "bar"))
65+
})
66+
Ω(failures[0]).ShouldNot(ContainSubstring("to be false"))
67+
Ω(failures[0]).Should(ContainSubstring("1: Expected a boolean. Got:\n <string>: bar"))
68+
})
6169
})
6270
})
6371

0 commit comments

Comments
 (0)