make WithTransform() propagate MatchMayChangeInTheFuture() from wrapped matcher
diff --git a/matchers/with_transform.go b/matchers/with_transform.go
index 430223e..a8d2a7c 100644
--- a/matchers/with_transform.go
+++ b/matchers/with_transform.go
@@ -2,6 +2,7 @@
import (
"fmt"
+ "github.com/onsi/gomega/internal/asyncassertion"
"github.com/onsi/gomega/types"
"reflect"
)
@@ -59,3 +60,7 @@
func (m *WithTransformMatcher) NegatedFailureMessage(_ interface{}) (message string) {
return m.Matcher.NegatedFailureMessage(m.transformedValue)
}
+
+func (m *WithTransformMatcher) MatchMayChangeInTheFuture(_ interface{}) bool {
+ return asyncassertion.MatchMayChangeInTheFuture(m.Matcher, m.transformedValue)
+}
diff --git a/matchers/with_transform_test.go b/matchers/with_transform_test.go
index 4d1a363..7ac6f1c 100644
--- a/matchers/with_transform_test.go
+++ b/matchers/with_transform_test.go
@@ -4,6 +4,7 @@
"errors"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
+ . "github.com/onsi/gomega/matchers"
)
var _ = Describe("WithTransformMatcher", func() {
@@ -84,4 +85,24 @@
})
})
})
+
+ Context("MatchMayChangeInTheFuture()", func() {
+ It("Propogates value from wrapped matcher on the transformed value", func() {
+ // dummy struct that holds a channel
+ type S struct{ C chan int }
+ getC := func(s S) chan int { return s.C } // extracts channel from struct
+ // wrap a Receive matcher, which does implement this method
+ var i int
+ m := WithTransform(getC, Receive(&i))
+ s := S{make(chan int)}
+ close(s.C)
+ Expect(m.Match(s)).To(BeFalse())
+ Expect(m.(*WithTransformMatcher).MatchMayChangeInTheFuture(s)).To(BeFalse()) // channel closed so Receive return false
+ })
+ It("Defaults to true", func() {
+ m := WithTransform(plus1, Equal(2)) // Equal does not have this method
+ Expect(m.Match(1)).To(BeTrue())
+ Expect(m.(*WithTransformMatcher).MatchMayChangeInTheFuture(1)).To(BeTrue()) // defaults to true
+ })
+ })
})