Skip to content

Allow free-form text in optionals #166

Open
@rdeltour

Description

@rdeltour

🤔 What's the problem you're trying to solve?

I'd like to have optional free-form text in my steps:

For instance:

Then error 123 is reported (because reasons)

The "because reasons" string isn't fixed, the content of the parenthesis varies depending on the scenario.

✨ What's your proposed solution?

It would be nice to either:

  • have a way to use some kind of "catch-all" structure (here .*) in optionals:
    error {int} is reported( \\(.*)
  • or allow parameters in optionals
    error {int} is reported( \\({})

⛏ Have you considered any alternatives or workarounds?

I tried using an anonymous parameter:

error {int} is reported( \\(){}

and ignore the related parameter in the step definition.

but this is not possible in my case, since I also have a step for:

error {int} is reported {int} times( \\(){}

which causes an ambiguous step definition.

This is why I'd need to put the anonymous part within the optional:

error {int} is reported( \\({})

But then it is an illegal expression (parameters are not allowed in optionals).

I also tried using a comment at the end of the expression:

Then error 123 is reported #(because reasons)

but comments are only allowed as a start of a new line.

The only resort is to use a regex. But the expressions then get quite ugly and unreadable (the examples above are simplified, my real expressions are more complex).
Or move the free-form text to its own line, but it is definitely less concise and sort of breaks the scenario flow.

These two workarounds work, but are suboptimal as they unfortunately make for less readable code.

📚 Any additional context?

I recently used cucumber v4.5.4 (cucumber-java), and the following expressions just worked for my use case:

error {int} is reported( \\(.*)`
error {int} is reported {int} time(s)( \\(.*)

This stopped working when migrating to cucumber v7.8.0!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions