CucumberSwift icon indicating copy to clipboard operation
CucumberSwift copied to clipboard

Code suggestion for Cucumber Expressions

Open uo9qsuf opened this issue 2 years ago • 4 comments

Code suggestion for Cucumber Expressions. At moment I get only suggestion in regex format.

testGherkin(): No CucumberSwift expression found that matches this step. Try adding the following Swift code to your step implementation file: 
When("^I execute the three \\{(\\d+)\\} tests$") { matches, _ in
    let integer = matches[1]
}

Solution can be a mode which the developer can set in the info plist for change from regex to Cucumber Expressions. On this way we can remove the "as CucumberExpression" in the steps.

@Tyler-Keith-Thompson If you can say me there I can at this support I can help you.

uo9qsuf avatar Nov 30 '22 12:11 uo9qsuf

So I can certainly add step suggestions that make use of expressions. Could potentially even get clever and find a way to give both as an option. I'll add that as an enhancement request.

That said, a plist setting to default to expressions won't work because a plist is runtime configuration and expressions vs regex is a compile-time concern.

It could be solved with codegen or clever imports, but I have a different solution in mind.

With regex literals added to Swift and supported by CucumberSwift we can just make a breaking change. Strings can be considered expressions and regex literals would of course be regex. This lines up well with other Cucumber implementations in other languages.

My only hesitation is I'm uncertain if most enterprise consumers are prepared to use regex literals or refactor all existing CucumberSwift tests to use expressions. In an ideal world I could use fixits to have the compiler do the heavy lifting.

Give me some time to ponder how to best support those with slower moving processes, but I think we can make the change so you can quit using "as CucumberExpression"

Tyler-Keith-Thompson avatar Nov 30 '22 17:11 Tyler-Keith-Thompson

Update: I've released a version that deprecates the string-based function. I'm gonna leave that for maybe a month and then I'll change behavior so that strings use expressions and regex literals work for regex.

As far as expression code suggestions I'll add that to the backlog.

Tyler-Keith-Thompson avatar Dec 08 '22 18:12 Tyler-Keith-Thompson

@Tyler-Keith-Thompson call thank you. I don't need anymore to case the expressions.

uo9qsuf avatar Dec 12 '22 10:12 uo9qsuf

Update: v4.0.5 removes the requirement to use "as CucumberExpression".

Tyler-Keith-Thompson avatar Feb 12 '23 22:02 Tyler-Keith-Thompson