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

Duplicated stepdefs do not throwing any error?! #176

Closed
shuai-zh opened this issue May 15, 2014 · 8 comments
Closed

Duplicated stepdefs do not throwing any error?! #176

shuai-zh opened this issue May 15, 2014 · 8 comments
Milestone

Comments

@shuai-zh
Copy link

I made two step definitions with completely the same regex in 2 different javascript files under the step_definitions folder as following:
a.js

...
 this.When(/^I visit "([^"]*)"$/, function (url, next) {
        console.log('The first one!');
    });
...

b.js

...
 this.When(/^I visit "([^"]*)"$/, function (url, next) {
        console.log('The second one with totally different implementation~');
    });
...

When I ran the test, I figured out that cucumber-js load the 2 files in alphabetical order, so the working definition was actually in 'b.js'.

I thought it would be unsafe not throwing any error(such as 'Duplicated step definitions') because when we deal with large amount of stepdefs, we cannot guarantee we will not accidentally override previous stepdefs and that would certainly cause lots of troubles.

Did I do it wrong or it is actually an issue with the cucumber-js?

@sajesh2686
Copy link

True Cucumber always picks the reg exp found in first step definition. you have to be careful with the reg exp defined in feature file and the step definition.

Am not sure if we have any alternate solution for this, but I usually suggest my team to be careful with this.

@shuai-zh
Copy link
Author

@sajesh2686 I don't think that is something we can compromise with, team members can never be that careful enough.

@jbpros
Copy link
Member

jbpros commented Jun 30, 2014

TL;DR: cucumber.js should throw an exception.

It is an issue in cucumber.js. Cucumber-ruby throws an error when two matches are found for a step. It also provides a --guess flag. @aslakhellesoy and I agreed that this flag should not be implemented. The reason for that is if a step is ambiguous for the machine, it probably is even more ambiguous for the people reading/writing those steps.

@jbpros jbpros added this to the 0.5 major features milestone Jun 30, 2014
@dmeehan1968
Copy link

This now seems to have missed its planned release milestone. I'm still getting problems with this in 0.5.1.

@aslakhellesoy
Copy link
Contributor

@dmeehan1968 would you be interested in sending a pull request to fix this?

@dmeehan1968
Copy link

Yes, happy to create a PR, but a bit short on time.

I had a bit of a look through the code to find the point where step defs are matched but couldn't find the relevant point.

If you can point me to the relevant routine/module that would be very helpful.

@jbpros
Copy link
Member

jbpros commented Jun 22, 2015

@dmeehan1968 thanks! Have a look here:

lookupStepDefinitionByName: function lookupStepDefinitionByName(name) {

@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
5 participants