diff --git a/be/assertions.go b/be/assertions.go index 1e91037..f2172a6 100644 --- a/be/assertions.go +++ b/be/assertions.go @@ -190,23 +190,48 @@ func ErrorContaining(err error, msg string) ghost.Result { switch { case err == nil && argMsg == fmt.Sprintf("%q", msg): return ghost.Result{ - Ok: false, - Message: fmt.Sprintf(`%v is nil; missing error message: %v`, argErr, msg), + Ok: false, + Message: fmt.Sprintf(`error %v is nil, does not contain message +got: +want: %v`, + argErr, + msg, + ), } case err == nil: return ghost.Result{ - Ok: false, - Message: fmt.Sprintf(`%v is nil; missing error message %v: %v`, argErr, argMsg, msg), + Ok: false, + Message: fmt.Sprintf(`error %v is nil, does not contain %v +got: +want: %v`, + argErr, + argMsg, + msg, + ), } case strings.Contains(err.Error(), msg): return ghost.Result{ - Ok: true, - Message: fmt.Sprintf("%v contains error message %q: %v", argErr, msg, err), + Ok: true, + Message: fmt.Sprintf(`error %v contains message %v +got: %v +want: %v`, + argErr, + argMsg, + err, + msg, + ), } default: return ghost.Result{ - Ok: false, - Message: fmt.Sprintf("%v does not contain error message %q: %v", argErr, msg, err), + Ok: false, + Message: fmt.Sprintf(`error %v does not contain message %v +got: %v +want: %v`, + argErr, + argMsg, + err, + msg, + ), } } } @@ -214,25 +239,42 @@ func ErrorContaining(err error, msg string) ghost.Result { // ErrorEqual asserts that an error string equals a particular message. func ErrorEqual(err error, msg string) ghost.Result { args := ghostlib.ArgsFromAST(err, msg) - argErr := args[0] + argErr, argMsg := args[0], args[1] if err == nil { return ghost.Result{ - Ok: false, - Message: fmt.Sprintf(`%v is nil; want message: %v`, argErr, msg), + Ok: false, + Message: fmt.Sprintf(`error %v is nil +got: +want: %v`, + argErr, + msg, + ), } } if err.Error() == msg { return ghost.Result{ - Ok: true, - Message: fmt.Sprintf("%v equals error message %q: %v", argErr, msg, err), + Ok: true, + Message: fmt.Sprintf(`error %v has message %v +value: %v`, + argErr, + argMsg, + err, + ), } } return ghost.Result{ - Ok: false, - Message: fmt.Sprintf("%v does not equal error message %q: %v", argErr, msg, err), + Ok: false, + Message: fmt.Sprintf(`error %v does not have message %v +got: %v +want: %v`, + argErr, + argMsg, + err, + msg, + ), } } diff --git a/be/assertions_test.go b/be/assertions_test.go index 8b89a97..1a11c13 100644 --- a/be/assertions_test.go +++ b/be/assertions_test.go @@ -353,14 +353,18 @@ func TestErrorContaining(t *testing.T) { g.Should(be.True(result.Ok)) g.Should(be.Equal( result.Message, - `err contains error message "oob": foobar`, + `error err contains message msg +got: foobar +want: oob`, )) result = be.ErrorContaining(errors.New("foobar"), "oob") g.Should(be.True(result.Ok)) g.Should(be.Equal( result.Message, - `errors.New("foobar") contains error message "oob": foobar`, + `error errors.New("foobar") contains message "oob" +got: foobar +want: oob`, )) }) @@ -374,14 +378,18 @@ func TestErrorContaining(t *testing.T) { g.Should(be.False(result.Ok)) g.Should(be.Equal( result.Message, - `err does not contain error message "boo": foobar`, + `error err does not contain message msg +got: foobar +want: boo`, )) result = be.ErrorContaining(errors.New("foobar"), "boo") g.Should(be.False(result.Ok)) g.Should(be.Equal( result.Message, - `errors.New("foobar") does not contain error message "boo": foobar`, + `error errors.New("foobar") does not contain message "boo" +got: foobar +want: boo`, )) }) @@ -393,11 +401,15 @@ func TestErrorContaining(t *testing.T) { result := be.ErrorContaining(err, msg) g.Should(be.False(result.Ok)) - g.Should(be.Equal(result.Message, `err is nil; missing error message msg: boo`)) + g.Should(be.Equal(result.Message, `error err is nil, does not contain msg +got: +want: boo`)) result = be.ErrorContaining(nil, "boo") g.Should(be.False(result.Ok)) - g.Should(be.Equal(result.Message, `nil is nil; missing error message: boo`)) + g.Should(be.Equal(result.Message, `error nil is nil, does not contain message +got: +want: boo`)) }) } @@ -412,14 +424,16 @@ func TestErrorEqual(t *testing.T) { g.Should(be.True(result.Ok)) g.Should(be.Equal( result.Message, - `err equals error message "foobar": foobar`, + `error err has message msg +value: foobar`, )) result = be.ErrorEqual(errors.New("foobar"), "foobar") g.Should(be.True(result.Ok)) g.Should(be.Equal( result.Message, - `errors.New("foobar") equals error message "foobar": foobar`, + `error errors.New("foobar") has message "foobar" +value: foobar`, )) }) @@ -433,14 +447,18 @@ func TestErrorEqual(t *testing.T) { g.Should(be.False(result.Ok)) g.Should(be.Equal( result.Message, - `err does not equal error message "boo": foobar`, + `error err does not have message msg +got: foobar +want: boo`, )) result = be.ErrorEqual(errors.New("foobar"), "boo") g.Should(be.False(result.Ok)) g.Should(be.Equal( result.Message, - `errors.New("foobar") does not equal error message "boo": foobar`, + `error errors.New("foobar") does not have message "boo" +got: foobar +want: boo`, )) }) @@ -452,11 +470,15 @@ func TestErrorEqual(t *testing.T) { result := be.ErrorEqual(err, msg) g.Should(be.False(result.Ok)) - g.Should(be.Equal(result.Message, `err is nil; want message: boo`)) + g.Should(be.Equal(result.Message, `error err is nil +got: +want: boo`)) result = be.ErrorEqual(nil, "boo") g.Should(be.False(result.Ok)) - g.Should(be.Equal(result.Message, `nil is nil; want message: boo`)) + g.Should(be.Equal(result.Message, `error nil is nil +got: +want: boo`)) }) }