use of io.cucumber.core.backend.StepDefinition in project cucumber-jvm by cucumber.
the class StepExpressionFactoryTest method docstring_and_datatable_match_same_step_definition.
@Test
void docstring_and_datatable_match_same_step_definition() {
String docString = "A rather long and boring string of documentation";
StepDefinition stepDefinition = new StubStepDefinition("Given some stuff:", UNKNOWN_TYPE);
StepExpression expression = stepExpressionFactory.createExpression(stepDefinition);
List<Argument> match = expression.match("Given some stuff:", docString, null);
assertThat(match.get(0).getValue(), is(equalTo(DocString.create(docString))));
match = expression.match("Given some stuff:", table);
assertThat(match.get(0).getValue(), is(equalTo(DataTable.create(table))));
}
use of io.cucumber.core.backend.StepDefinition in project cucumber-jvm by cucumber.
the class Java8LambdaStepDefinitionMarksCorrectStackElementTest method exception_from_step_should_be_defined_at_step_definition_class.
@Test
void exception_from_step_should_be_defined_at_step_definition_class() {
LambdaGlueRegistry.INSTANCE.set(myLambdaGlueRegistry);
new SomeLambdaStepDefs();
final StepDefinition stepDefinition = myLambdaGlueRegistry.getStepDefinition();
CucumberInvocationTargetException exception = assertThrows(CucumberInvocationTargetException.class, () -> stepDefinition.execute(new Object[0]));
assertThat(exception.getInvocationTargetExceptionCause(), new CustomTypeSafeMatcher<Throwable>("exception with matching stack trace") {
@Override
protected boolean matchesSafely(Throwable item) {
return Arrays.stream(item.getStackTrace()).filter(stepDefinition::isDefinedAt).findFirst().filter(stackTraceElement -> SomeLambdaStepDefs.class.getName().equals(stackTraceElement.getClassName())).isPresent();
}
});
}
use of io.cucumber.core.backend.StepDefinition in project cucumber-jvm by cucumber.
the class CachingGlueTest method returns_fresh_match_from_cache_after_evicting_scenario_scoped.
@Test
void returns_fresh_match_from_cache_after_evicting_scenario_scoped() throws AmbiguousStepDefinitionsException {
URI uri = URI.create("file:path/to.feature");
String stepText = "pattern1";
Step pickleStep1 = getPickleStep(stepText);
StepDefinition stepDefinition1 = new MockedScenarioScopedStepDefinition("^pattern1");
glue.addStepDefinition(stepDefinition1);
glue.prepareGlue(stepTypeRegistry);
PickleStepDefinitionMatch pickleStepDefinitionMatch = glue.stepDefinitionMatch(uri, pickleStep1);
assertThat(((CoreStepDefinition) pickleStepDefinitionMatch.getStepDefinition()).getStepDefinition(), is(equalTo(stepDefinition1)));
glue.removeScenarioScopedGlue();
StepDefinition stepDefinition2 = new MockedScenarioScopedStepDefinition("^pattern1");
glue.addStepDefinition(stepDefinition2);
glue.prepareGlue(stepTypeRegistry);
PickleStepDefinitionMatch pickleStepDefinitionMatch2 = glue.stepDefinitionMatch(uri, pickleStep1);
assertThat(((CoreStepDefinition) pickleStepDefinitionMatch2.getStepDefinition()).getStepDefinition(), is(equalTo(stepDefinition2)));
}
use of io.cucumber.core.backend.StepDefinition in project cucumber-jvm by cucumber.
the class CachingGlueTest method returns_match_from_cache_for_step_with_table.
@Test
void returns_match_from_cache_for_step_with_table() throws AmbiguousStepDefinitionsException {
StepDefinition stepDefinition1 = new MockedStepDefinition("^pattern1", DataTable.class);
StepDefinition stepDefinition2 = new MockedStepDefinition("^pattern2", DataTable.class);
glue.addStepDefinition(stepDefinition1);
glue.addStepDefinition(stepDefinition2);
glue.prepareGlue(stepTypeRegistry);
URI uri = URI.create("file:path/to.feature");
String stepText = "pattern1";
Step pickleStep1 = getPickleStepWithSingleCellTable(stepText, "cell 1");
PickleStepDefinitionMatch match1 = glue.stepDefinitionMatch(uri, pickleStep1);
assertThat(((CoreStepDefinition) match1.getStepDefinition()).getStepDefinition(), is(equalTo(stepDefinition1)));
// check cache
assertThat(glue.getStepPatternByStepText().get(stepText), is(equalTo(stepDefinition1.getPattern())));
CoreStepDefinition coreStepDefinition = glue.getStepDefinitionsByPattern().get(stepDefinition1.getPattern());
assertThat(coreStepDefinition.getStepDefinition(), is(equalTo(stepDefinition1)));
// check arguments
assertThat(((DataTable) match1.getArguments().get(0).getValue()).cell(0, 0), is(equalTo("cell 1")));
// check second match
Step pickleStep2 = getPickleStepWithSingleCellTable(stepText, "cell 2");
PickleStepDefinitionMatch match2 = glue.stepDefinitionMatch(uri, pickleStep2);
// check arguments
assertThat(((DataTable) match2.getArguments().get(0).getValue()).cell(0, 0), is(equalTo("cell 2")));
}
use of io.cucumber.core.backend.StepDefinition in project cucumber-jvm by cucumber.
the class CachingGlueTest method throws_ambiguous_steps_def_exception_when_many_patterns_match.
@Test
void throws_ambiguous_steps_def_exception_when_many_patterns_match() {
StepDefinition stepDefinition1 = new MockedStepDefinition("pattern1");
StepDefinition stepDefinition2 = new MockedStepDefinition("^pattern2");
StepDefinition stepDefinition3 = new MockedStepDefinition("^pattern[1,3]");
glue.addStepDefinition(stepDefinition1);
glue.addStepDefinition(stepDefinition2);
glue.addStepDefinition(stepDefinition3);
glue.prepareGlue(stepTypeRegistry);
URI uri = URI.create("file:path/to.feature");
checkAmbiguousCalled(uri);
// try again to verify if we don't cache when there is ambiguous step
checkAmbiguousCalled(uri);
}
Aggregations