Tyler-Keith-Thompson / CucumberSwift

A lightweight swift Cucumber implementation
https://tyler-keith-thompson.github.io/CucumberSwift/documentation/cucumberswift/
MIT License
74 stars 19 forks source link

Code suggestion for Cucumber Expressions #57

Open uo9qsuf opened 1 year ago

uo9qsuf commented 1 year ago

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.

Tyler-Keith-Thompson commented 1 year ago

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

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.

uo9qsuf commented 1 year ago

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

Tyler-Keith-Thompson commented 1 year ago

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