Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cucumber Expressions: Non Capture Group #131

Closed
KyleFairns opened this issue Mar 10, 2017 · 6 comments
Closed

Cucumber Expressions: Non Capture Group #131

KyleFairns opened this issue Mar 10, 2017 · 6 comments
Labels
🐛 bug Defect / Bug ⚡ enhancement Request for new functionality

Comments

@KyleFairns
Copy link

KyleFairns commented Mar 10, 2017

Summary

I'm linking to the issue that I created over in the cucumber-js repo here in order to trace back the whole conversation.

There are many cases in our step definitions where we have a varity of repeated groups that don't change the steps functionality, but does do quite a bit for readablilty in the feature files:

  • "must"/"should"
  • optional words like "the", "I" etc that would match Given I fill in "Foo" & And fill in "Bar"
  • lists of interchangable words

Say that you are using these alternatives across a large set of step definitions and you wish to change them all. This is where the problem (and the solution) both appear.

Current way of completing the task

At current, we can do alternatives like so:

Given('{pronoun} have/has {int} child(ren)', (pronoun, childCount) => {
  // Code that does not require the "pronoun" parameter at all
});

However, this does mean that we have a parameter that is never actually used in the step definition that we have and this is the only way of storing the list to be used in many differing steps.

Possible Solution

Perhaps square brackets could be used for things that don't need to be captured, but still require the transformation.

Given('[pronoun] have/has {int} child(ren)', (childCount) => {
   // Code
});

When('[pronoun] picks up {stringInDoubleQuotes} from {stringInDoubleQuotes}', (child, place) => {
   // Code
});

Then('[pronoun] should have {int} child(ren) in [pronoun] care', (childCount) => {
  // Code
});

Another plus side, is that if the parameter needs to be captured, the only difference would be the brackets that you use in that step definition:

  Then('{pronoun} does something', (pronoun) => {
     if(pronoun == "Jeff"){
        // Do something different for Jeff
     } else {
       // Do your thing
     }   
  });

Context & Motivation

We will be working with cucumber on a wide variety of projects in our company and I can guarantee that many of them will require a large number of declaratively written step definitions that require many alternatives that won't be captured for use within the step definitions.

This would make it easier for us to keep track of all of the alternatives that we will be using, and will mean that we wont have to search through the many step definition files for all of the uses..

And I am certain that others in the cucumber community will be in the same situation as I.

@mattwynne
Copy link
Member

mattwynne commented Mar 10, 2017

Couldn't you just use regular string interpolation here?

i.e.

const pronoun = "He/She"
Given(`${pronoun} have/has {int} child(ren)`, (childCount) => {
  // Code that does not require the "pronoun" parameter at all
});

@aslakhellesoy
Copy link
Contributor

In JavaScript and Ruby you could, @matt, but not in Java or C#.

Further, it becomes cumbersome to use this consistently across different stepdef files.

@KyleFairns
Copy link
Author

I've completed the changes for this, but I don't believe I have the right permissions to complete a pull request.

Permission to cucumber/cucumber.git denied to KyleFairns. appears when I try to push to a new branch

There was only one file changed for the code, and three tests were removed that tested the escaping of square brackets (however, they are now special characters in terms of cucumber-expressions).

Is there a way for me to gain those permissions, or would you like me to just post the changes below?

@aslakhellesoy
Copy link
Contributor

aslakhellesoy commented Apr 8, 2017

You have to fork the repo, clone your fork, create a branch for your change, push to your fork and then make a pull request.

See https://help.github.com/articles/creating-a-pull-request-from-a-fork/ and https://help.github.com/articles/creating-a-pull-request/ for details.

@aslakhellesoy
Copy link
Contributor

Closed due to inactivity

@lock
Copy link

lock bot commented Oct 24, 2018

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.

@lock lock bot locked as resolved and limited conversation to collaborators Oct 24, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
🐛 bug Defect / Bug ⚡ enhancement Request for new functionality
Projects
None yet
Development

No branches or pull requests

3 participants