onsi / gomega

Ginkgo's Preferred Matcher Library
http://onsi.github.io/gomega/
MIT License
2.16k stars 281 forks source link

Fix HaveExactElements to work inside ContainElement or other collection matchers #648

Closed eiiches closed 1 year ago

eiiches commented 1 year ago

Fixes #647

As described in #647, HaveExactElements() leaves some internal state once its Match() returns false. The state never gets cleaned afterwards and causes subsequent calls on the instance to return incorrect results. This can be a problem when the matcher is placed inside ContainElement() or any other matchers that reuse and call inner matcher instances multiple times.

This PR fixes the issue by resetting the matcher state at the beginning of the HaveExactElements#Match().

onsi commented 1 year ago

LGTM! will merge when CI goes green