Search in sources :

Example 16 with StepDefinition

use of io.cucumber.core.backend.StepDefinition in project cucumber-jvm by cucumber.

the class StepExpressionFactoryTest method unknown_target_type_does_no_transform_data_table.

@Test
void unknown_target_type_does_no_transform_data_table() {
    StepDefinition stepDefinition = new StubStepDefinition("Given some stuff:", UNKNOWN_TYPE);
    StepExpression expression = stepExpressionFactory.createExpression(stepDefinition);
    List<Argument> match = expression.match("Given some stuff:", table);
    assertThat(match.get(0).getValue(), is(equalTo(DataTable.create(table))));
}
Also used : StubStepDefinition(io.cucumber.core.backend.StubStepDefinition) StepDefinition(io.cucumber.core.backend.StepDefinition) StubStepDefinition(io.cucumber.core.backend.StubStepDefinition) Test(org.junit.jupiter.api.Test)

Example 17 with StepDefinition

use of io.cucumber.core.backend.StepDefinition in project cucumber-jvm by cucumber.

the class StepExpressionFactoryTest method throws_for_unknown_parameter_types.

@Test
void throws_for_unknown_parameter_types() {
    StepDefinition stepDefinition = new StubStepDefinition("Given a {unknownParameterType}");
    List<Envelope> events = new ArrayList<>();
    bus.registerHandlerFor(Envelope.class, events::add);
    CucumberException exception = assertThrows(CucumberException.class, () -> stepExpressionFactory.createExpression(stepDefinition));
    assertThat(exception.getMessage(), is("" + "Could not create a cucumber expression for 'Given a {unknownParameterType}'.\n" + "It appears you did not register a parameter type."));
    assertThat(events, iterableWithSize(1));
    assertNotNull(events.get(0).getUndefinedParameterType());
}
Also used : ArrayList(java.util.ArrayList) StubStepDefinition(io.cucumber.core.backend.StubStepDefinition) StepDefinition(io.cucumber.core.backend.StepDefinition) StubStepDefinition(io.cucumber.core.backend.StubStepDefinition) CucumberException(io.cucumber.core.exception.CucumberException) Envelope(io.cucumber.messages.types.Envelope) Test(org.junit.jupiter.api.Test)

Example 18 with StepDefinition

use of io.cucumber.core.backend.StepDefinition in project cucumber-jvm by cucumber.

the class StepExpressionFactoryTest method table_expression_with_type_creates_single_ingredients_from_table.

@Test
void table_expression_with_type_creates_single_ingredients_from_table() {
    registry.defineDataTableType(new DataTableType(Ingredient.class, beanMapper(registry)));
    StepDefinition stepDefinition = new StubStepDefinition("Given some stuff:", Ingredient.class);
    StepExpression expression = stepExpressionFactory.createExpression(stepDefinition);
    List<Argument> match = expression.match("Given some stuff:", tableTransposed);
    Ingredient ingredient = (Ingredient) match.get(0).getValue();
    assertThat(ingredient.name, is(equalTo("chocolate")));
}
Also used : DataTableType(io.cucumber.datatable.DataTableType) StubStepDefinition(io.cucumber.core.backend.StubStepDefinition) StepDefinition(io.cucumber.core.backend.StepDefinition) StubStepDefinition(io.cucumber.core.backend.StubStepDefinition) Test(org.junit.jupiter.api.Test)

Example 19 with StepDefinition

use of io.cucumber.core.backend.StepDefinition in project cucumber-jvm by cucumber.

the class CoreStepDefinitionTest method should_apply_identity_transform_to_data_table_when_target_type_is_object.

@Test
void should_apply_identity_transform_to_data_table_when_target_type_is_object() {
    Feature feature = TestFeatureParser.parse("" + "Feature: Test feature\n" + "  Scenario: Test scenario\n" + "     Given I have some step\n" + "      | content |\n");
    StepDefinition stepDefinition = new StubStepDefinition("I have some step", Object.class);
    StepExpression expression = stepExpressionFactory.createExpression(stepDefinition);
    CoreStepDefinition coreStepDefinition = new CoreStepDefinition(id, stepDefinition, expression);
    List<Argument> arguments = coreStepDefinition.matchedArguments(feature.getPickles().get(0).getSteps().get(0));
    assertThat(arguments.get(0).getValue(), is(equalTo(DataTable.create(singletonList(singletonList("content"))))));
}
Also used : Argument(io.cucumber.core.stepexpression.Argument) StepDefinition(io.cucumber.core.backend.StepDefinition) Feature(io.cucumber.core.gherkin.Feature) StepExpression(io.cucumber.core.stepexpression.StepExpression) Test(org.junit.jupiter.api.Test)

Example 20 with StepDefinition

use of io.cucumber.core.backend.StepDefinition in project cucumber-jvm by cucumber.

the class CoreStepDefinitionTest method should_convert_empty_pickle_table_cells_to_null_values.

@Test
void should_convert_empty_pickle_table_cells_to_null_values() {
    Feature feature = TestFeatureParser.parse("" + "Feature: Test feature\n" + "  Scenario: Test scenario\n" + "     Given I have some step\n" + "       |  |\n");
    StepDefinition stepDefinition = new StubStepDefinition("I have some step", Object.class);
    StepExpression expression = stepExpressionFactory.createExpression(stepDefinition);
    CoreStepDefinition coreStepDefinition = new CoreStepDefinition(id, stepDefinition, expression);
    List<Argument> arguments = coreStepDefinition.matchedArguments(feature.getPickles().get(0).getSteps().get(0));
    assertEquals(DataTable.create(singletonList(singletonList(null))), arguments.get(0).getValue());
}
Also used : Argument(io.cucumber.core.stepexpression.Argument) StepDefinition(io.cucumber.core.backend.StepDefinition) Feature(io.cucumber.core.gherkin.Feature) StepExpression(io.cucumber.core.stepexpression.StepExpression) Test(org.junit.jupiter.api.Test)

Aggregations

StepDefinition (io.cucumber.core.backend.StepDefinition)43 Test (org.junit.jupiter.api.Test)42 StubStepDefinition (io.cucumber.core.backend.StubStepDefinition)29 Step (io.cucumber.core.gherkin.Step)22 Feature (io.cucumber.core.gherkin.Feature)18 Argument (io.cucumber.core.stepexpression.Argument)18 StepExpression (io.cucumber.core.stepexpression.StepExpression)18 Executable (org.junit.jupiter.api.function.Executable)14 CucumberException (io.cucumber.core.exception.CucumberException)13 URI (java.net.URI)9 DataTableType (io.cucumber.datatable.DataTableType)6 CucumberBackendException (io.cucumber.core.backend.CucumberBackendException)5 CucumberInvocationTargetException (io.cucumber.core.backend.CucumberInvocationTargetException)5 StepExpressionFactory (io.cucumber.core.stepexpression.StepExpressionFactory)5 StepTypeRegistry (io.cucumber.core.stepexpression.StepTypeRegistry)5 DocString (io.cucumber.docstring.DocString)4 InvocationTargetException (java.lang.reflect.InvocationTargetException)4 Arrays.asList (java.util.Arrays.asList)4 List (java.util.List)4 BytesContainsString.bytesContainsString (io.cucumber.core.plugin.BytesContainsString.bytesContainsString)3