From 5b9da39b66e8e994455c2525c4421c8cc00a7f93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ernesto=20Jime=CC=81nez?= Date: Sat, 2 Jan 2016 12:02:58 +0100 Subject: [PATCH] MatchedBy documentation --- mock/mock.go | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/mock/mock.go b/mock/mock.go index 9895bb5..bc6c86b 100644 --- a/mock/mock.go +++ b/mock/mock.go @@ -480,9 +480,17 @@ func (f argumentMatcher) String() string { return fmt.Sprintf("func(%s) bool", f.fn.Type().In(0).Name()) } -// Builds an argumentMatcher from |fn|, which must be a function accepting a -// single argument (of any type) which returns a bool. If |fn| doesn't match -// the required signature, MathedBy() panics. +// MatchedBy can be used to match a mock call based on only certain properties +// from a complex struct or some calculation. It takes a function that will be +// evaluated with the called argument and will return true when there's a match +// and false otherwise. +// +// Example: +// m.On("Do", func(req *http.Request) bool { return req.Host == "example.com" }) +// +// |fn|, must be a function accepting a single argument (of the expected type) +// which returns a bool. If |fn| doesn't match the required signature, +// MathedBy() panics. func MatchedBy(fn interface{}) argumentMatcher { fnType := reflect.TypeOf(fn)