Skip to content

Commit

Permalink
updates MatchError godoc comment to also accept a Gomega matcher (#654)
Browse files Browse the repository at this point in the history
  • Loading branch information
thediveo authored Mar 25, 2023
1 parent 5129b5c commit 67b869d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
11 changes: 7 additions & 4 deletions matchers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 67b869d

Please sign in to comment.