cucumber / language-service

Cucumber Language Service
MIT License
12 stars 21 forks source link

fix: Generate formatted Python step definitions #161

Closed kieran-ryan closed 4 months ago

kieran-ryan commented 6 months ago

🤔 What's changed?

The Python step definition snippet has been modified as follows:

Examples

When generating a Python step definition from a gherkin step...

When I eat "<eat>" cucumbers

...the step definition is indented by 2 spaces - which is invalid Python; and a space is present between the parentheses (()) and the colon (:) of the function declaration.

  @when('I eat {string} cucumbers')
  def step_when(context, string) :
      # This was autogenerated using cucumber syntax.
      # Please convert to use regular expressions, as Behave does not currently support Cucumber Expressions

Additionally, when generating a Python step definition from a gherkin step containing no parameters...

Then I should have many cucumber

...a trailing comma and space appear after context.

  @then('I should have many cucumber')
  def step_then(context, ) :
      # This was autogenerated using cucumber syntax.
      # Please convert to use regular expressions, as Behave does not currently support Cucumber Expressions

⚡️ What's your motivation?

Fixes cucumber/language-service#160, rendering formatted Python step definitions as follows:

@then('I should have many cucumber')
def step_then(context):
    # This was autogenerated using cucumber syntax.
    # Please convert to use regular expressions, as Behave does not currently support Cucumber Expressions

And with multiple parameters as follows:

Given there is a "string" and an integer of 5
@given('there is a {string} and an integer of {int}')
def step_given(context, string, int):
    # This was autogenerated using cucumber syntax.
    # Please convert to use regular expressions, as Behave does not currently support Cucumber Expressions.

🏷️ What kind of change is this?

♻️ Anything particular you want feedback on?

NA

📋 Checklist: