grillon
grillon copied to clipboard
Json context assertions
For the moment we have a couple of assertions with the Value type that represents a json value.
As we are separating the assertion logic from the DSL, it makes sense to identify the different types of json Value, that we can call json contexts:
- json body
- json path
- pure json value
For example the Equality trait can be implemented for Values coming from those different contexts. For debug/logging purposes it is essential to know the Part under test, arising from the context.
The corresponding parts should be:
/// A json value
#[strum(serialize = "json value")]
#[serde(rename = "json value")]
JsonValue,
/// The json body of an http response.
#[strum(serialize = "json body")]
#[serde(rename = "json body")]
JsonBody,
/// The json value of an http response at the given path.
#[strum(serialize = "json path")]
#[serde(rename = "json path")]
JsonPath,
The lib API should stay simple and cover these different examples:
json!(1).eq(&json!(1)): the resulting assertion's part should be aJsonValueJsonBody(json!(1)).eq(&json!(1)): the resulting assertion's part should be aJsonBodyJsonPath(json!(1)).eq(&json!(1)): the resulting assertion's part should be aJsonPath
This way we can easily wrap the json value into its context, or just fallback to a default JsonValue when we want to assert some json data.