make Not() propagate MatchMayChangeInTheFuture() from wrapped matcher
diff --git a/internal/asyncassertion/async_assertion.go b/internal/asyncassertion/async_assertion.go index 7bbec43..b007383 100644 --- a/internal/asyncassertion/async_assertion.go +++ b/internal/asyncassertion/async_assertion.go
@@ -95,6 +95,12 @@ return true } + return MatchMayChangeInTheFuture(matcher, value) +} + +//MatchMayChangeInTheFuture is a helper to call MatchMayChangeInTheFuture on an unknown matcher. +//If matcher implements oracleMatcher, it will call the method. Otherwise just returns true. +func MatchMayChangeInTheFuture(matcher types.GomegaMatcher, value interface{}) bool { oracleMatcher, ok := matcher.(oracleMatcher) if !ok { return true
diff --git a/matchers/and.go b/matchers/and.go index e20fbae..5092463 100644 --- a/matchers/and.go +++ b/matchers/and.go
@@ -24,7 +24,7 @@ return true, nil } -func (m *AndMatcher) FailureMessage(actual interface{}) (message string) { +func (m *AndMatcher) FailureMessage(_ interface{}) (message string) { return m.firstFailedMatchErrMsg }
diff --git a/matchers/not.go b/matchers/not.go index 5ad0d63..0cacc94 100644 --- a/matchers/not.go +++ b/matchers/not.go
@@ -1,6 +1,9 @@ package matchers -import "github.com/onsi/gomega/types" +import ( + "github.com/onsi/gomega/types" + "github.com/onsi/gomega/internal/asyncassertion" +) type NotMatcher struct { Matcher types.GomegaMatcher @@ -21,3 +24,7 @@ func (m *NotMatcher) NegatedFailureMessage(actual interface{}) (message string) { return m.Matcher.FailureMessage(actual) // works beautifully } + +func (m *NotMatcher) MatchMayChangeInTheFuture(actual interface{}) bool { + return asyncassertion.MatchMayChangeInTheFuture(m.Matcher, actual) // just return m.Matcher's value +}
diff --git a/matchers/not_test.go b/matchers/not_test.go index e716178..e745651 100644 --- a/matchers/not_test.go +++ b/matchers/not_test.go
@@ -3,6 +3,7 @@ import ( . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" + . "github.com/onsi/gomega/matchers" ) var _ = Describe("NotMatcher", func() { @@ -40,4 +41,21 @@ }) }) }) + + Context("MatchMayChangeInTheFuture()", func() { + It("Propogates value from wrapped matcher", func() { + // wrap a Receive matcher, which does implement this method + channel := make(chan int) + close(channel) + var i int + m := Not(Receive(&i)) + Expect(m.Match(channel)).To(BeTrue()) + Expect(m.(*NotMatcher).MatchMayChangeInTheFuture(channel)).To(BeFalse()) + }) + It("Defaults to true", func() { + m := Not(Equal(1)) // Equal does not have this method + Expect(m.Match(2)).To(BeTrue()) + Expect(m.(*NotMatcher).MatchMayChangeInTheFuture(2)).To(BeTrue()) // defaults to true + }) + }) })