Open ttahmouch opened 9 years ago
@honzajavorek Workaround solution for this could be one afterEachValidation
hook and adjusting the transaction
object:
results
and the test.valid
propertyexpected
data from the transaction
objecttest.status
test.isValid
results
data structure for the custom validator outputtest.valid
or test.isValid
? (you mention both)
Otherwise, your proposal make sense to me. However, this would mean Gavel would always run and user could just overwrite it's results, but I guess that's not an issue.
I would love to have the option to say that dredd needs to validate the exact values of the responses even if it's application/json.
You can do that already! Just look to the documentarion for custom chai expectstions in hooks.
Dredd's life cycle, as it was designed and documented, was broken until now - you could not change the transaction.test
object in hooks and in some cases, Dredd would emit test fail
events to reporters right after Gavel validation. This is now fixed in https://github.com/apiaryio/dredd/pull/648.
I'm pretty confident we have now, as @netmilk wrote, everything in place. Moreover, everything should also work as expected and documented.
Hence implementing this in hooks should be entirely possible now and not only with afterEachValidation
hooks, but also with after
and afterEach
hooks. This issue can be closed if the use case gets a nice, working example in documentation (and preferably also test).
As I understood the original intention is to replace Gavel validation by arbitrary validation. In that case the usage of Gavel as a validator should be opted-out, meaning Gavel must not be called in the first place.
Perhaps, a hooks.validate()
hook to perform the validation by yourself? It would be required to meet the Gavel's unified validation result structure in that case. It's quite generic at this point, so it's not coupled with any kind of underlying validator. This way the input to Dredd would be reliable, as there can be multiple things related on the validation result (argument against manual transaction
mutation to imitate custom validation).
Gavel
currently uses a simple text diff to validateHTML
response entity bodies. I would likeGavel
to supportX/HTML
validation in the future usingXML Schema
. However, here is how I am circumventingGavel
validation, and validating a response myself.As a user, I want to replace
Gavel
validation in cases where testing a transaction could not feasibly pass because a real response body will never equal an expected response body.Perhaps there could be a
hooks.validation()
orhooks.duringValidation()
that allows for an alternative toGavel
. Perhaps there could also betransaction.pass
, with similar intention astransaction.fail
, to pass before or duringGavel
validation.