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

Call another step from current #66

Closed Hsilgos closed 1 year ago

Hsilgos commented 1 year ago

Hi. I'm looking for replacement of Cucumberish and I think CucumberSwift is good alternative. Unfortunately there is a problem for which I haven't found a good workaround. Cucumberish provides function SStep(definition) which allows to call a step during execution of the current step:

class MySteps: StepImplementation {
  public func setupSteps() {
        Given("Some basic setup") { _, _ in
        }

        Given("Some additional setup") { _, _ in
           // Blah blah
           // Calling basic setup.
           SStep("Some basic setup")
        }
    }
}

Why is it important? I use Cucumber to automate tests for Java and Swift and logic is very similar in both languages. In Java it's necessary to declare function with name for each step and when it's necessary this function can be called directly... But in CucumberSwift (and Cucumberish) almost always lambdas are used.

Yes, it's possible to extract logic to function and call this function:

class MySteps: StepImplementation {
  public func setupSteps() {
        Given("Some basic setup") { _, _ in
           self.someBasicSetup()
        }

        Given("Some additional setup") { _, _ in
           // Blah blah
           // Calling basic setup.
           self.someBasicSetup()
        }
    }

   fun someBasicSetup() {
   }
}

but readability and test report really suffer.

So it would be nice to either provide a way to call step from step like Cucumberish's SStep(...) does. Looking at implementation in Cucumber.swift it doesn't look too complicated.

Tyler-Keith-Thompson commented 1 year ago

This seems reasonable. I'd like to dream up a better API surface than SStep (looks like a typo). Maybe something like executeFirstStep(matching: "some string").

I'm slammed with work at the moment so I won't be able to turn this around super quickly. PRs are welcome, when my schedule eases up I'll put this on the Kanban board so that it's obvious it's being addressed.

Hsilgos commented 1 year ago

This seems reasonable. I'd like to dream up a better API surface than SStep (looks like a typo). Maybe something like executeFirstStep(matching: "some string").

I'm slammed with work at the moment so I won't be able to turn this around super quickly. PRs are welcome, when my schedule eases up I'll put this on the Kanban board so that it's obvious it's being addressed.

Sure, I've made a small change. I'll publish as soon as add unit tests