Skip to content

Commit

Permalink
DocString arguments can be converted to scalar types just like captur…
Browse files Browse the repository at this point in the history
…e group arguments
  • Loading branch information
aslakhellesoy committed Jul 14, 2015
1 parent 2d36e94 commit e4c12f3
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 5 deletions.
1 change: 1 addition & 0 deletions History.md
@@ -1,5 +1,6 @@
## [1.2.4-SNAPSHOT](https://github.com/cucumber/cucumber-jvm/compare/v1.2.3...master) (In Git)

* [Core] DocString arguments can be converted to scalar types just like capture group arguments (Aslak Hellesøy)
* [Guice] The `cucumber-guice.properties` file is no longer used. Use `cucumber.properties` instead.
* [Guice] The `guice.injector-source` property can be overridden as a System property or environment variable ([#881](https://github.com/cucumber/cucumber-jvm/issues/881) Aslak Hellesøy)
* [Java] `ObjectFactory.addClass` returns a boolean indicating whether or not stepdefs/hooks for that class should be registered. (Aslak Hellesøy)
Expand Down
4 changes: 3 additions & 1 deletion core/src/main/java/cucumber/runtime/StepDefinitionMatch.java
Expand Up @@ -73,7 +73,9 @@ private Object[] transformedArgs(Step step, LocalizedXStreams.LocalizedXStream x
if (step.getRows() != null) {
result.add(tableArgument(step, n, xStream));
} else if (step.getDocString() != null) {
result.add(step.getDocString().getValue());
ParameterInfo parameterInfo = getParameterType(n, String.class);
Object arg = parameterInfo.convert(step.getDocString().getValue(), xStream);
result.add(arg);
}
return result.toArray(new Object[result.size()]);
}
Expand Down
17 changes: 17 additions & 0 deletions core/src/test/java/cucumber/runtime/StepDefinitionMatchTest.java
Expand Up @@ -57,6 +57,23 @@ public void converts_with_explicit_converter() throws Throwable {
verify(stepDefinition).execute(ENGLISH, new Object[]{new Thing("the thing")});
}

@Test
public void converts_doc_string_with_explicit_converter() throws Throwable {
StepDefinition stepDefinition = mock(StepDefinition.class);
when(stepDefinition.getParameterCount()).thenReturn(1);
when(stepDefinition.getParameterType(0, String.class)).thenReturn(new ParameterInfo(Thing.class, null, null,
null));

Step stepWithDocString = mock(Step.class);
DocString docString = new DocString("test", "the thing", 999);
when(stepWithDocString.getDocString()).thenReturn(docString);
when(stepWithDocString.getRows()).thenReturn(null);

StepDefinitionMatch stepDefinitionMatch = new StepDefinitionMatch(new ArrayList<Argument>(), stepDefinition, "some.feature", stepWithDocString, new LocalizedXStreams(classLoader));
stepDefinitionMatch.runStep(ENGLISH);
verify(stepDefinition).execute(ENGLISH, new Object[]{new Thing("the thing")});
}

@XStreamConverter(ThingConverter.class)
public static class Thing {
public final String name;
Expand Down
Expand Up @@ -16,11 +16,12 @@ class DateWrapper {

class DateWrapperConverter extends Transformer<DateWrapper> {
def DateWrapper transform(String string) {
def df = new SimpleDateFormat("dd-MM-yyyy")
def df = new SimpleDateFormat("yyyy-MM-dd")
return new DateWrapper(date:df.parse(string));
}
}

Given(~'^today\'s date is "(.*)"') { DateWrapper dw ->
assertEquals(71, dw.date.year)
Given(~'^today\'s date is "(.*)" and tomorrow is:') { DateWrapper today, DateWrapper tomorrow ->
assertEquals(3, today.date.date)
assertEquals(4, tomorrow.date.date)
}
Expand Up @@ -24,7 +24,10 @@ Feature: Cucumber Runner Rocks
| 2012 | Cucumber-JVM |

Scenario: A date
Given today's date is "10-03-1971"
Given today's date is "1971-10-03" and tomorrow is:
"""
1971-10-04
"""


Scenario: Call a method or property from second world
Expand Down

0 comments on commit e4c12f3

Please sign in to comment.