Search code examples
javaintellij-ideacucumber

Java and Cucumber: Strange ambiguous step definition exception


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?


Solution

  • Answering 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 because of W in addition to P