Skip to content

Commit a6d787d

Browse files
committed
Remove diff substring before serializing result for GoConvey UI.
1 parent 29ad8a0 commit a6d787d

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

serializer.go

+7
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package assertions
33
import (
44
"encoding/json"
55
"fmt"
6+
"strings"
67

78
"github.com/smartystreets/assertions/internal/go-render/render"
89
)
@@ -15,6 +16,9 @@ type Serializer interface {
1516
type failureSerializer struct{}
1617

1718
func (self *failureSerializer) serializeDetailed(expected, actual interface{}, message string) string {
19+
if index := strings.Index(message, " Diff:"); index > 0 {
20+
message = message[:index]
21+
}
1822
view := FailureView{
1923
Message: message,
2024
Expected: render.Render(expected),
@@ -25,6 +29,9 @@ func (self *failureSerializer) serializeDetailed(expected, actual interface{}, m
2529
}
2630

2731
func (self *failureSerializer) serialize(expected, actual interface{}, message string) string {
32+
if index := strings.Index(message, " Diff:"); index > 0 {
33+
message = message[:index]
34+
}
2835
view := FailureView{
2936
Message: message,
3037
Expected: fmt.Sprintf("%+v", expected),

serializer_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ import (
99
func TestFailureSerializerCreatesSerializedVersionOfAssertionResult(t *testing.T) {
1010
thing1 := Thing1{"Hi"}
1111
thing2 := Thing2{"Bye"}
12-
message := "Super-hip failure message."
12+
message := "Super-hip failure message. Diff: Something that we don't need."
1313
serializer := newSerializer()
1414

1515
actualResult := serializer.serialize(thing1, thing2, message)
1616

1717
expectedResult, _ := json.Marshal(FailureView{
18-
Message: message,
18+
Message: "Super-hip failure message.",
1919
Expected: fmt.Sprintf("%+v", thing1),
2020
Actual: fmt.Sprintf("%+v", thing2),
2121
})
@@ -26,7 +26,7 @@ func TestFailureSerializerCreatesSerializedVersionOfAssertionResult(t *testing.T
2626

2727
actualResult = serializer.serializeDetailed(thing1, thing2, message)
2828
expectedResult, _ = json.Marshal(FailureView{
29-
Message: message,
29+
Message: "Super-hip failure message.",
3030
Expected: fmt.Sprintf("%#v", thing1),
3131
Actual: fmt.Sprintf("%#v", thing2),
3232
})

0 commit comments

Comments
 (0)