From d117d7c67901bb7dd4094dfe6e440584ba29eab2 Mon Sep 17 00:00:00 2001 From: TheDiveO <6920158+thediveo@users.noreply.github.com> Date: Sat, 25 Mar 2023 16:47:21 +0100 Subject: [PATCH] updates MatchError godoc comment to also accept a Gomega matcher --- docs/index.md | 2 +- matchers.go | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/docs/index.md b/docs/index.md index cbc37fb23..f684e4206 100644 --- a/docs/index.md +++ b/docs/index.md @@ -796,7 +796,7 @@ succeeds if `ACTUAL` is a non-nil `error` that matches `EXPECTED`. `EXPECTED` mu - A matcher, in which case `ACTUAL.Error()` is tested against the matcher. - An error, in which case `ACTUAL` and `EXPECTED` are compared via `reflect.DeepEqual()`. If they are not deeply equal, they are tested by `errors.Is(ACTUAL, EXPECTED)`. (The latter allows to test whether `ACTUAL` wraps an `EXPECTED` error.) -Any other type for `EXPECTED` is an error. +Any other type for `EXPECTED` is an error. It is also an error for `ACTUAL` to be nil. ### Working with Channels diff --git a/matchers.go b/matchers.go index 857586a91..47cbae1c4 100644 --- a/matchers.go +++ b/matchers.go @@ -87,14 +87,17 @@ func Succeed() types.GomegaMatcher { return &matchers.SucceedMatcher{} } -// MatchError succeeds if actual is a non-nil error that matches the passed in string/error. +// MatchError succeeds if actual is a non-nil error that matches the passed in +// string, error, or matcher. // // These are valid use-cases: // -// Expect(err).Should(MatchError("an error")) //asserts that err.Error() == "an error" -// Expect(err).Should(MatchError(SomeError)) //asserts that err == SomeError (via reflect.DeepEqual) +// Expect(err).Should(MatchError("an error")) //asserts that err.Error() == "an error" +// Expect(err).Should(MatchError(SomeError)) //asserts that err == SomeError (via reflect.DeepEqual) +// Expect(err).Should(MatchError(ContainsSubstring("sprocket not found"))) // asserts that edrr.Error() contains substring "sprocket not found" // -// It is an error for err to be nil or an object that does not implement the Error interface +// It is an error for err to be nil or an object that does not implement the +// Error interface func MatchError(expected interface{}) types.GomegaMatcher { return &matchers.MatchErrorMatcher{ Expected: expected,