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

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

Closed
UL-ChrisGlew opened this issue Jun 3, 2024 · 9 comments
Labels
enhancement New feature or request

Comments

@UL-ChrisGlew
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

@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
Copy link
Contributor

@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:

  • Define a property in the DeveroomConfiguration class for the snippet style (type SnippetExpressionStyle).
  • Populate the value of the setting from the config file in ReqnrollConfigDeserializer. You need to add one more untyped property (Dictionary<string, string> Trace) to ReqnrollJsonConfiguration for that.
  • Check the two usages of SnippetService.DefaultExpressionStyle and rework them somehow that they should give a precedence to the configured value. You can always get the configuration from a project scope with projectScope.GetDeveroomConfiguration().

@gasparnagy gasparnagy added the enhancement New feature or request label Jun 4, 2024
@clrudolphi
Copy link
Contributor

@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
Copy link
Contributor

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
Copy link
Contributor

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

@clrudolphi
Copy link
Contributor

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

@clrudolphi
Copy link
Contributor

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

gasparnagy pushed a commit that referenced this issue Jun 5, 2024
…tionSkeletonStyle' (#18)

* FIX for GH18

Fix for GH18. Modified the way Reqnroll.json is deserialized to pull in the values from the 'Trace' element. Sets a new property on DeveroomConfiguration to reflect the json config. Modified the SnippetService to use that value (rather than the Traits) when creating the snippet provider.

* GH18: Corrected one existing DefineStepsCommand.feature scenario since the stubbed configurations now set the default to be CucumberExpression.
@gasparnagy
Copy link
Contributor

Fixed by #19

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants