Search in sources :

Example 61 with StubStepDefinition

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")));
}
Also used : StubStepDefinition(io.cucumber.core.backend.StubStepDefinition) Feature(io.cucumber.core.gherkin.Feature) HookDefinition(io.cucumber.core.backend.HookDefinition) TestCaseState(io.cucumber.core.backend.TestCaseState) Test(org.junit.jupiter.api.Test)

Example 62 with StubStepDefinition

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)));
}
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 63 with StubStepDefinition

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));
}
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 64 with StubStepDefinition

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)));
}
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 65 with StubStepDefinition

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)")));
}
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

StubStepDefinition (io.cucumber.core.backend.StubStepDefinition)105 Test (org.junit.jupiter.api.Test)104 Feature (io.cucumber.core.gherkin.Feature)89 ByteArrayOutputStream (java.io.ByteArrayOutputStream)73 StubBackendSupplier (io.cucumber.core.runtime.StubBackendSupplier)71 StubFeatureSupplier (io.cucumber.core.runtime.StubFeatureSupplier)70 TimeServiceEventBus (io.cucumber.core.runtime.TimeServiceEventBus)51 UUID (java.util.UUID)51 StepDefinition (io.cucumber.core.backend.StepDefinition)32 StubHookDefinition (io.cucumber.core.backend.StubHookDefinition)26 DocString (io.cucumber.docstring.DocString)20 StepDurationTimeService (io.cucumber.core.runner.StepDurationTimeService)19 StepExpression (io.cucumber.core.stepexpression.StepExpression)18 RuntimeOptionsBuilder (io.cucumber.core.options.RuntimeOptionsBuilder)17 Step (io.cucumber.core.gherkin.Step)15 Argument (io.cucumber.core.stepexpression.Argument)15 Executable (org.junit.jupiter.api.function.Executable)14 CucumberException (io.cucumber.core.exception.CucumberException)13 Arrays.asList (java.util.Arrays.asList)10 PrintStream (java.io.PrintStream)9