cucumber icon indicating copy to clipboard operation
cucumber copied to clipboard

Generate Default Steps If None Exist

Open tscritch opened this issue 4 years ago • 3 comments

If this feature already exists I apologize, but I can't seem to find it if it does.

I would like cucumber to output (whether in the console or a file) a default steps implementation if the scenario steps cannot be found but there is an existing feature file. I know other versions of cucumber do this for other languages/testing frameworks.

My guess is that this would be fairly straightforward given we have the feature file parsed and can generate a basic/empty steps builder. I would love to contribute this feature if it is something wanted.

example.feature

Feature: Example feature
  Scenario: An example scenario
    Given I am trying out Cucumber
    When I consider what I am doing
    Then I am interested in ATDD
    And we can implement rules with regex

output (something like this):

let mut builder: Steps<crate::MyWorld> = Steps::new();

builder
  .given_async(
      "I am trying out Cucumber",
      t!(|mut world, _step| {
          world
      })
  )
  .when_regex_async(
      "I consider what I am doing",
      t!(|world, _matches, _step| {
          world
      }),
  )
  .then("I am interested in ATDD", 
      t!(|world, _step| {
          world
      })
  )
  .then("we can implement rules with regex",
      t!(|world, _step| {
          world
      })
  );

tscritch avatar Feb 22 '21 18:02 tscritch

Hey! It is not yet something that exists, and I am aware of what other languages do. It's a neat feature, but I've always felt it... wasn't enough.

My more ambitious plan is to use a Cucumber-aware extension to the language server to allow autocompleting steps based on feature files. This is one reason I wrote the gherkin crate, so I had control over the AST to enable this. :smile:

But that's a while off. I'd be happy to accept a PR that implements something like this in the interim if you have a good proposal on how to go about it.

bbqsrc avatar Feb 22 '21 22:02 bbqsrc

@tyranron I'm not really sure, if we want this feature. Sounds like it violates feature coupled step definitions anti-pattern.

If you are sure, that we want it, I'm strongly against solutions around auto-generating .rs files with build.rs, as it will be painful to setup. And simplicity of this feature is vital, as it's especially useful for newcomers.

But we can pretty easily implement custom Writer, which will output code for implementing steps:

[Summary]
1 feature
4 scenarios (4 skipped)
4 steps (4 skipped)

You can implement missing steps with the snippets below:

#[given(regex = r"wait 1 sec")]
#[when(regex = r"wait 1 sec")]
#[then(regex = r"wait 1 sec")]
async fn wait_1_sec(world: &mut MyWorld) {}

ilslv avatar Oct 21 '21 12:10 ilslv

Discussed:

We don't want this feature for now, because of mentioned feature coupled step definitions anti-pattern. Also in v0.10 preferred way of describing steps is more ergonomic proc-macro attributes (examples of usage can be found in Getting Started chapter of the book). Additionally in v0.10 were introduced features for managing complexity (see Test Modules Organization chapter). Mentioning all that we don't see that feature as being all too useful. But we'll leave this issue opened as a reminder for moonshot goal of cucumber-aware language server.

@tscritch can you please describe your workflow? Maybe we are missing something that makes this feature more useful.

ilslv avatar Oct 21 '21 13:10 ilslv

The vscode cucumber plugin now supports https://github.com/cucumber/vscode

GoooIce avatar Oct 18 '22 00:10 GoooIce

I guess we can close this now. Despite being a controversial feature, it really feels like a responsibility of external tooling, rather than Cucumber itself.

Feel free to reopen, if there will be much demand of this.

tyranron avatar Oct 18 '22 07:10 tyranron