hurl
hurl copied to clipboard
Have a nice diff when comparing bodies
It looks like when using body assertions there is no simple way to compare actual and expected values.
E.g. : I make a request that returns body
{
"id": 0,
"name": "Frieda",
"picture": "images/scottish-terrier.jpeg",
"age": 3,
"breed": "Scottish Terrier",
"location": "Lisco, Alabama"
}
In my hurl file is as follows :
# Get a doggy thing:
GET https://example.net/api/dogs/
HTTP/1.1 200
{
"id": 0,
"name": "Julien",
"picture": "images/scottish-terrier.jpeg",
"age": 3,
"breed": "Scottish Terrier",
"location": "Lisco, Alabama"
}
<img width="1033" alt="Capture d’écran 2020-11-20 à 14 55 40" src="https://user-images.githubusercontent.com/113336/99807944-77a2ee80-2b40-11eb-8855-ce559a130fcf.png">
The output is
error: Assert Body Value
--> ./integration/test-files/nominal/edito/accessory-orange.hurl:36:1
|
36 | {
| ^ actual value is < {
"id": 0,
"name": "Frieda",
"picture": "images/scottish-terrier.jpeg",
"age": 3,
"breed": "Scottish Terrier",
"location": "Lisco, Alabama"
} >
Would it be possible to have a simple way to diff the actual and expected ? Like what is possible with JUnit failed string comparisons.

The json body { ...} is equivalent to the following assert: `body equals "{...}" Therefore, this is an assert on a string (not a json).
The error message could maybe be reduced to the different line/character in the string
error: Assert Body Value
--> ./integration/test-files/nominal/edito/accessory-orange.hurl:38:1
|
38 | "name": "Julien",
| ^ actual value is <Frieda",>
}
In assertion libraries the message is also just "expected xxx but was xxy" but (when in an IDE) there's a way to diff the contents.
Maybe it could be an option to generate a diff and pass it to any standard diff reader ?