Skip to content

Actionable error message for large json documents #45

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 29, 2021

Conversation

hibikiledo
Copy link
Contributor

@hibikiledo hibikiledo commented Mar 21, 2021

Problem

When using assertJsonDocumentMatches, it is hard to navigate the error message when the assertion fails.

The message only states that the given JSON document is not a match of the provided constraints.
It would be great to also tell which constraint(s) the JSON document fails to satisfy.

Solution

I implement additionalFailureDescription in JsonValueMatchesMany constraint to return a string representation of constraints that fail during evaluations.

The result would look like this.

Screen Shot 2564-03-21 at 07 41 33

I think this would greatly simplify investigation when the tests fail.

Thank you

Copy link
Owner

@martin-helmich martin-helmich left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution, @hibikiledo! 👍 Full ACK that this is an entirely sensible change to make -- the validation messages, especially for larger assertions, are currently not optimal and can be improved significantly.

I'm just having one thought regarding the statefulness of the JsonValueMatchesAny constraint (see the respective comment). Let me know your thoughts on this.

Copy link
Owner

@martin-helmich martin-helmich left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Looking good! I just added (and already applied) one quick suggestion (whitespace only) to make codeclimate stop complaining.

@martin-helmich martin-helmich merged commit e2ff61f into martin-helmich:master Mar 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants