Skip to content

Commit

Permalink
[Core] Default snippet type in CucumberOptions should not override pr…
Browse files Browse the repository at this point in the history
…operties

When using `cucumber.properties`

```
cucumber.snippet-tye=camelcase
```

In combination with:

```
@RunWith(Cucumber.class)
@CucumberOptions
public class RunCucumberTest {

}
```

The default snippet type from `@CucumberOptions` would override the value set
by `cucumber.properties`.
  • Loading branch information
mpkorstanje committed Sep 3, 2020
1 parent be95023 commit ada3bd2
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
6 changes: 2 additions & 4 deletions core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@ sub modules together e.g. `cucumber-junit` and `cucumber-java`.
## Properties, Environment variables, System Options ##

Cucumber will in order of precedence parse properties from system properties,
environment variables and the `cucumber.properties` file.

Note that options provided by `@CucumberOptions` take precedence over the
properties file and CLI arguments take precedence over all.
environment variables, `@CucumberOptions` and the `cucumber.properties` file.
Note that the CLI arguments take precedence over all.

Note that the `cucumber-junit-platform-engine` is provided with properties
by the Junit Platform rather than Cucumber. See
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,9 @@ private void addName(CucumberOptions options, RuntimeOptionsBuilder args) {
}

private void addSnippets(CucumberOptions options, RuntimeOptionsBuilder args) {
args.setSnippetType(options.snippets());
if (options.snippets() != SnippetType.UNDERSCORE) {
args.setSnippetType(options.snippets());
}
}

private void addGlue(CucumberOptions options, RuntimeOptionsBuilder args) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,13 @@ void create_with_snippets() {
assertThat(runtimeOptions.getSnippetType(), is(equalTo(SnippetType.CAMELCASE)));
}

@Test
void default_snippet_type_should_not_override_existing_snippet_type() {
RuntimeOptions options = new RuntimeOptionsBuilder().setSnippetType(SnippetType.CAMELCASE).build();
RuntimeOptions runtimeOptions = parser().parse(WithDefaultOptions.class).build(options);
assertThat(runtimeOptions.getSnippetType(), is(equalTo(SnippetType.CAMELCASE)));
}

@Test
void create_default_summary_printer_when_no_summary_printer_plugin_is_defined() {
RuntimeOptions runtimeOptions = parser()
Expand Down Expand Up @@ -308,6 +315,11 @@ private static class WithoutOptions {
// empty
}

@CucumberOptions
private static class WithDefaultOptions {
// empty
}

private static class WithoutOptionsWithBaseClassWithoutOptions extends WithoutOptions {
// empty
}
Expand Down

0 comments on commit ada3bd2

Please sign in to comment.