Skip to content

Commit ed9a20a

Browse files
committed
Merge branch '31-pick-up-steps' of https://github.com/oc/cucumber-jvm into oc-31-pick-up-steps
2 parents 1c40982 + 7527328 commit ed9a20a

File tree

5 files changed

+36
-0
lines changed

5 files changed

+36
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
.project
33
.classpath
44
*.iws
5+
*.iml
6+
*.ipr
57
target
68
chromedriver.log
79
Gemfile.lock

core/src/main/java/cucumber/junit/Cucumber.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,14 @@ public Cucumber(Class featureClass, final Runtime runtime) throws Initialization
4949
this.runtime = runtime;
5050
String pathName = featurePath(featureClass);
5151
parseFeature(pathName, filters(featureClass));
52+
addAdditionalScanPaths(featureClass, this.runtime);
53+
}
54+
55+
private void addAdditionalScanPaths(Class featureClass, final Runtime runtime) {
56+
cucumber.junit.Feature featureAnnotation = (cucumber.junit.Feature) featureClass.getAnnotation(cucumber.junit.Feature.class);
57+
if (featureAnnotation != null) {
58+
runtime.addStepdefScanPath(featureAnnotation.packages());
59+
}
5260
}
5361

5462
private String featurePath(Class featureClass) {

core/src/main/java/cucumber/junit/Feature.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,6 @@
1313
long[] lines() default {};
1414

1515
String[] tags() default {};
16+
17+
String[] packages() default {};
1618
}

core/src/main/java/cucumber/runtime/Runtime.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,4 +84,13 @@ public World newWorld(Set<String> tags) {
8484
return new World(backends, this, tags);
8585
}
8686

87+
// XXX: should this be ctor initialized?
88+
public void addStepdefScanPath(String[] packages) {
89+
for (String packageName : packages) {
90+
if(packageName.matches("^([a-z]\\w*\\.?)+$"))
91+
backends.addAll(Resources.instantiateSubclasses(Backend.class, "cucumber.runtime", packageName));
92+
else
93+
throw new CucumberException("Additional package isn't valid: " + packageName);
94+
}
95+
}
8796
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package cucumber.examples.java.scan;
2+
3+
import cucumber.junit.Cucumber;
4+
import cucumber.junit.Feature;
5+
import org.junit.runner.RunWith;
6+
7+
/**
8+
* This test class tells JUnit to run a particular feature with Cucumber.
9+
* Step definitions will be scanned underneath both this class' package, and
10+
* underneath cucumber.examples.java.calculator.
11+
*/
12+
@RunWith(Cucumber.class)
13+
@Feature(value = "basic_arithmetic.feature", packages = {"cucumber.examples.java.calculator"})
14+
public class basic_arithmetic_with_scan_Test {
15+
}

0 commit comments

Comments
 (0)