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

Upgrade to Cucumber Expressions 3.0.0 #764

Closed
wants to merge 8 commits into from

Conversation

aslakhellesoy
Copy link
Contributor

@aslakhellesoy aslakhellesoy commented Feb 17, 2017

This PR upgrades to Cucumber Expressions 3.0.0, which has several improvements.

This PR also removes the custom logic to compute parameter names in snippet functions, and uses the logic provided by the cucumber-expressions library instead.

Copy link
Member

@jbpros jbpros left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great!

The build is failing because of ES features (class) used by cucumber-expressions that are not available on Node 4.

Should we just add cucumber-expressions to the files transpiled by babel?

.gitignore Outdated
@@ -3,3 +3,4 @@
lib/
node_modules
usage.txt
.idea/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer if we avoided IDE-specific exclusions.

It's often recommended to do that locally so that we don't have to worry about everyone's preferred IDEs/editors.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we add it to the repo, then we don't have to worry about some git noob adding their whole IDE config folder in a PR.

Is this really worth worrying about?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If a "git noob" sends a PR with the whole .idea folder checked in, it would be a great opportunity to teach them a bit more about Git 👍

But no, it's probably not worth discussing any further. I told you my preference, you decide.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm with @jbpros here. I believe anything that is not universal to this project belongs in your local global gitignore.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just my two cents: We don't have to "worry" about everyone's preferred IDE, if we just accept their addition to the gitignore whenever it comes. Also, I'm guessing this won't be the last time someone tries to add .idea/ to the gitignore.

But I agree, either way this isn't worth worrying about lol

console.error('addTransform is obsolete and will be removed in a future version. Please use addParameter instead.')
}
addParameter({captureGroupRegexps, transformer, typeName})
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer not to have function definitions in here. Can these be moved into helpers? Similar to how After/Before/defineStep work.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 47d54ec

// eslint-disable-next-line no-console
if (console !== 'undefined' && typeof console.error === 'function') {
// eslint-disable-next-line no-console
console.error('addTransform is obsolete and will be removed in a future version. Please use addParameter instead.')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use util.deprecate here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh nice, wasn't aware of that one.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in d4d4728

})
"""
When I run cucumber.js
Then the step "a passing step" has status "passed"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a newline to the end of this file. Thanks for writing this feature test!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in d7642f0

@aslakhellesoy
Copy link
Contributor Author

The cucumber-expressions library's main script is dist/index.js, which is transpiled by Babel and included in the npm package. Looks like it's not ES5 code though. I'm going to have to tweak cucumber-expressions' Babel settings.

@charlierudolph
Copy link
Member

@aslakhellesoy I'm uncertain about changing the API to addParameter. That method name doesn't tell me enough about what it does. Thats the internal cucumber expression name but doesn't need to be the public facing API. I envision this being used mostly for actual transforms instead of merely naming certain capture group regular expressions but I could be wrong. I believe the transformer function is required at the moment too.

@aslakhellesoy aslakhellesoy changed the title Upgrade to Cucumber Expressions 2.0.0 Upgrade to Cucumber Expressions 2.0.1 Feb 26, 2017
@aslakhellesoy
Copy link
Contributor Author

The {...} parts of cucumber expressions are called parameters (the equivalent of a RegExp capture group).

Custom parameter types can be registered, and they have a name, pattern (or list of patterns) and a transform function. For convenience there are a couple of "built-in" transforms for float and int.

It's important to establish a ubiquitous language for the various Cucumber implementations, both for the API and the documentation. Ideally Cucumber would provide an API that is identical to the "internal" Cucumber Expressions API. I did design the external API of Cucumber Expressions to be "user friendly". I think parameter and parameter type are better names than transform for a few reasons.

The term parameter is a familiar concept in programming. It allows us to say things like: "The I have {int} cukes in my {bodypart} expressions has two parameters". It would be weird to say it has two transforms.

A parameter doesn't necessarily have to transform a string - it could leave it unchanged. A custom parameter is still useful in many cases, typically when we want to restrict matching to a particular pattern, such as /red|blue|yellow/. (Currently the API requires an explicit transform function, but we could make that optional (and default an identity function) in a future release of Cucumber Expressions.

Maybe it would be better to rename addParameter to defineParameterType, because we're not really adding a parameter, we're defining a parameter type that can be used by parameters in expressions.

Regarding the Cucumber API - I think it would be better to use positional arguments (as described in the docs) rather than named ones. The addParameter method is polymorphic - the 3rd argument, captureGroupRegexps can be a RegExp or an array of RegExp. In most cases you only need a single RegExp, and it looks weird to say captureGroupRegexps: /red|blue|yellow/. In general I do like named parameters in methods, but I think this is an exception.

@aslakhellesoy
Copy link
Contributor Author

What are your thoughts on this @charlierudolph ?

@charlierudolph
Copy link
Member

I like the rename to defineParameterType. In general I don't like positional arguments when you have 4 or more arguments. I think it makes the function call too hard to read. With regards to captureGroupRegexs. We could also support captureGroupRegex and stipulate that you must specify one and only one.

@aslakhellesoy
Copy link
Contributor Author

Ok, sounds good. I hope to release a new Cucumber Expressions in a couple of days with those renames, and a few other goodies. I'll update this PR after that, and then we should be good to go! (Plus the two other PRs I've submitted that depend on this one).

aslakhellesoy added a commit to cucumber/common that referenced this pull request Mar 8, 2017
@aslakhellesoy aslakhellesoy force-pushed the cucumber-expressions-2.0.0 branch from 2df2293 to 72c3d4a Compare March 9, 2017 09:59
@aslakhellesoy aslakhellesoy changed the title Upgrade to Cucumber Expressions 2.0.1 Upgrade to Cucumber Expressions 3.0.0 Mar 9, 2017
@aslakhellesoy
Copy link
Contributor Author

I've done the renames, can you take another look?

Copy link
Member

@charlierudolph charlierudolph left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great. Thanks @aslakhellesoy

import * as helpers from './helpers'

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add this newline back

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seriously?

.gitignore Outdated
@@ -3,3 +3,4 @@
lib/
node_modules
usage.txt
.idea/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please remove this? I strongly agree with @jbpros and would prefer to take that opportunity to teach people to use their local global gitignore.

@@ -0,0 +1,69 @@
Feature: Custom Parameter
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use parameter type instead of parameter in this title, the feature description, and the scenario titles.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually looks like this was done in one of the following PRs so this can be ignored.

@charlierudolph charlierudolph deleted the cucumber-expressions-2.0.0 branch March 9, 2017 23:54
@lock
Copy link

lock bot commented Oct 25, 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 25, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants