Search in sources :

Example 31 with Feature

use of io.cucumber.core.gherkin.Feature in project cucumber-jvm by cucumber.

the class TestCaseStateTest method provides_both_the_example_row_line_and_scenario_outline_line_for_scenarios_from_scenario_outlines.

@Test
void provides_both_the_example_row_line_and_scenario_outline_line_for_scenarios_from_scenario_outlines() {
    Feature feature = TestFeatureParser.parse("" + "Feature: Test feature\n" + "  Scenario Outline: Test scenario\n" + "     Given I have 4 <thing> in my belly\n" + "     Examples:\n" + "       | thing | \n" + "       | cuke  | \n");
    TestCaseState state = createTestCaseState(feature);
    assertThat(state.getLine(), is(6));
}
Also used : Feature(io.cucumber.core.gherkin.Feature) Test(org.junit.jupiter.api.Test)

Example 32 with Feature

use of io.cucumber.core.gherkin.Feature in project cucumber-jvm by cucumber.

the class TestCaseStateTest method provides_the_uri_and_scenario_line_as_unique_id.

@Test
void provides_the_uri_and_scenario_line_as_unique_id() {
    Feature feature = TestFeatureParser.parse("file:path/file.feature", "" + "Feature: Test feature\n" + "  Scenario: Test scenario\n" + "     Given I have 4 cukes in my belly\n");
    TestCaseState state = createTestCaseState(feature);
    assertThat(state.getUri() + ":" + state.getLine(), is(new File("path/file.feature:2").toURI().toString()));
}
Also used : Feature(io.cucumber.core.gherkin.Feature) File(java.io.File) Test(org.junit.jupiter.api.Test)

Example 33 with Feature

use of io.cucumber.core.gherkin.Feature in project cucumber-jvm by cucumber.

the class AmbiguousStepDefinitionsExceptionTest method can_report_ambiguous_step_definitions.

@Test
void can_report_ambiguous_step_definitions() {
    Feature feature = TestFeatureParser.parse("" + "Feature: Test feature\n" + "  Scenario: Test scenario\n" + "     Given I have 4 cukes in my belly\n");
    Step mockPickleStep = feature.getPickles().get(0).getSteps().get(0);
    PickleStepDefinitionMatch mockPickleStepDefinitionMatchOne = mock(PickleStepDefinitionMatch.class);
    when(mockPickleStepDefinitionMatchOne.getPattern()).thenReturn("PickleStepDefinitionMatchOne_Pattern");
    when(mockPickleStepDefinitionMatchOne.getLocation()).thenReturn("PickleStepDefinitionMatchOne_Location");
    PickleStepDefinitionMatch mockPickleStepDefinitionMatchTwo = mock(PickleStepDefinitionMatch.class);
    when(mockPickleStepDefinitionMatchTwo.getPattern()).thenReturn("PickleStepDefinitionMatchTwo_Pattern");
    when(mockPickleStepDefinitionMatchTwo.getLocation()).thenReturn("PickleStepDefinitionMatchTwo_Location");
    List<PickleStepDefinitionMatch> matches = asList(mockPickleStepDefinitionMatchOne, mockPickleStepDefinitionMatchTwo);
    AmbiguousStepDefinitionsException expectedThrown = new AmbiguousStepDefinitionsException(mockPickleStep, matches);
    assertAll(() -> assertThat(expectedThrown.getMessage(), is(equalTo("" + "\"I have 4 cukes in my belly\" matches more than one step definition:\n" + "  \"PickleStepDefinitionMatchOne_Pattern\" in PickleStepDefinitionMatchOne_Location\n" + "  \"PickleStepDefinitionMatchTwo_Pattern\" in PickleStepDefinitionMatchTwo_Location"))), () -> assertThat(expectedThrown.getCause(), is(nullValue())), () -> assertThat(expectedThrown.getMatches(), is(equalTo(matches))));
}
Also used : Step(io.cucumber.core.gherkin.Step) Feature(io.cucumber.core.gherkin.Feature) Test(org.junit.jupiter.api.Test)

Example 34 with Feature

use of io.cucumber.core.gherkin.Feature 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 35 with Feature

use of io.cucumber.core.gherkin.Feature 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

Feature (io.cucumber.core.gherkin.Feature)152 Test (org.junit.jupiter.api.Test)144 StubStepDefinition (io.cucumber.core.backend.StubStepDefinition)92 StubBackendSupplier (io.cucumber.core.runtime.StubBackendSupplier)78 ByteArrayOutputStream (java.io.ByteArrayOutputStream)78 StubFeatureSupplier (io.cucumber.core.runtime.StubFeatureSupplier)77 UUID (java.util.UUID)67 TimeServiceEventBus (io.cucumber.core.runtime.TimeServiceEventBus)59 StubHookDefinition (io.cucumber.core.backend.StubHookDefinition)26 RuntimeOptionsBuilder (io.cucumber.core.options.RuntimeOptionsBuilder)23 Step (io.cucumber.core.gherkin.Step)22 StepDefinition (io.cucumber.core.backend.StepDefinition)21 StepDurationTimeService (io.cucumber.core.runner.StepDurationTimeService)21 Argument (io.cucumber.core.stepexpression.Argument)18 StepExpression (io.cucumber.core.stepexpression.StepExpression)18 DocString (io.cucumber.docstring.DocString)17 Executable (org.junit.jupiter.api.function.Executable)16 URI (java.net.URI)15 Arrays.asList (java.util.Arrays.asList)14 Collections.singletonList (java.util.Collections.singletonList)13