Skip to content

Commit

Permalink
Merge pull request #29 from zak905/fix_wrong_file_in_error
Browse files Browse the repository at this point in the history
Fix wrong file in logged message when failure occurs
  • Loading branch information
h2non authored Aug 9, 2022
2 parents 6066e70 + d37bf8a commit 6a2e4d1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion assert/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func StatusRedirect() Func {
func StatusEqual(code int) Func {
return func(res *http.Response, req *http.Request) error {
if res.StatusCode != code {
return fmt.Errorf("Unexpected status code for: %s %s => %d != %d", req.Method, req.Url.String(), res.StatusCode, code)
return fmt.Errorf("Unexpected status code for: %s %s => %d != %d", req.Method, req.URL.String(), res.StatusCode, code)
}
return nil
}
Expand Down
12 changes: 11 additions & 1 deletion expect.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package baloo
import (
"fmt"
"net/http"
"path"
"runtime"

"gopkg.in/h2non/baloo.v3/assert"
"gopkg.in/h2non/gentleman.v2"
Expand All @@ -27,6 +29,8 @@ func FlushAssertFuncs() {
// TestingT implements part of the same interface as testing.T
type TestingT interface {
Error(args ...interface{})
Fail()
Logf(format string, args ...interface{})
}

// Expect represents the HTTP expectation suite who is
Expand Down Expand Up @@ -201,7 +205,13 @@ func (e *Expect) Done() error {
// Run assertions
err = e.run(res.RawResponse, res.RawRequest)
if err != nil {
e.test.Error(err)
_, fileName, line, ok := runtime.Caller(1)
if !ok {
//fallback to test.Error
e.test.Error(err)
}
e.test.Logf("%s:%d: %s\n", path.Base(fileName), line, err)
e.test.Fail()
}

return err
Expand Down

0 comments on commit 6a2e4d1

Please sign in to comment.