Search in sources :

Example 21 with StepDefinition

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

the class JavaStepDefinitionTransposeTest method isTransposed.

private boolean isTransposed(Method method) {
    Steps steps = new Steps();
    Lookup lookup = new SingletonFactory(steps);
    StepDefinition stepDefinition = new JavaStepDefinition(method, "some text", lookup);
    return stepDefinition.parameterInfos().get(0).isTransposed();
}
Also used : StepDefinition(io.cucumber.core.backend.StepDefinition) Lookup(io.cucumber.core.backend.Lookup)

Example 22 with StepDefinition

use of io.cucumber.core.backend.StepDefinition 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)));
}
Also used : DataTable(io.cucumber.datatable.DataTable) 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 23 with StepDefinition

use of io.cucumber.core.backend.StepDefinition 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));
}
Also used : DocStringType(io.cucumber.docstring.DocStringType) StubStepDefinition(io.cucumber.core.backend.StubStepDefinition) StepDefinition(io.cucumber.core.backend.StepDefinition) StubStepDefinition(io.cucumber.core.backend.StubStepDefinition) JsonNode(com.fasterxml.jackson.databind.JsonNode) DocString(io.cucumber.docstring.DocString) Test(org.junit.jupiter.api.Test)

Example 24 with StepDefinition

use of io.cucumber.core.backend.StepDefinition 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)));
}
Also used : StubStepDefinition(io.cucumber.core.backend.StubStepDefinition) StepDefinition(io.cucumber.core.backend.StepDefinition) StubStepDefinition(io.cucumber.core.backend.StubStepDefinition) DocString(io.cucumber.docstring.DocString) Test(org.junit.jupiter.api.Test)

Example 25 with StepDefinition

use of io.cucumber.core.backend.StepDefinition 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)")));
}
Also used : Argument(io.cucumber.core.stepexpression.Argument) StubStepDefinition(io.cucumber.core.backend.StubStepDefinition) StepDefinition(io.cucumber.core.backend.StepDefinition) StubStepDefinition(io.cucumber.core.backend.StubStepDefinition) CucumberBackendException(io.cucumber.core.backend.CucumberBackendException) Step(io.cucumber.core.gherkin.Step) CucumberException(io.cucumber.core.exception.CucumberException) Executable(org.junit.jupiter.api.function.Executable) Feature(io.cucumber.core.gherkin.Feature) 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