Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Run scenarios/features by name #323

Merged
merged 2 commits into from

2 participants

@klausbayrhammer

Refs #233
Added a --name pattern in CLI-Runner and a name tag in Cucumber.Options, to specify a pattern which has to be matched by the feature name or the scenario name using the Gherkin.PatternFilter

klausbayrhammer added some commits
@klausbayrhammer klausbayrhammer refs #233 run features/scenarios by name
added --name argument to specify a pattern to match a scenario or feature name
76b1949
@klausbayrhammer klausbayrhammer fixed paramter order expected/actual c4669fc
@aslakhellesoy aslakhellesoy merged commit c4669fc into cucumber:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on May 17, 2012
  1. @klausbayrhammer

    refs #233 run features/scenarios by name

    klausbayrhammer authored
    added --name argument to specify a pattern to match a scenario or feature name
  2. @klausbayrhammer
This page is out of date. Refresh to see the latest.
View
5 core/src/main/java/cucumber/runtime/RuntimeOptions.java
@@ -17,6 +17,7 @@
import java.util.List;
import java.util.Properties;
import java.util.ResourceBundle;
+import java.util.regex.Pattern;
import static cucumber.runtime.model.CucumberFeature.load;
import static java.util.Arrays.asList;
@@ -81,6 +82,10 @@ private void parse(List<String> args) {
strict = true;
} else if (arg.equals("--monochrome") || arg.equals("-m")) {
monochrome = true;
+ } else if (arg.equals("--name") || arg.equals("-n")) {
+ String nextArg = args.remove(0);
+ Pattern patternFilter = Pattern.compile(nextArg);
+ filters.add(patternFilter);
} else {
PathWithLines pathWithLines = new PathWithLines(arg);
featurePaths.add(pathWithLines.path);
View
17 core/src/test/java/cucumber/runtime/RuntimeOptionsTest.java
@@ -5,6 +5,7 @@
import java.io.File;
import java.util.Properties;
+import java.util.regex.Pattern;
import static java.util.Arrays.asList;
import static junit.framework.Assert.assertEquals;
@@ -65,6 +66,22 @@ public void default_strict() {
}
@Test
+ public void name() {
+ String someName = "someName";
+ RuntimeOptions options = new RuntimeOptions(new Properties(), "--name", someName);
+ Pattern actualPattern = (Pattern) options.filters.iterator().next();
+ assertEquals(someName, actualPattern.pattern());
+ }
+
+ @Test
+ public void name_short() {
+ String someName = "someName";
+ RuntimeOptions options = new RuntimeOptions(new Properties(), "-n", someName);
+ Pattern actualPattern = (Pattern) options.filters.iterator().next();
+ assertEquals(someName, actualPattern.pattern());
+ }
+
+ @Test
public void overrides_options_with_system_properties() {
Properties properties = new Properties();
properties.setProperty("cucumber.options", "--glue lookatme andmememe");
View
6 junit/src/main/java/cucumber/junit/Cucumber.java
@@ -149,5 +149,11 @@ private void addChildren(List<CucumberFeature> cucumberFeatures) throws Initiali
*/
boolean monochrome() default false;
+ /**
+ * Specify a patternfilter for features or scenarios
+ *
+ * @return a list of patterns
+ */
+ String[] name() default {};
}
}
View
15 junit/src/main/java/cucumber/junit/RuntimeOptionsFactory.java
@@ -25,11 +25,26 @@ public RuntimeOptions create() {
addFormats(options, args);
addFeatures(options, clazz, args);
addStrict(options, args);
+ addName(options, args);
return new RuntimeOptions(System.getProperties(), args.toArray(new String[args.size()]));
}
+ private void addName(Cucumber.Options options, List<String> args)
+ {
+ if (options != null) {
+ if(options.name().length != 0)
+ {
+ for (String name : options.name())
+ {
+ args.add("--name");
+ args.add(name);
+ }
+ }
+ }
+ }
+
private Cucumber.Options getOptions(Class<?> clazz) {
return clazz.getAnnotation(Cucumber.Options.class);
}
View
78 junit/src/test/java/cucumber/junit/RuntimeOptionsFactoryTest.java
@@ -1,58 +1,110 @@
package cucumber.junit;
-import cucumber.runtime.RuntimeOptions;
-import org.junit.Test;
-
import static cucumber.junit.RuntimeOptionsFactory.packageName;
import static cucumber.junit.RuntimeOptionsFactory.packagePath;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
-public class RuntimeOptionsFactoryTest {
+import java.util.Iterator;
+import java.util.List;
+import java.util.regex.Pattern;
+
+import org.junit.Test;
+
+import cucumber.runtime.RuntimeOptions;
+
+public class RuntimeOptionsFactoryTest
+{
@Test
- public void create_strict() throws Exception {
+ public void create_strict() throws Exception
+ {
RuntimeOptionsFactory runtimeOptionsFactory = new RuntimeOptionsFactory(Strict.class);
RuntimeOptions runtimeOptions = runtimeOptionsFactory.create();
assertTrue(runtimeOptions.strict);
}
@Test
- public void create_non_strict() throws Exception {
+ public void create_non_strict() throws Exception
+ {
RuntimeOptionsFactory runtimeOptionsFactory = new RuntimeOptionsFactory(NotStrict.class);
RuntimeOptions runtimeOptions = runtimeOptionsFactory.create();
assertFalse(runtimeOptions.strict);
}
@Test
- public void create_without_options() throws Exception {
+ public void create_without_options() throws Exception
+ {
RuntimeOptionsFactory runtimeOptionsFactory = new RuntimeOptionsFactory(WithoutOptions.class);
RuntimeOptions runtimeOptions = runtimeOptionsFactory.create();
assertFalse(runtimeOptions.strict);
}
@Test
- public void finds_path_for_class_in_package() {
+ public void create_with_no_name() throws Exception
+ {
+ RuntimeOptionsFactory runtimeOptionsFactory = new RuntimeOptionsFactory(NoName.class);
+ RuntimeOptions runtimeOptions = runtimeOptionsFactory.create();
+ assertTrue(runtimeOptions.filters.isEmpty());
+ }
+
+ @Test
+ public void create_with_multiple_names() throws Exception
+ {
+ RuntimeOptionsFactory runtimeOptionsFactory = new RuntimeOptionsFactory(MultipleNames.class);
+
+ RuntimeOptions runtimeOptions = runtimeOptionsFactory.create();
+
+ List<Object> filters = runtimeOptions.filters;
+ assertEquals(2, filters.size());
+ Iterator<Object> iterator = filters.iterator();
+ assertEquals("name1", getRegexpPattern(iterator.next()));
+ assertEquals("name2", getRegexpPattern(iterator.next()));
+ }
+
+ private String getRegexpPattern(Object pattern)
+ {
+ return ((Pattern) pattern).pattern();
+ }
+
+ @Test
+ public void finds_path_for_class_in_package()
+ {
assertEquals("java/lang", packagePath(String.class));
}
@Test
- public void finds_path_for_class_in_toplevel_package() {
+ public void finds_path_for_class_in_toplevel_package()
+ {
assertEquals("", packageName("TopLevelClass"));
}
@Cucumber.Options(strict = true)
- public static class Strict {
+ static class Strict
+ {
+ // empty
+ }
+
+ @Cucumber.Options
+ static class NotStrict
+ {
// empty
}
- @Cucumber.Options()
- public static class NotStrict {
+ @Cucumber.Options(name = {"name1", "name2"})
+ static class MultipleNames
+ {
// empty
}
- public static class WithoutOptions {
+ @Cucumber.Options
+ static class NoName
+ {
// empty
}
+ static class WithoutOptions
+ {
+ // empty
+ }
}
Something went wrong with that request. Please try again.