use of io.cucumber.core.backend.StubStepDefinition in project cucumber-jvm by cucumber.
the class RuntimeTest method should_make_scenario_name_available_to_hooks.
@Test
void should_make_scenario_name_available_to_hooks() {
final Feature feature = TestFeatureParser.parse("path/test.feature", "Feature: feature name\n" + " Scenario: scenario name\n" + " Given first step\n" + " When second step\n" + " Then third step\n");
final HookDefinition beforeHook = mock(HookDefinition.class);
when(beforeHook.getLocation()).thenReturn("");
when(beforeHook.getTagExpression()).thenReturn("");
FeatureSupplier featureSupplier = new StubFeatureSupplier(feature);
Runtime runtime = Runtime.builder().withFeatureSupplier(featureSupplier).withBackendSupplier(new StubBackendSupplier(singletonList(beforeHook), asList(new StubStepDefinition("first step"), new StubStepDefinition("second step"), new StubStepDefinition("third step")), emptyList())).build();
runtime.run();
ArgumentCaptor<TestCaseState> capturedScenario = ArgumentCaptor.forClass(TestCaseState.class);
verify(beforeHook).execute(capturedScenario.capture());
assertThat(capturedScenario.getValue().getName(), is(equalTo("scenario name")));
}
use of io.cucumber.core.backend.StubStepDefinition in project cucumber-jvm by cucumber.
the class StepExpressionFactoryTest method table_expression_with_type_creates_table_from_table.
@Test
void table_expression_with_type_creates_table_from_table() {
StepDefinition stepDefinition = new StubStepDefinition("Given some stuff:", DataTable.class);
StepExpression expression = stepExpressionFactory.createExpression(stepDefinition);
List<Argument> match = expression.match("Given some stuff:", table);
DataTable dataTable = (DataTable) match.get(0).getValue();
assertThat(dataTable.cells(), is(equalTo(table)));
}
use of io.cucumber.core.backend.StubStepDefinition in project cucumber-jvm by cucumber.
the class StepExpressionFactoryTest method docstring_expression_transform_doc_string_to_json_node.
@Test
void docstring_expression_transform_doc_string_to_json_node() {
String docString = "{\"hello\": \"world\"}";
String contentType = "json";
registry.defineDocStringType(new DocStringType(JsonNode.class, contentType, (String s) -> objectMapper.convertValue(docString, JsonNode.class)));
StepDefinition stepDefinition = new StubStepDefinition("Given some stuff:", JsonNode.class);
StepExpression expression = stepExpressionFactory.createExpression(stepDefinition);
List<Argument> match = expression.match("Given some stuff:", docString, contentType);
JsonNode node = (JsonNode) match.get(0).getValue();
assertThat(node.asText(), equalTo(docString));
}
use of io.cucumber.core.backend.StubStepDefinition in project cucumber-jvm by cucumber.
the class StepExpressionFactoryTest method docstring_expression_transform_doc_string_to_string.
@Test
void docstring_expression_transform_doc_string_to_string() {
String docString = "A rather long and boring string of documentation";
StepDefinition stepDefinition = new StubStepDefinition("Given some stuff:", String.class);
StepExpression expression = stepExpressionFactory.createExpression(stepDefinition);
List<Argument> match = expression.match("Given some stuff:", docString, null);
assertThat(match.get(0).getValue(), is(equalTo(docString)));
}
use of io.cucumber.core.backend.StubStepDefinition in project cucumber-jvm by cucumber.
the class StepDefinitionMatchTest method throws_could_not_invoke_step_when_execution_failed_with_null_arguments.
@Test
void throws_could_not_invoke_step_when_execution_failed_with_null_arguments() {
Feature feature = TestFeatureParser.parse("file:test.feature", "" + "Feature: Test feature\n" + " Scenario: Test scenario\n" + " Given I have an null value\n");
Step step = feature.getPickles().get(0).getSteps().get(0);
StepDefinition stepDefinition = new StubStepDefinition("I have an {word} value", new CucumberBackendException("This exception is expected!", new IllegalAccessException()), String.class);
List<Argument> arguments = asList(() -> null);
StepDefinitionMatch stepDefinitionMatch = new PickleStepDefinitionMatch(arguments, stepDefinition, URI.create("file:path/to.feature"), step);
Executable testMethod = () -> stepDefinitionMatch.runStep(null);
CucumberException actualThrown = assertThrows(CucumberException.class, testMethod);
assertThat("Unexpected exception message", actualThrown.getMessage(), is(equalTo("Could not invoke step [I have an {word} value] defined at '{stubbed location with details}'.\n" + "It appears there was a problem with the step definition.\n" + "The converted arguments types were (null)")));
}
Aggregations