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

Visual Studio Extension does not acknowledge setting 'stepDefinitionSkeletonStyle' #18

Closed UL-ChrisGlew closed 1 month ago

UL-ChrisGlew commented 1 month ago

Used Visual Studio

Visual Studio 2022

Are the latest Visual Studio updates installed?

Yes

Content of reqnroll.json (if present)

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

Issue Description

It appears that the VS2022 Extension does not currently change behavior when setting the 'stepDefinitionSkeletonStyle' to 'RegexAttribute'.

The expected behavior is that the 'Define Steps' button should show Regex-based step definitions, but will always seem to show Cucumber expressions.

I have had a dig into the codebase, with @timothy-plummer-ul and it seems like the main culprit is the following line:

image

When using Reqnroll, the flag for 'ReqnrollProjectTraits.CucumberExpression' is always set here, and does not appear to check the config file for it's value inside the 'ReqnrollProjectSettingsProvider' class:

image

I have experimented with reading from the config file, which seemed to enable the expected behavior of the config point, so it seems like this is a bug in the extension.

Steps to Reproduce

  1. Create a new Reqnroll project
  2. Add a 'reqnroll.json' file into the project with the following: { "trace": { "stepDefinitionSkeletonStyle": "RegexAttribute" }}
  3. Create a new feature file and add a new, undefined step definition.
  4. Right-click and select 'Define Steps'
  5. A dialog should appear, showing the suggested definitions. These should be using Regex, but are currently still using Cucumber.

Link to a project repository that reproduces the issue

No response

gasparnagy commented 1 month ago

Hm... the referred code is just for the "default" expression style. I think that is OK, the question is why isn't it overridden.

@clrudolphi can hopefully find the root cause.

clrudolphi commented 1 month ago

@gasparnagy I could use some guidance on how to proceed. As best I can understand, the ReqnrollConfigDeserializer ignores the setting. It is interested in the feature language and binding Culture settings. I can't find the code (in the VisualStudio project) that reads from the trace section of the config file. The ReqnrollProjectSettingsProvider class appears to always set the CucumberExpression trait of the ReqnrollProjectTraits enum. I can't find anywhere in the code where the trace section would override that to turn that flag off.

Oddly enough, when I attempt to recreate this through the Tests/Specs, the opposite occurs. I can get Regex to work but not Cucumber. Is that because the stubs don't support that? Please review the tests I've written on my own branch at: RnRVS_GH18 TIA

gasparnagy commented 1 month ago

@clrudolphi I did check 😆 It is not using the config, because it is not implemented in the VS extension.... 😀

Background: In SpecFlow those who had the special cucumber expression plugin wanted cucumber expression snippets anyway. And in case of the cucumber expression plugin we were setting the special trait, so the "default" snippet calculation was "good enough" and no one missed the config. But now the trait is always set for Reqnroll, so the config is getting important again. We need to implement that.

In the Tests/Specs maybe the cuke ex trait is not set on the stubbed project and this is why you get a different default as usual. It would be good to change the stub to have the cuke ex trait by default. This can be done in StubProjectSettingsProvider at this line. This will break one of the existing scenarios, but the scenario text can be modified accordingly. Your scenarios are good, I would only keep the second one.

The implementation might be something like:

clrudolphi commented 1 month ago

@gasparnagy : Thanks for the pointers. Almost done. One discrepancy has crept up. The Documentation for Reqnroll here indicates that the relevant Trace setting is called stepDefinitionSnippetStyle.

stepDefinitionSnippetStyle | CucumberExpressionAttribute / RegexAttribute | Specifies the default step definition style.Default: CucumberExpressionAttribute

The schema for the Reqnroll.json file however, says that the element should be "stepDefinitionSkeletonStyle" "$schema": "https://schemas.reqnroll.net/reqnroll-config-latest.json"

Which is correct? For now, I'm implementing this as if the schema is correct and the docs are wrong.

gasparnagy commented 1 month ago

Unfortunately the "skeleton" one is the correct. https://github.com/reqnroll/Reqnroll/blob/main/Reqnroll/Configuration/JsonConfig/TraceElement.cs#L25

(The "snippet" is the cucumber compatible term and "skeleton" was a term I introduced 15 years ago, but I can't get rid of that, it seems.)

clrudolphi commented 1 month ago

Would you like the Documentation page updated to have it match the schema?

clrudolphi commented 1 month ago

Latest code is now at this branch: https://github.com/clrudolphi/Reqnroll.VisualStudio/tree/GH18

clrudolphi commented 1 month ago

Since it uses the 'skeleton' term, I'll create a PR.

gasparnagy commented 1 month ago

Fixed by #19