From 67b869d65ae76f6db20349a440ed9ccb49b96ca0 Mon Sep 17 00:00:00 2001 From: TheDiveO <6920158+thediveo@users.noreply.github.com> Date: Sat, 25 Mar 2023 16:55:53 +0100 Subject: [PATCH] updates MatchError godoc comment to also accept a Gomega matcher (#654) --- 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 5b3f3c81f..a73adbe48 100644 --- a/docs/index.md +++ b/docs/index.md @@ -823,7 +823,7 @@ succeeds if `ACTUAL` is a non-nil `error` that matches `EXPECTED`. `EXPECTED` mu - `errors.Is(ACTUAL, EXPECTED)` returns `true` - `ACTUAL` or any of the errors it wraps (directly or indirectly) equals `EXPECTED` in terms of `reflect.DeepEqual()`. -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 44056ad64..b832f3dba 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,