alexkrechik / VSCucumberAutoComplete

Cucumber (Gherkin) Full Support Extension for VSCode
https://marketplace.visualstudio.com/items?itemName=alexkrechik.cucumberautocomplete
MIT License
331 stars 82 forks source link

With strictGherkinCompletion, step with mismatched keyword is marked as valid #241

Closed mtkennerly closed 5 years ago

mtkennerly commented 5 years ago

Describe the bug With strictGherkinCompletion turned on, step autocompletion correctly only shows matches with the same keyword. However, once you have fully typed the step, it is marked as valid and you can jump to its definition even though it has the wrong keyword.

To Reproduce Create these files:

Open the feature file. When some multiword condition will not be flagged as invalid, and you can jump to the definition of the given version.

Expected behavior In this example, When some multiword condition should be flagged as invalid.

Screenshots image

Cucumberautocomplete part of VSCode settings:

{
    "cucumberautocomplete.steps": [
        "steps/*.py"
    ],
    "cucumberautocomplete.gherkinDefinitionPart": "@(given|when|then)\\(",
    "cucumberautocomplete.strictGherkinCompletion": true
}

Gherkin step line When some multiword condition

alexkrechik commented 5 years ago

Will you cucumber runner fail for such steps ?

mtkennerly commented 5 years ago

Yeah, it does. Here's the output from Behave:

$ behave
Feature: Demo # features/demo.feature:1

  Scenario: A                     # features/demo.feature:2
    When some multiword condition # None

You can implement step definitions for undefined steps with these snippets:

@when(u'some multiword condition')
def step_impl(context):
    raise NotImplementedError(u'STEP: When some multiword condition')

Failing scenarios:
  features/demo.feature:2  A

0 features passed, 1 failed, 0 skipped
0 scenarios passed, 1 failed, 0 skipped
0 steps passed, 0 failed, 0 skipped, 1 undefined
Took 0m0.000s

Changing When to Given in the feature file:

$ behave
Feature: Demo # features/demo.feature:1

  Scenario: A                      # features/demo.feature:2
    Given some multiword condition # steps/demo.py:4

1 feature passed, 0 failed, 0 skipped
1 scenario passed, 0 failed, 0 skipped
1 step passed, 0 failed, 0 skipped, 0 undefined
Took 0m0.000s
alexkrechik commented 5 years ago

strictGherkinCompletion option was designed for completion purpose only. Anyway, most runners will not fail in case of gherkin word mistmatch, so we can't add such checking in case for strictGherkinCompletion: true. As a variant, some alternative option like strictGherkinChecking could be added in some future release.

mtkennerly commented 5 years ago

Got it, that makes sense. I'm surprised that other runners wouldn't fail, but I just tried it in Ruby/Cucumber, and it passed.

alexkrechik commented 5 years ago

strictGherkinValidation option added in 2.14.0 should correctly handle your case.