Skip to content

Commit e4c12f3

Browse files
committed
DocString arguments can be converted to scalar types just like capture group arguments
1 parent 2d36e94 commit e4c12f3

File tree

5 files changed

+29
-5
lines changed

5 files changed

+29
-5
lines changed

History.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
## [1.2.4-SNAPSHOT](https://github.com/cucumber/cucumber-jvm/compare/v1.2.3...master) (In Git)
22

3+
* [Core] DocString arguments can be converted to scalar types just like capture group arguments (Aslak Hellesøy)
34
* [Guice] The `cucumber-guice.properties` file is no longer used. Use `cucumber.properties` instead.
45
* [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)
56
* [Java] `ObjectFactory.addClass` returns a boolean indicating whether or not stepdefs/hooks for that class should be registered. (Aslak Hellesøy)

core/src/main/java/cucumber/runtime/StepDefinitionMatch.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,9 @@ private Object[] transformedArgs(Step step, LocalizedXStreams.LocalizedXStream x
7373
if (step.getRows() != null) {
7474
result.add(tableArgument(step, n, xStream));
7575
} else if (step.getDocString() != null) {
76-
result.add(step.getDocString().getValue());
76+
ParameterInfo parameterInfo = getParameterType(n, String.class);
77+
Object arg = parameterInfo.convert(step.getDocString().getValue(), xStream);
78+
result.add(arg);
7779
}
7880
return result.toArray(new Object[result.size()]);
7981
}

core/src/test/java/cucumber/runtime/StepDefinitionMatchTest.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,23 @@ public void converts_with_explicit_converter() throws Throwable {
5757
verify(stepDefinition).execute(ENGLISH, new Object[]{new Thing("the thing")});
5858
}
5959

60+
@Test
61+
public void converts_doc_string_with_explicit_converter() throws Throwable {
62+
StepDefinition stepDefinition = mock(StepDefinition.class);
63+
when(stepDefinition.getParameterCount()).thenReturn(1);
64+
when(stepDefinition.getParameterType(0, String.class)).thenReturn(new ParameterInfo(Thing.class, null, null,
65+
null));
66+
67+
Step stepWithDocString = mock(Step.class);
68+
DocString docString = new DocString("test", "the thing", 999);
69+
when(stepWithDocString.getDocString()).thenReturn(docString);
70+
when(stepWithDocString.getRows()).thenReturn(null);
71+
72+
StepDefinitionMatch stepDefinitionMatch = new StepDefinitionMatch(new ArrayList<Argument>(), stepDefinition, "some.feature", stepWithDocString, new LocalizedXStreams(classLoader));
73+
stepDefinitionMatch.runStep(ENGLISH);
74+
verify(stepDefinition).execute(ENGLISH, new Object[]{new Thing("the thing")});
75+
}
76+
6077
@XStreamConverter(ThingConverter.class)
6178
public static class Thing {
6279
public final String name;

groovy/src/test/groovy/cucumber/runtime/groovy/date_stepdefs.groovy

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,12 @@ class DateWrapper {
1616

1717
class DateWrapperConverter extends Transformer<DateWrapper> {
1818
def DateWrapper transform(String string) {
19-
def df = new SimpleDateFormat("dd-MM-yyyy")
19+
def df = new SimpleDateFormat("yyyy-MM-dd")
2020
return new DateWrapper(date:df.parse(string));
2121
}
2222
}
2323

24-
Given(~'^today\'s date is "(.*)"') { DateWrapper dw ->
25-
assertEquals(71, dw.date.year)
24+
Given(~'^today\'s date is "(.*)" and tomorrow is:') { DateWrapper today, DateWrapper tomorrow ->
25+
assertEquals(3, today.date.date)
26+
assertEquals(4, tomorrow.date.date)
2627
}

groovy/src/test/resources/cucumber/runtime/groovy/a_feature.feature

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@ Feature: Cucumber Runner Rocks
2424
| 2012 | Cucumber-JVM |
2525

2626
Scenario: A date
27-
Given today's date is "10-03-1971"
27+
Given today's date is "1971-10-03" and tomorrow is:
28+
"""
29+
1971-10-04
30+
"""
2831

2932

3033
Scenario: Call a method or property from second world

0 commit comments

Comments
 (0)