-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Fix duplicated step definitions from the same step locations #633
Fix duplicated step definitions from the same step locations #633
Conversation
Tests to be written. |
@brasmusson, @martykube |
@ffbit I've reviewed the code. It's good! |
@@ -43,10 +43,18 @@ public RuntimeGlue(UndefinedStepsTracker tracker, LocalizedXStreams localizedXSt | |||
@Override | |||
public void addStepDefinition(StepDefinition stepDefinition) { | |||
StepDefinition previous = stepDefinitionsByPattern.get(stepDefinition.getPattern()); | |||
if (previous != null) { | |||
if (previous == null || haveSameLocation(previous, stepDefinition)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is a matter of taste, but I would probably have used:
if (previous == null) {
stepDefinitionsByPattern.put(stepDefinition.getPattern(), stepDefinition);
} else if (!haveSameLocation(previous, stepDefinition)) {
throw new DuplicateStepDefinitionException(previous, stepDefinition);
}
In a method named addStepDefinition, the if (previous == null || haveSameLocation(previous, stepDefinition))
triggered a "no, it is not right to add the stepDefinition in both these cases" in me, but it is actually ok, since put overwrites the previous step definition with the new one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changed.
@brasmusson |
Some notes on RuntimeGlueTest's test case.
@aslakhellesoy |
Thanks for all the work on this everyone. I'll have a look this weekend and let you know. |
@aslakhellesoy |
It seems to me that this change is a workaround for the situation when the glue path has duplicate entries, and defensively tries to cope with that situation. Why should we allow duplicate entries in the glue path? Isn't it better to throw an exception early in that case? It sounds like this is a configuration error that the user should try to fix. |
@aslakhellesoy Another one occurs if we've got a super class for the one annotated with the @CucumberOptions.
The test part structure of the project might look like
In this case we have 2 same paths in the glue paths.
And a failure can be seen in the test log
This problem is a sort of solved though a work around here and in the proposal #632. Let's continue playing with our example.
In this case we have 2 different paths in the glue paths.
And neither that mentioned work around nor the #632 works and we can see the same annoying failure message. This pull request tries to solve the problem from the other side - by handling step definitions which have exactly the same location. |
@aslakhellesoy |
@aslakhellesoy For the case that the duplicate glue paths are coming from the user specifies multiple glue paths options that end up as duplicates, I think that you are right, an error notifying the user to fix the settings appropriate. The complication here comes from #568 which introduces that list options (formatter, glue, tags, features) are added up from the inheritance tree. #568 intentionally implemented "adding to" behavior, to that for instance default formatter can be specified in a So the problem needs to be solved, either in RuntimeOptionsFactory (where the problem is introduced), or in RuntimeOptions (as suggested in #632, which currently does not handle the example with base classes in parent packages), or in RuntimeGlue (as suggested in this PR). The change in this RP has the down side (sort of) that if a user explicitly specifies |
@martykube I think that #632 does not work with the second example, because a parent package and a sub package are not the identical path, so the Set will allow them both, but the lookup from glue paths include sub packages. So a step definition in the sub package will be found through both parent package path and the sub package path. |
@aslakhellesoy @ffbit I did some more thinking on this issue. Before #568, the package of the class with Maybe the right solution for this sort of "package defined multiple times in the glue paths" problem is to, in a sense go back to the original behaviour, only add the package of the runner class with Then we would be back to the state that if the same step definition is found through different glue paths item, then it is an configuration error which should generate an exception. WDYT? |
@brasmusson Good point. |
@ffbit On the surface it might appear that the Duplicate Step Definition exception which comes from duplicate glue paths entries, is related to the issue of merging or using data from several The question is what should the following runner structure result in?
I would say that this should result in a Duplicate Step Definition exception since the user should be notified not to explicitly define duplicate (or parent package, sub package) glue paths. |
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. |
Relates to #608, #622, #632 issues.