SpecFlowOSS / SpecFlow

#1 .NET BDD Framework. SpecFlow automates your testing & works with your existing code. Find Bugs before they happen. Behavior Driven Development helps developers, testers, and business representatives to get a better understanding of their collaboration
https://www.specflow.org/
Other
2.24k stars 754 forks source link

Parsing seems to remove curly braces from step parameter name #2502

Open mickaelleclerc opened 2 years ago

mickaelleclerc commented 2 years ago

SpecFlow Version

3.9.22

Which test runner are you using?

xUnit

Test Runner Version Number

2.4.1

.NET Implementation

.NET 5.0

Project Format of the SpecFlow project

Classic project format using <PackageReference> tags

.feature.cs files are generated using

SpecFlow.Tools.MsBuild.Generation NuGet package

Test Execution Method

Visual Studio Test Explorer

SpecFlow Section in app.config or content of specflow.json

specflow.json reference private assemblies

Issue Description

Part of my scenario contains a step like this one This in a sentence with { my tag }. my tag is a parameter of the step bind to a custom type. I wrote a transform for this custom type where the regex pattern is (^\{[a-z A-Z]+\}$)

It seems that SpecFlow removes thes curly braces while parsing the step. My transform is then never called. I tried with some characters other than alpha numeric characters with no success.

Is there any reason the curly braces are removed after parsing ?

Steps to Reproduce

Create a parameterized step where the parameter in the sentence is wrapped within curly braces.

Link to Repro Project

No response

clrudolphi commented 2 years ago

I believe this is working. I put together a small test project to attempt to recreate your problem.

With a feature file containing: `'' Scenario: TestingStepArgConverter Given a myclass of {myv} ''' and a binding class of:

'''csharp

[Binding]
public class SF2502StepArgumentTransformsUsingCurlyBraces
{
    [StepArgumentTransformation(@"^(\{[a-z A-Z]+\})$")]
    public MyClass ConvertToMyClass(string v)
    {
        return new MyClass(v);
    }

    [Given(@"^a myclass of (.*)$")]
    public void TestMyClass(MyClass x)
    {
        x.v.Should().Be("{myv}");
    }
}

public class MyClass
{
    public string v;
    public MyClass(string v)
    {
        this.v = v;
    }
}

''' In order to get this to work, I added a set of parenthesis around the curly braces in order to tell the regex to capture the entire string - that then becomes the string argument passed to the StepArgumentTransformation method (in this example: ConvertToMyClass() ).

Were you able to work around your problem? Can this bug/issue be closed?