Permalink
Browse files

Get gluePath from runtimeOptions

  • Loading branch information...
1 parent 46aa3ec commit 0e143c0b933d90e9794ff873dd7b5a7dac417a25 @aslakhellesoy aslakhellesoy committed Mar 11, 2012
@@ -85,7 +85,7 @@ public static void run(String[] argv, ClassLoader classLoader) throws IOExceptio
System.exit(1);
}
- Runtime runtime = new Runtime(new FileResourceLoader(), gluePaths, classLoader, runtimeOptions);
+ Runtime runtime = new Runtime(new FileResourceLoader(), classLoader, runtimeOptions);
if (dotCucumber != null) {
writeDotCucumber(featurePaths, dotCucumber, runtime);
@@ -47,11 +47,11 @@
private ScenarioResultImpl scenarioResult = null;
private final RuntimeOptions runtimeOptions;
- public Runtime(ResourceLoader resourceLoader, List<String> gluePaths, ClassLoader classLoader, RuntimeOptions runtimeOptions) {
- this(resourceLoader, gluePaths, classLoader, loadBackends(resourceLoader, classLoader), runtimeOptions);
+ public Runtime(ResourceLoader resourceLoader, ClassLoader classLoader, RuntimeOptions runtimeOptions) {
+ this(resourceLoader, classLoader, loadBackends(resourceLoader, classLoader), runtimeOptions);
}
- public Runtime(ResourceLoader resourceLoader, List<String> gluePaths, ClassLoader classLoader, Collection<? extends Backend> backends, RuntimeOptions runtimeOptions) {
+ public Runtime(ResourceLoader resourceLoader, ClassLoader classLoader, Collection<? extends Backend> backends, RuntimeOptions runtimeOptions) {
if (backends.isEmpty()) {
throw new CucumberException("No backends were found. Please make sure you have a backend module on your CLASSPATH.");
}
@@ -60,7 +60,7 @@ public Runtime(ResourceLoader resourceLoader, List<String> gluePaths, ClassLoade
glue = new RuntimeGlue(undefinedStepsTracker, new LocalizedXStreams(classLoader));
for (Backend backend : backends) {
- backend.loadGlue(glue, gluePaths);
+ backend.loadGlue(glue, runtimeOptions.glue);
backend.setUnreportedStepExecutor(this);
}
this.runtimeOptions = runtimeOptions;
@@ -8,11 +8,12 @@
import gherkin.formatter.Formatter;
import java.io.File;
+import java.util.ArrayList;
import java.util.List;
public class RuntimeOptions {
@Parameter(names = {"-g", "--glue"}, description = "Where cucumber looks for step definitions and hooks.")
- public List<File> glue;
+ public List<String> glue = new ArrayList<String>();
@Parameter(names = {"--dotcucumber"}, description = "Where to output .cucumber files (for code completion).")
public File dotCucumber;
@@ -30,7 +31,7 @@
public List<Formatter> formatters;
@Parameter(description = "Feature paths")
- public List<File> featurePaths;
+ public List<String> featurePaths;
public RuntimeOptions(String... args) {
JCommander cmd = new JCommander(this);
@@ -62,7 +62,7 @@ private void runFeaturesWithFormatter(final List<String> featurePaths, File outp
final ClasspathResourceLoader resourceLoader = new ClasspathResourceLoader(classLoader);
final List<String> gluePaths = emptyList();
RuntimeOptions runtimeOptions = new RuntimeOptions();
- final Runtime runtime = new Runtime(resourceLoader, gluePaths, classLoader, asList(mock(Backend.class)), runtimeOptions);
+ final Runtime runtime = new Runtime(resourceLoader, classLoader, asList(mock(Backend.class)), runtimeOptions);
runtime.run(featurePaths, emptyList(), f, f);
f.done();
f.close();
@@ -51,7 +51,7 @@ private void runFeaturesWithFormatter(final List<String> featurePaths) throws IO
final ClasspathResourceLoader resourceLoader = new ClasspathResourceLoader(classLoader);
final List<String> gluePaths = emptyList();
RuntimeOptions runtimeOptions = new RuntimeOptions();
- final cucumber.runtime.Runtime runtime = new Runtime(resourceLoader, gluePaths, classLoader, asList(mock(Backend.class)), runtimeOptions);
+ final cucumber.runtime.Runtime runtime = new Runtime(resourceLoader, classLoader, asList(mock(Backend.class)), runtimeOptions);
runtime.run(featurePaths, emptyList(), f, f);
f.done();
f.close();
@@ -6,7 +6,6 @@
import org.junit.Test;
import java.io.IOException;
-import java.util.ArrayList;
import static cucumber.runtime.TestHelper.feature;
import static java.util.Arrays.asList;
@@ -18,7 +17,7 @@
public void should_run_background() throws IOException {
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
RuntimeOptions runtimeOptions = new RuntimeOptions();
- Runtime runtime = new Runtime(new ClasspathResourceLoader(classLoader), new ArrayList<String>(), classLoader, asList(mock(Backend.class)), runtimeOptions);
+ Runtime runtime = new Runtime(new ClasspathResourceLoader(classLoader), classLoader, asList(mock(Backend.class)), runtimeOptions);
CucumberFeature feature = feature("test.feature", "" +
"Feature:\n" +
" Background:\n" +
@@ -28,7 +28,7 @@
public void buildMockWorld() {
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
RuntimeOptions runtimeOptions = new RuntimeOptions();
- runtime = new Runtime(mock(ResourceLoader.class), new ArrayList<String>(), classLoader, asList(mock(Backend.class)), runtimeOptions);
+ runtime = new Runtime(mock(ResourceLoader.class), classLoader, asList(mock(Backend.class)), runtimeOptions);
glue = runtime.getGlue();
}
@@ -48,7 +48,7 @@ public void after_hooks_execute_before_objects_are_disposed() throws Throwable {
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
RuntimeOptions runtimeOptions = new RuntimeOptions();
- Runtime runtime = new Runtime(new ClasspathResourceLoader(classLoader), CODE_PATHS, classLoader, asList(backend), runtimeOptions);
+ Runtime runtime = new Runtime(new ClasspathResourceLoader(classLoader), classLoader, asList(backend), runtimeOptions);
runtime.getGlue().addAfterHook(hook);
scenario.run(mock(Formatter.class), mock(Reporter.class), runtime);
@@ -12,13 +12,13 @@
@Test
public void assigns_feature_paths() {
RuntimeOptions options = new RuntimeOptions("--glue", "somewhere", "somewhere_else");
- assertEquals(asList(new File("somewhere_else")), options.featurePaths);
+ assertEquals(asList("somewhere_else"), options.featurePaths);
}
@Test
public void assigns_glue() {
RuntimeOptions options = new RuntimeOptions("--glue", "somewhere");
- assertEquals(asList(new File("somewhere")), options.glue);
+ assertEquals(asList("somewhere"), options.glue);
}
@Test
@@ -5,7 +5,6 @@
import gherkin.formatter.JSONPrettyFormatter;
import org.junit.Test;
-import java.util.Collections;
import java.util.List;
import static cucumber.runtime.TestHelper.feature;
@@ -27,7 +26,7 @@ public void runs_feature_with_json_formatter() throws Exception {
List<Backend> backends = asList(mock(Backend.class));
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
RuntimeOptions runtimeOptions = new RuntimeOptions();
- new Runtime(new ClasspathResourceLoader(classLoader), Collections.<String>emptyList(), classLoader, backends, runtimeOptions).run(feature, jsonFormatter, jsonFormatter);
+ new Runtime(new ClasspathResourceLoader(classLoader), classLoader, backends, runtimeOptions).run(feature, jsonFormatter, jsonFormatter);
jsonFormatter.done();
String expected = "" +
"[\n" +
@@ -48,7 +48,7 @@
private final JavaBackend backend = new JavaBackend(new SingletonFactory(defs));
private final ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
private final RuntimeOptions runtimeOptions = new RuntimeOptions();
- private final Runtime runtime = new Runtime(new ClasspathResourceLoader(classLoader), NO_PATHS, classLoader, asList(backend), runtimeOptions);
+ private final Runtime runtime = new Runtime(new ClasspathResourceLoader(classLoader), classLoader, asList(backend), runtimeOptions);
private final Glue glue = runtime.getGlue();
@org.junit.Before
@@ -55,10 +55,9 @@ public Cucumber(Class clazz) throws InitializationError, IOException {
ClassLoader classLoader = clazz.getClassLoader();
resourceLoader = new ClasspathResourceLoader(classLoader);
assertNoDeclaredMethods(clazz);
- List<String> featurePaths = featurePaths(clazz);
- List<String> gluePaths = gluePaths(clazz);
+ List<String> featurePaths = featurePaths(clazz, getFeatureAnnotation(clazz));
RuntimeOptions runtimeOptions = runtimeOptions(clazz);
- runtime = new Runtime(resourceLoader, gluePaths, classLoader, runtimeOptions);
+ runtime = new Runtime(resourceLoader, classLoader, runtimeOptions);
// TODO: Create formatter(s) based on Annotations. Use same technique as in cli.Main for MultiFormatter
jUnitReporter = new JUnitReporter(new NullReporter(), new NullReporter());
@@ -102,20 +101,27 @@ private void assertNoDeclaredMethods(Class clazz) {
}
private RuntimeOptions runtimeOptions(Class clazz) {
- Options cucumberOptions = getFeatureAnnotation(clazz);
-
List<String> args = new ArrayList<String>();
-
+ Options cucumberOptions = getFeatureAnnotation(clazz);
+ addGlue(cucumberOptions, clazz, args);
+
RuntimeOptions runtimeOptions = new RuntimeOptions(args.toArray(new String[args.size()]));
return runtimeOptions;
}
- /**
- * @param clazz the Class used to kick it all off
- * @return either a path to a single feature, or to a directory or classpath entry containing them
- */
- private List<String> featurePaths(Class clazz) {
- Options cucumberOptions = getFeatureAnnotation(clazz);
+ private void addGlue(Options options, Class clazz, List<String> args) {
+ if(options != null) {
+ for (String glue : options.glue()) {
+ args.add("--glue");
+ args.add(glue);
+ }
+ } else {
+ args.add("--glue");
+ args.add(packagePath(clazz));
+ }
+ }
+
+ private List<String> featurePaths(Class clazz, Options cucumberOptions) {
String featurePath;
if (cucumberOptions != null) {
featurePath = cucumberOptions.value();
@@ -125,21 +131,6 @@ private RuntimeOptions runtimeOptions(Class clazz) {
return asList(featurePath);
}
- private List<String> gluePaths(Class clazz) {
- List<String> gluePaths = new ArrayList<String>();
-
- gluePaths.add(packagePath(clazz));
-
- // Add additional ones
- Options cucumberOptions = getFeatureAnnotation(clazz);
- if (cucumberOptions != null) {
- for (String packageName : cucumberOptions.packages()) {
- gluePaths.add(packagePath(packageName));
- }
- }
- return gluePaths;
- }
-
private List<Object> filters(Class clazz) {
Options cucumberOptions = getFeatureAnnotation(clazz);
Object[] filters = new Object[0];
@@ -196,6 +187,6 @@ private Options getFeatureAnnotation(Class clazz) {
/**
* @return where to look for glue code (stepdefs and hooks)
*/
- String[] packages() default {};
+ String[] glue() default {};
}
}
@@ -13,8 +13,8 @@
* This class defines before and after hooks which provide automatic spring rollback capabilities.
* These hooks will apply to any element(s) within a <code>.feature</code> file tagged with <code>@txn</code>.
* <p/>
- * Clients wishing to leverage these hooks should include this class' package in the <code>packages</code> property of the
- * Test class' <code>Feature</code> annotation.
+ * Clients wishing to leverage these hooks should include this class' package in the <code>glue</code> property of the
+ * Test class' {@link Cucumber.Options} annotation.
* <p/>
* The BEFORE and AFTER hooks both rely on being able to obtain a <code>PlatformTransactionManager</code> by type, or
* by an optionally specified bean name, from the runtime <code>BeanFactory</code>.

0 comments on commit 0e143c0

Please sign in to comment.