Skip to content

Commit

Permalink
Make tests slightly more readable. Follow coding conventions. Closes #…
Browse files Browse the repository at this point in the history
  • Loading branch information
aslakhellesoy committed Nov 28, 2012
1 parent ecdbd77 commit 42ee985
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 42 deletions.
4 changes: 4 additions & 0 deletions History.md
@@ -1,3 +1,7 @@
##

* [Core] Scenario --name not working for names with quotes and multiple words ([#379](https://github.com/cucumber/cucumber-jvm/issues/379), [#429](https://github.com/cucumber/cucumber-jvm/pull/429) William Powell)

## [1.1.1](https://github.com/cucumber/cucumber-jvm/compare/v1.0.14...1.1.1)

This release bumps the minor version number from 1.0 to 1.1. This is because there are backwards-incompatible changes.
Expand Down
25 changes: 13 additions & 12 deletions core/src/main/java/cucumber/runtime/RuntimeOptions.java
Expand Up @@ -25,6 +25,7 @@
public class RuntimeOptions {
public static final String VERSION = ResourceBundle.getBundle("cucumber.version").getString("cucumber-jvm.version");
public static final String USAGE = FixJava.readResource("/cucumber/runtime/USAGE.txt");
private static final Pattern SHELLWORDS_PATTERN = Pattern.compile("[^\\s']+|'([^']*)'");

public final List<String> glue = new ArrayList<String>();
public final List<Object> filters = new ArrayList<Object>();
Expand Down Expand Up @@ -56,19 +57,19 @@ public RuntimeOptions(Properties properties, String... argv) {
}

private List<String> cucumberOptionsSplit(String property) {
List<String> matchList = new ArrayList<String>();
Pattern regex = Pattern.compile("[^\\s']+|'([^']*)'");
Matcher regexMatcher = regex.matcher(property);
while (regexMatcher.find()) {
if (regexMatcher.group(1) != null)
matchList.add(regexMatcher.group(1));
else
matchList.add(regexMatcher.group());
}
return matchList;
}
List<String> matchList = new ArrayList<String>();
Matcher shellwordsMatcher = SHELLWORDS_PATTERN.matcher(property);
while (shellwordsMatcher.find()) {
if (shellwordsMatcher.group(1) != null) {
matchList.add(shellwordsMatcher.group(1));
} else {
matchList.add(shellwordsMatcher.group());
}
}
return matchList;
}

private void parse(List<String> args) {
private void parse(List<String> args) {
List<Object> parsedFilters = new ArrayList<Object>();
while (!args.isEmpty()) {
String arg = args.remove(0);
Expand Down
45 changes: 15 additions & 30 deletions core/src/test/java/cucumber/runtime/RuntimeOptionsTest.java
@@ -1,7 +1,5 @@
package cucumber.runtime;

import net.sourceforge.cobertura.ant.Regex;

import org.junit.Test;

import java.io.File;
Expand Down Expand Up @@ -67,49 +65,36 @@ public void default_strict() {
}

@Test
public void name() {
String someName = "someName";
RuntimeOptions options = new RuntimeOptions(new Properties(), "--name", someName);
public void name_without_spaces_is_preserved() {
RuntimeOptions options = new RuntimeOptions(new Properties(), "--name", "someName");
Pattern actualPattern = (Pattern) options.filters.iterator().next();
assertEquals(someName, actualPattern.pattern());
assertEquals("someName", actualPattern.pattern());
}

@Test
public void name_with_spaces() {
String someName = "some Name";
RuntimeOptions options = new RuntimeOptions(new Properties(), "--name", someName);
public void name_with_spaces_is_preserved() {
RuntimeOptions options = new RuntimeOptions(new Properties(), "--name", "some Name");
Pattern actualPattern = (Pattern) options.filters.iterator().next();
assertEquals(someName, actualPattern.pattern());
}
assertEquals("some Name", actualPattern.pattern());
}

@Test
public void ensure_name_with_spaces_works_with_cucumber_options() {
String someName = "some Name";
Properties properties = new Properties();
properties.setProperty("cucumber.options", "--name '" + someName + "'");
properties.setProperty("cucumber.options", "--name 'some Name'");
RuntimeOptions options = new RuntimeOptions(properties);
Pattern actualPattern = (Pattern) options.filters.iterator().next();
assertEquals(someName, actualPattern.pattern());
assertEquals("some Name", actualPattern.pattern());
}

@Test
public void ensure_multiple_cucumber_options_with_spaces_parse_correctly() {
String someName = "some Name";
String somePath = "some file\\path";
Properties properties = new Properties();
properties.setProperty("cucumber.options", "--name '" + someName + "'" + " --dotcucumber '" + somePath + "'");
properties.setProperty("cucumber.options", "--name 'some Name' --dotcucumber 'some file\\path'");
RuntimeOptions options = new RuntimeOptions(properties);
Pattern actualPattern = (Pattern) options.filters.iterator().next();
assertEquals(someName, actualPattern.pattern());
assertEquals(new File(somePath), options.dotCucumber);
}

@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());
assertEquals("some Name", actualPattern.pattern());
assertEquals(new File("some file\\path"), options.dotCucumber);
}

@Test
Expand Down

0 comments on commit 42ee985

Please sign in to comment.