Skip to content

Commit

Permalink
Run scenarios/features by name. Closes #233, #323
Browse files Browse the repository at this point in the history
  • Loading branch information
aslakhellesoy committed May 18, 2012
1 parent 73cba13 commit 157adae
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 42 deletions.
1 change: 1 addition & 0 deletions History.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## [Git master](https://github.com/cucumber/cucumber-jvm/compare/v1.0.7...master)

* [Core] Run scenarios/features by name ([#233](https://github.com/cucumber/cucumber-jvm/issues/233), [#323](https://github.com/cucumber/cucumber-jvm/pull/323) Klaus Bayrhammer)
* [Jython] Added missing `self` argument in Jython snippets. ([#324](https://github.com/cucumber/cucumber-jvm/issues/324) Aslak Hellesøy)
* [Scala] Fixed regression from v1.0.6 in Scala module - glue code wasn't loaded at all. ([#321](https://github.com/cucumber/cucumber-jvm/issues/321) Aslak Hellesøy)

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ To hack on Cucumber-JVM you need a JDK, Maven and Git to get the code. You also
* UTF-8 file encoding
* LF (UNIX) line endings
* No wildcard imports
* Curly brace on same line as block
* 4 Space indent (no tabs)
* Java
* XML
Expand Down
1 change: 1 addition & 0 deletions core/src/main/resources/cucumber/runtime/USAGE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Options:
-f, --format FORMAT[:OUT] How to format results. Goes to STDOUT unless OUT is specified.
Available formats: junit, html, pretty, progress, json, json-pretty.
-t, --tags TAG_EXPRESSION Only run scenarios tagged with tags matching TAG_EXPRESSION.
-n, --name REGEXP Only run scenarios whose names match REGEXP.
-d, --dry-run Skip execution of glue code.
-m, --monochrome Don't colour terminal output.
--dotcucumber Where to write out runtime information.
Expand Down
9 changes: 3 additions & 6 deletions junit/src/main/java/cucumber/junit/RuntimeOptionsFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,10 @@ public RuntimeOptions create() {

}

private void addName(Cucumber.Options options, List<String> args)
{
private void addName(Cucumber.Options options, List<String> args) {
if (options != null) {
if(options.name().length != 0)
{
for (String name : options.name())
{
if (options.name().length != 0) {
for (String name : options.name()) {
args.add("--name");
args.add(name);
}
Expand Down
57 changes: 21 additions & 36 deletions junit/src/test/java/cucumber/junit/RuntimeOptionsFactoryTest.java
Original file line number Diff line number Diff line change
@@ -1,56 +1,49 @@
package cucumber.junit;

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;
import cucumber.runtime.RuntimeOptions;
import org.junit.Test;

import java.util.Iterator;
import java.util.List;
import java.util.regex.Pattern;

import org.junit.Test;

import cucumber.runtime.RuntimeOptions;
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
{
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 create_with_no_name() throws Exception
{
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
{
public void create_with_multiple_names() throws Exception {
RuntimeOptionsFactory runtimeOptionsFactory = new RuntimeOptionsFactory(MultipleNames.class);

RuntimeOptions runtimeOptions = runtimeOptionsFactory.create();
Expand All @@ -62,49 +55,41 @@ public void create_with_multiple_names() throws Exception
assertEquals("name2", getRegexpPattern(iterator.next()));
}

private String getRegexpPattern(Object pattern)
{
private String getRegexpPattern(Object pattern) {
return ((Pattern) pattern).pattern();
}

@Test
public void finds_path_for_class_in_package()
{
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)
static class Strict
{
static class Strict {
// empty
}

@Cucumber.Options
static class NotStrict
{
static class NotStrict {
// empty
}

@Cucumber.Options(name = {"name1", "name2"})
static class MultipleNames
{
static class MultipleNames {
// empty
}

@Cucumber.Options
static class NoName
{
static class NoName {
// empty
}

static class WithoutOptions
{
static class WithoutOptions {
// empty
}
}

0 comments on commit 157adae

Please sign in to comment.