From 834d5841c70be12a7f9bcc974f5b14d9ca8babce Mon Sep 17 00:00:00 2001 From: gedi Date: Thu, 16 Mar 2017 20:29:40 +0200 Subject: [PATCH] makes more explicit error message for an example json matcher --- examples/api/api_test.go | 15 ++++++++++++--- examples/api/version.feature | 2 +- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/examples/api/api_test.go b/examples/api/api_test.go index 919cfde..d406c9c 100644 --- a/examples/api/api_test.go +++ b/examples/api/api_test.go @@ -60,9 +60,18 @@ func (a *apiFeature) theResponseShouldMatchJSON(body *gherkin.DocString) (err er if expected, err = json.Marshal(data); err != nil { return } - actual = a.resp.Body.Bytes() - if !bytes.Equal(actual, expected) { - err = fmt.Errorf("expected json, does not match actual: %s", string(actual)) + actual = bytes.TrimSpace(a.resp.Body.Bytes()) + if len(actual) != len(expected) { + return fmt.Errorf("expected json length: %d does not match actual: %d", len(expected), len(actual)) + } + for i, b := range actual { + if b != expected[i] { + return fmt.Errorf( + "expected json does not match actual at character: %s^%s", + string(actual[:i]), + string(actual[i:i+1]), + ) + } } return } diff --git a/examples/api/version.feature b/examples/api/version.feature index e204af7..8136d93 100644 --- a/examples/api/version.feature +++ b/examples/api/version.feature @@ -20,6 +20,6 @@ Feature: get version And the response should match json: """ { - "version": "v0.6.1" + "version": "v0.6.3" } """