2
votes

Environment: Java/IntelliJ/Cucumber

Lately, I'v experienced several times that IntelliJ claims an ambiguous step definition when there doesn't appear to be one.

cucumber.runtime.AmbiguousStepDefinitionsException: "that "saken" is a 
rejected case in kommune "5000"" matches more than one step definition:
"^that "([^"]*)" is a rejected case" in SakSteps.isARejectedCase(String)
"^that "([^"]*)" is a rejected case in kommune "([^"]*)"$" in 
SakSteps.isARejectedCaseInKommune(String,String)

The "Given" step text is not the same, although the first 6 strings match:

"^that "([^"]*)" is a rejected case"
"^that "([^"]*)" is a rejected case in kommune "([^"]*)"$"

The method names are not at all similar:

isARejectedCase(String)
isARejectedCaseInKommune(String,String)

How come IntelliJ/Cucumber claims that these are ambiguous?

This code did work before. There may have been some plugin update or other in between, but I don't see why it should behave like this?

1
I experienced similar issues, which I attribute to the fact that the first regexp expression ("^that "([^"]*)" is a rejected case") is a sub-case of the second ("^that "([^"]*)" is a rejected case in kommune "([^"]*)"$"). What I usually do is find a different wording to distinguish them. Maybe you could also add $ at the end of the first, to indicate the end of the sentence. - hotzst
Wow! How did I not see that?! You're absolutely right - it seems that indicating the end of the sentence with "$" is the key. Put your comment in an answer, so that I can give you credit for it :-) - Hfrav

1 Answers

0
votes

Answring my own post here:

The reason was a missing "$" at the end of the step definition, to mark the end of the sentence. Without that, it will match definitions that start with the same words. Example:

When X does Y because of W
When X does Y becayse of W in addition to P