dart_gherkin icon indicating copy to clipboard operation
dart_gherkin copied to clipboard

Failing a step in a `onAfterStep` hook

Open are opened this issue 3 years ago • 0 comments

Hi! First of all thank you for maintaining this library, I know how hard it is to do work in open-source. I appreciate it!

Context

We are using this package to run custom contract tests. We are using the gherkin runner as one of the parts of the whole testing structure.

Currently we are on a roadblock: after each step in a scenario we need to confirm that the contract is being upheld, and in case the contract is broken we need to fail the step (even if the step executed successfully). One way we can implement it is to add an expect assertion in each step definition, but that can be troublesome because 1. we need to repeat this in each step, 2. forgetting to add this the definition can give way to bugs.

Fortunately the cucumber standard has hooks that seem to do fill this void perfectly.

However, in this package, there is no way to influence the "result" of a step in the onAfterStep hook, so the only option is to throw. But throwing interrupts the execution of the step, so reporter is not being called and the exception is propagated upwards.

Question

Would it be desirable to add a feature where the result of a step can be failed in a hook (and that causes the rest of the steps to be skipped and properly reported)?

I can definitely submit a proof of concept PR. Let me know if that is something thats worth pursuing for this library in general.

are avatar May 11 '21 16:05 are