reqnroll / Reqnroll.VisualStudio

Visual Studio extension for Reqnroll - open-source .NET BDD framework
https://reqnroll.net
BSD 3-Clause "New" or "Revised" License
10 stars 3 forks source link

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

Closed TimMurphy closed 1 month ago

TimMurphy commented 1 month ago

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 commented 1 month ago

@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 commented 1 month ago

Thanks

On Wed, 19 June 2024, 01:48 Chris Rudolphi, @.***> wrote:

@gasparnagy https://github.com/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.

— Reply to this email directly, view it on GitHub https://github.com/reqnroll/Reqnroll.VisualStudio/issues/28#issuecomment-2176429373, or unsubscribe https://github.com/notifications/unsubscribe-auth/AADFDDRHQUJPGLF4KPYD5L3ZIBJGRAVCNFSM6AAAAABJMIOK46VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCNZWGQZDSMZXGM . You are receiving this because you authored the thread.Message ID: @.***>

clrudolphi commented 1 month ago

@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 commented 1 month ago

@clrudolphi

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

gasparnagy commented 1 month ago

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

gasparnagy commented 1 month ago

@TimMurphy Thank you for your sponsorship! 🙏🤘

TimMurphy commented 1 month ago

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.