Search in sources :

Example 96 with Feature

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

the class CoreStepDefinitionTest method should_apply_identity_transform_to_doc_string_when_target_type_is_object.

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

Example 97 with Feature

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

the class CoreStepDefinitionTest method passes_plain_data_table.

@Test
void passes_plain_data_table() throws Throwable {
    Method m = Steps.class.getMethod("plainDataTable", DataTable.class);
    Feature feature = TestFeatureParser.parse("" + "Feature: Test feature\n" + "  Scenario: Test scenario\n" + "     Given some text\n" + "      | Birth Date | \n" + "      | 1957-05-10 | \n");
    DataTable stepDefs = runStepDef(m, false, feature);
    assertAll(() -> assertThat(stepDefs.cell(0, 0), is(equalTo("Birth Date"))), () -> assertThat(stepDefs.cell(1, 0), is(equalTo("1957-05-10"))));
}
Also used : DataTable(io.cucumber.datatable.DataTable) Method(java.lang.reflect.Method) Feature(io.cucumber.core.gherkin.Feature) Test(org.junit.jupiter.api.Test)

Example 98 with Feature

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

the class CoreStepDefinitionTest method transforms_to_list_of_single_values.

@Test
void transforms_to_list_of_single_values() throws Throwable {
    Method m = Steps.class.getMethod("listOfListOfDoubles", List.class);
    Feature feature = TestFeatureParser.parse("" + "Feature: Test feature\n" + "  Scenario: Test scenario\n" + "     Given some text\n" + "      | 100.5 | 99.5 | \n" + "      | 0.5   | -0.5 | \n" + "      | 1000  | 999  | \n");
    List<List<Double>> stepDefs = runStepDef(m, false, feature);
    assertThat(stepDefs.toString(), is(equalTo("[[100.5, 99.5], [0.5, -0.5], [1000.0, 999.0]]")));
}
Also used : ArrayList(java.util.ArrayList) Collections.singletonList(java.util.Collections.singletonList) Arrays.asList(java.util.Arrays.asList) List(java.util.List) Method(java.lang.reflect.Method) Feature(io.cucumber.core.gherkin.Feature) Test(org.junit.jupiter.api.Test)

Example 99 with Feature

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

the class RunnerTest method createPickleMatchingStepDefinitions.

private Pickle createPickleMatchingStepDefinitions(StubStepDefinition stepDefinition) {
    String pattern = stepDefinition.getPattern();
    Feature feature = TestFeatureParser.parse("" + "Feature: Test feature\n" + "  Scenario: Test scenario\n" + "     Given " + pattern + "\n");
    return feature.getPickles().get(0);
}
Also used : Feature(io.cucumber.core.gherkin.Feature)

Example 100 with Feature

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

the class TestCaseStateTest method attach_string_emits_event_on_bus.

@Test
void attach_string_emits_event_on_bus() {
    Feature feature = TestFeatureParser.parse("" + "Feature: Test feature\n" + "  Scenario: Test scenario\n" + "     Given I have 4 cukes in my belly\n");
    TestCaseState state = createTestCaseState(feature);
    List<EmbedEvent> embedEvents = new ArrayList<>();
    List<Envelope> envelopes = new ArrayList<>();
    bus.registerHandlerFor(EmbedEvent.class, embedEvents::add);
    bus.registerHandlerFor(Envelope.class, envelopes::add);
    UUID activeTestStep = UUID.randomUUID();
    state.setCurrentTestStepId(activeTestStep);
    state.attach("Hello World", "text/plain", "hello.txt");
    EmbedEvent embedEvent = embedEvents.get(0);
    assertThat(embedEvent.getData(), is("Hello World".getBytes(UTF_8)));
    assertThat(embedEvent.getMediaType(), is("text/plain"));
    assertThat(embedEvent.getName(), is("hello.txt"));
    Envelope envelope = envelopes.get(0);
    assertThat(envelope.getAttachment().getBody(), is("Hello World"));
    assertThat(envelope.getAttachment().getContentEncoding(), is(ContentEncoding.IDENTITY));
    assertThat(envelope.getAttachment().getMediaType(), is("text/plain"));
    assertThat(envelope.getAttachment().getFileName(), is("hello.txt"));
    assertThat(envelope.getAttachment().getTestStepId(), is(activeTestStep.toString()));
    assertThat(envelope.getAttachment().getTestCaseStartedId(), is(state.getTestExecutionId().toString()));
}
Also used : ArrayList(java.util.ArrayList) Envelope(io.cucumber.messages.types.Envelope) UUID(java.util.UUID) Feature(io.cucumber.core.gherkin.Feature) EmbedEvent(io.cucumber.plugin.event.EmbedEvent) 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