Skip to content

Commit

Permalink
Use Go-syntax representation when printing other interactions with mock
Browse files Browse the repository at this point in the history
  • Loading branch information
petergtz committed Oct 28, 2017
1 parent 53d177b commit b99e34d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
2 changes: 1 addition & 1 deletion dsl.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ func formatParams(params []Param) (result string) {
if i > 0 {
result += ", "
}
result += fmt.Sprint(param)
result += fmt.Sprintf("%#v", param)
}
return
}
Expand Down
21 changes: 17 additions & 4 deletions dsl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -556,8 +556,8 @@ var _ = Describe("MockDisplay", func() {
"Mock invocation count for method \"Flash\" with params [wrong string -987] " +
"does not match expectation.\n\n\tExpected: 1; but got: 0\n\n" +
"\tBut other interactions with this mock were:\n" +
"\tFlash(Hello, 123)\n" +
"\tFlash(Again, 456)\n",
"\tFlash(\"Hello\", 123)\n" +
"\tFlash(\"Again\", 456)\n",
))
})

Expand All @@ -569,11 +569,24 @@ var _ = Describe("MockDisplay", func() {
"Mock invocation count for method \"Flash\" with params [wrong string -987] " +
"does not match expectation.\n\n\tExpected: 1; but got: 0\n\n" +
"\tBut other interactions with this mock were:\n" +
"\tFlash(Hello, 123)\n" +
"\tShow(Again)\n"),
"\tFlash(\"Hello\", 123)\n" +
"\tShow(\"Again\")\n"),
)
})

It("formats params in interactions with Go syntax for better readability", func() {
display.NetHttpRequestParam(http.Request{Host: "x.com"})
Expect(func() { display.VerifyWasCalledOnce().NetHttpRequestParam(http.Request{Host: "y.com"}) }).To(PanicWith(
`Mock invocation count for method "NetHttpRequestParam" with params [{ <nil> 0 0 map[] <nil> <nil> 0 [] false y.com map[] map[] <nil> map[] <nil> <nil> <nil> <nil>}] does not match expectation.
Expected: 1; but got: 0
But other interactions with this mock were:
NetHttpRequestParam(http.Request{Method:"", URL:(*url.URL)(nil), Proto:"", ProtoMajor:0, ProtoMinor:0, Header:http.Header(nil), Body:io.ReadCloser(nil), GetBody:(func() (io.ReadCloser, error))(nil), ContentLength:0, TransferEncoding:[]string(nil), Close:false, Host:"x.com", Form:url.Values(nil), PostForm:url.Values(nil), MultipartForm:(*multipart.Form)(nil), Trailer:http.Header(nil), RemoteAddr:"", RequestURI:"", TLS:(*tls.ConnectionState)(nil), Cancel:(<-chan struct {})(nil), Response:(*http.Response)(nil), ctx:context.Context(nil)})
`,
))
})

It("shows no interactions if there were none", func() {
Expect(func() { display.VerifyWasCalledOnce().Flash("wrong string", -987) }).To(PanicWith(
"Mock invocation count for method \"Flash\" with params [wrong string -987] " +
Expand Down

0 comments on commit b99e34d

Please sign in to comment.