Cucumber-jvm: Add support for Cucumber Expressions

Created on 9 Aug 2016  Â·  16Comments  Â·  Source: cucumber/cucumber-jvm

Summary

Cucumber Expressions is a new alternative to
Regular Expressions, which is easier to read and write, and less daunting.

Expected Behavior

Step Defintions that don't start with a ^ or end with a $ should be interpreted as a Cucumber Expression:

@Given("I have {n} cukes in my belly")

Alternatively we can decide to use regular expressions if the string uses / delimiters:

@Given("/I have (\\d+) cukes in my belly/")

Whatever mechanism we choose to differentiate is likely to break existing step definitions, so we'd have to make a new major release and document how to migrate.

Snippets for undefined steps should use Cucumber Expressions, and not Regular Expressions. We want users to start migrating, and if we can avoid it we'll not generate snippets with regular expressions. (Well, we might if enough people want it). The cucumber-expression library can already generate expressions from text.

Finally, the current Transform logic should be deprecated and the logic built into the cucumber-expression library should be used instead.

Context & Motivation

Having to use Regular Expressions is one of the most common complaints against Cucumber. Other clones of Cucumber who support something similar to Cucumber Expressions seem to have happier users!

pinned enhancement

Most helpful comment

Thanks for waiting!

All 16 comments

This looks great! I tried to see what versions supported it but this link
in the documentation (http://docs.cucumber.io/cucumber-expressions/) seems
to be broken:

http://docs.cucumber.io/standard-library.adoc#implementations

Also, the documentation has this text:

You may have a Color class that you want to use to capture the red part of
the step, but unless you register a transform for that class, Cucumber
won't be able to recognise that. Let's register a transform for Color:

But the Java example below uses the Currency class and not the Color class.
The Javascript and Ruby ones use Color. Just in case you want to correct
the documentation.

Bill

On Mon, Aug 8, 2016 at 5:43 PM Aslak Hellesøy [email protected]
wrote:

Summary

Cucumber Expressions http://docs.cucumber.io/cucumber-expressions/ is a
new alternative to
Regular Expressions, which is easier to read and write, and less daunting.
Expected Behavior

Step Defintions that don't start with a ^ or end with a $ should be
interpreted as a Cucumber Expression:

@Given("I have {n} cukes in my belly")

Alternatively we can decide to use regular expressions if the string uses
/ delimiters:

@Given("/I have (\d+) cukes in my belly/")

Whatever mechanism we choose to differentiate is likely to break existing
step definitions, so we'd have to make a new major release and document how
to migrate.

Snippets for undefined steps should use Cucumber Expressions, and not
Regular Expressions. We want users to start migrating, and if we can avoid
it we'll not generate snippets with regular expressions. (Well, we might if
enough people want it). The cucumber-expression library can already
generate expressions from text.

Finally, the current Transform logic should be deprecated and the logic
built into the cucumber-expression library should be used instead.
Context & Motivation

Having to use Regular Expressions is one of the most common complaints
against Cucumber. Other clones of Cucumber who support something similar to
Cucumber Expressions seem to have happier users!

—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/cucumber/cucumber-jvm/issues/1041, or mute the thread
https://github.com/notifications/unsubscribe-auth/AAo43LBH9cMRQLFXHV0S_OpgwlheCEVGks5qd78-gaJpZM4JflbC
.

I just pushed a fix - better now?

Are Cucumber Expressions already supported in an official release? If not, how can we try them out? I cannot find any explanation on how to integrate them.

Thanks,
V.

The Cucumber-Expressions library is implemented, but not integrated into Cucumber-JVM yet. That's why this ticket is open.

Thanks for the fast reply!
Is it maybe available in a snapshot version upload in a maven repo somewhere? I'd love to check them out

No they're not integrated yet

No there no Cucumber-JVM version where cucumber-experssions has been integrated, it does require a quite substantial amount of work to do that - work that has been started but it is still WIP.

Ok, thanks guys for the Speedy Gonzalez reaction. Will use normal reg exp for now and move to cucumber expressions later.

Cheers,
V.

Waiting for integration!

Thanks for waiting!

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in a week if no further activity occurs.

How would you use cucumber expressions for something like this
"^the client has an account balance of \$([\-\d,\d+\.\d+]*)$"

The links on this post don't work anymore but I found this: https://docs.cucumber.io/cucumber/cucumber-expressions/
But this doc still says that you can use reg ex or cuke expressions. Not sure if this doc is old too.

I'm also looking at these examples that show reg ex. So is reg ex still allowed in cucumber version 3.0.2?
https://github.com/cucumber/cucumber/blob/master/cucumber-expressions/java/src/test/java/io/cucumber/cucumberexpressions/RegularExpressionTest.java

Heya, you're better of asking further questions on Slack of the mailing list. Maintainers don't scale. :D

  1. the client has an account balance of ${bigDecimal}
  2. Regular expressions and Cucumber expressions are both supported.
  3. Because XStream was removed your regular expression won't be transformed into a big decimal straight away. You'll have to register it as a parameter type.
  4. Version 4.2 supports anonymous parameter types which will make a best effort attempt.

I did try 4.2.0 which works with my steps from cucumber 1.x.x without any changes but I'm waiting for the mutation plugin and the pro-plugin to also be updated in order to use 4.2.0. Until then I would like to have this working with 3.0.2

the client has an account balance of ${bigDecimal} doesn't seem to be working with v3.0.2
My reg ex covered all my scenarios that uses $20,000.50, $0.00 and $-1.00
How do I get my reg ex to work in this new version?

Ah. Maybe it's all lowercase. Check the docs.

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings