Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Define Steps does produces incorrect regex for step definition attribute #28

Closed
TimMurphy opened this issue Jun 16, 2024 · 7 comments
Closed

Comments

@TimMurphy
Copy link

Used Visual Studio

Visual Studio 2022

Are the latest Visual Studio updates installed?

Yes

Content of reqnroll.json (if present)

{
  "$schema": "https://schemas.reqnroll.net/reqnroll-config-latest.json",

  "bindingAssemblies": [
      {
          "assembly": "CroquetScores.TestHelpers"
      }
  ]
}

Issue Description

When a step in a feature includes brackets (), the regex for the step definition created by Define Steps... is incorrect .

As an example if you have the following step

When I call the integer.ToString()

The generated step is:

[When("I call the integer.ToString\\)")]
public void WhenICallTheInteger_ToString()
{
    throw new PendingStepException();
}

Notice how the brackets of the steps are written as \). The generated code should be:

[When(@"I call the integer.ToString\(\)")]
public void WhenICallTheInteger_ToString()
{
    throw new PendingStepException();
}

Steps to Reproduce

Create a feature with the following scenario.

Scenario: Brackets example
	Given I have the integer '2'
	When I call the integer.ToString()
	Then the result should be a string '2'

Right click in the feature file and select Define Steps....

The Define Steps window will show the when step as

[When("I call the integer.ToString\\)")]
public void WhenICallTheInteger_ToString()
{
     throw new PendingStepException();
 }

Link to a project repository that reproduces the issue

No response

@clrudolphi
Copy link
Contributor

@gasparnagy - I've attempted to find an authoritative source online for what characters are legal in a step, but not having any luck finding anything that addresses this question. Which non-alphanumeric characters are allowed (or not allowed)?
With that, I'll take a look at what needs to be changed to address this issue.

@TimMurphy
Copy link
Author

TimMurphy commented Jun 18, 2024 via email

@clrudolphi
Copy link
Contributor

@TimMurphy here are my findings so far.
When using the default stepDefinitionSkeletonStyle of Cucumber expressions, I get the same behavior you note in this issue.
When I use the older Regex style, I get the following code skeleton generated by the "Define Steps..." Command:

        [When(@"I call the integer\.ToString\(\) method")]
        public void WhenICallTheInteger_ToStringMethod()
        {
            throw new PendingStepException();
        }

Would the above work for you? Are you wanting to use Regex expressions or Cucumber expressions?
If the above is OK, then try using the Regex style snippet generator by modifying your reqnroll.json configuration file and insert the following:

"trace": { "stepDefinitionSkeletonStyle": "RegexAttribute" },

See the Documentation for details on the reqnroll.json configuration file.

HTH.
I'll keep looking for an explanation of the behavior while using the Cucumber expression style.

@TimMurphy
Copy link
Author

@clrudolphi

That works perfect;y. Thanks for that and for all your work to create and main Reqnrol

@gasparnagy
Copy link
Contributor

For the record, the cucumber expression syntax specification is here: https://github.com/cucumber/cucumber-expressions?tab=readme-ov-file#escaping

@gasparnagy
Copy link
Contributor

@TimMurphy Thank you for your sponsorship! 🙏🤘

@TimMurphy
Copy link
Author

For the record, the cucumber expression syntax specification is here: https://github.com/cucumber/cucumber-expressions?tab=readme-ov-file#escaping

Good to know but I rather have "clean" specs with regex steps.

gasparnagy pushed a commit that referenced this issue Jun 20, 2024
…inition (#28) (#29)

* Proposed fix for GH28

* Revised CucumberExpressionSkeletonProvider and Spec test to reflect code review comments.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants