Closed matryer closed 8 years ago
Instead of rely in the user, what I think it makes for sense is rely on sensible defaults. The idea is if the content type is JSON just relay on the JSON non strict equal to assert the response (non strict is not taking into account order on the elements, with the exception of arrays), that should be ok for most of the users.
For advance users, in case of JSON maybe a JSON Schema helps (I don't know the best way to relate a response to a schema)
If the content type is not JSON, the exact match is the most sensible default, with the possibility of implementing more assertions for other content types for example XML
The idea itself looks reasonable, but I think json
label should work as json(mode=same)
by default. I think that simplicity of the silk's way of written test is one of it's strengths, so one should try to save it.
Agreed... I'm all for simplicity and will always listen to something that strips functionality out, rather than adds it.
Question is, which is the sensible default:
JSON isn't biased about the order of fields. I don't remember any use cases where strict matching could make big difference.
The order of fields could change through the time, e.g when API producer switch to another JSON marshaller (nodejs 0.10 and 4 might stringify JSON with different field order). But at the same time, no API consumer would be harmed by this change, as JSON is a scheme-less data structure.
:+1: +1
Right now this keeps me from fully utilizing this beautiful tool, as I would like to minifiy the JSON on the server, but have it prettified in the docs. In addition there is no real reason to be overly strict about the order in the docs as @narqo mentioned (IMHO). I would also opt to have the docs specify the required fields in the JSON and have lenient tests in case extra fields are included. This would allow us to keep minimal tests and avoid updating the docs with unneeded information if we later add features elsewhere.
I also agree that flagging json responses with three backticks and json
should be enough to enable the "lenient" mode.
I have implemented json
and json(mode=subset)
in #36
I wonder if we can use subset by default, and have strict
or exact
as the option?
exact
is currently missing, but should be easy to add. As for the default, I leave the decision up to you. subset
seems to be the more developer friendly default IMHO.
I think we can get rid of subset
and just have it as the default. So exact
is the only option?
@matryer so subset
is default, same
and exact
as options?
@matryer done. subset is now the default with same
and exact
as options.
Proposal: better bodies in Silk
Bodies in Silk could make use of the 'formatting' tag thing where not only the data type is specified, but also the kind of assertions that could take place:
The types of bodies could be:
exact
- the body must match verbatimsame
- the JSON must essentially be equal but fields may be in different orders and formatting (whitespace) is ignoredsubset
- each mentioned field is asserted, additional fields in the body is ignoredThe syntax highlight language specified could also drive which
ParseBody
function is called.Cons
Alternatives
Other options to consider:
json
language specifier might be enough to indicate the datatype, and we could use flags (when running the file) to indicate what type of assertion to make