Search in sources :

Example 16 with StubStepDefinition

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

the class PrettyFormatterTest method should_print_tags.

@Test
void should_print_tags() {
    Feature feature = TestFeatureParser.parse("path/test.feature", "" + "@feature_tag\n" + "Feature: feature name\n" + "  @scenario_tag\n" + "  Scenario: scenario name\n" + "    Then first step\n" + "  @scenario_outline_tag\n" + "  Scenario Outline: scenario outline name\n" + "    Then <arg> step\n" + "    @examples_tag\n" + "    Examples: examples name\n" + "      |  arg    |\n" + "      | second  |\n");
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    Runtime.builder().withFeatureSupplier(new StubFeatureSupplier(feature)).withAdditionalPlugins(new PrettyFormatter(out)).withRuntimeOptions(new RuntimeOptionsBuilder().setMonochrome().build()).withBackendSupplier(new StubBackendSupplier(new StubStepDefinition("first step", "path/step_definitions.java:7"), new StubStepDefinition("second step", "path/step_definitions.java:11"))).build().run();
    assertThat(out, isBytesEqualTo("" + "\n" + "@feature_tag @scenario_tag\n" + "Scenario: scenario name # path/test.feature:4\n" + "  Then first step       # path/step_definitions.java:7\n" + "\n" + "@feature_tag @scenario_outline_tag @examples_tag\n" + "Scenario Outline: scenario outline name # path/test.feature:12\n" + "  Then second step                      # path/step_definitions.java:11\n"));
}
Also used : StubBackendSupplier(io.cucumber.core.runtime.StubBackendSupplier) StubFeatureSupplier(io.cucumber.core.runtime.StubFeatureSupplier) RuntimeOptionsBuilder(io.cucumber.core.options.RuntimeOptionsBuilder) StubStepDefinition(io.cucumber.core.backend.StubStepDefinition) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Feature(io.cucumber.core.gherkin.Feature) Test(org.junit.jupiter.api.Test)

Example 17 with StubStepDefinition

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

the class PrettyFormatterTest method should_print_multiple_tables.

@Test
void should_print_multiple_tables() {
    Feature feature = TestFeatureParser.parse("path/test.feature", "" + "Feature: Test feature\n" + "  Scenario: Test Scenario\n" + "    Given first step\n" + "      | key1     | key2     |\n" + "      | value1   | value2   |\n" + "      | another1 | another2 |\n" + "    Given second step\n" + "      | key3     | key4     |\n" + "      | value3   | value4   |\n" + "      | another3 | another4 |\n");
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    Runtime.builder().withFeatureSupplier(new StubFeatureSupplier(feature)).withAdditionalPlugins(new PrettyFormatter(out)).withRuntimeOptions(new RuntimeOptionsBuilder().setMonochrome().build()).withBackendSupplier(new StubBackendSupplier(new StubStepDefinition("first step", "path/step_definitions.java:7", DataTable.class), new StubStepDefinition("second step", "path/step_definitions.java:15", DataTable.class))).build().run();
    assertThat(out, isBytesEqualTo("" + "\n" + "Scenario: Test Scenario # path/test.feature:2\n" + "  Given first step      # path/step_definitions.java:7\n" + "    | key1     | key2     |\n" + "    | value1   | value2   |\n" + "    | another1 | another2 |\n" + "  Given second step     # path/step_definitions.java:15\n" + "    | key3     | key4     |\n" + "    | value3   | value4   |\n" + "    | another3 | another4 |\n"));
}
Also used : StubBackendSupplier(io.cucumber.core.runtime.StubBackendSupplier) StubFeatureSupplier(io.cucumber.core.runtime.StubFeatureSupplier) RuntimeOptionsBuilder(io.cucumber.core.options.RuntimeOptionsBuilder) StubStepDefinition(io.cucumber.core.backend.StubStepDefinition) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Feature(io.cucumber.core.gherkin.Feature) Test(org.junit.jupiter.api.Test)

Example 18 with StubStepDefinition

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

the class PrettyFormatterTest method should_mark_nested_argument_as_part_of_full_argument.

@Test
void should_mark_nested_argument_as_part_of_full_argument() {
    Formats formats = ansi();
    StepTypeRegistry registry = new StepTypeRegistry(Locale.ENGLISH);
    StepExpressionFactory stepExpressionFactory = new StepExpressionFactory(registry, bus);
    StepDefinition stepDefinition = new StubStepDefinition("^the order is placed( and (not yet )?confirmed)?$", String.class);
    StepExpression expression = stepExpressionFactory.createExpression(stepDefinition);
    PrettyFormatter prettyFormatter = new PrettyFormatter(new ByteArrayOutputStream());
    String stepText = "the order is placed and not yet confirmed";
    String formattedText = prettyFormatter.formatStepText("Given ", stepText, formats.get("passed"), formats.get("passed_arg"), createArguments(expression.match(stepText)));
    assertThat(formattedText, equalTo(AnsiEscapes.GREEN + "Given " + AnsiEscapes.RESET + AnsiEscapes.GREEN + "the order is placed" + AnsiEscapes.RESET + AnsiEscapes.GREEN + AnsiEscapes.INTENSITY_BOLD + " and not yet confirmed" + AnsiEscapes.RESET));
}
Also used : StepTypeRegistry(io.cucumber.core.stepexpression.StepTypeRegistry) StepExpressionFactory(io.cucumber.core.stepexpression.StepExpressionFactory) StubStepDefinition(io.cucumber.core.backend.StubStepDefinition) StepDefinition(io.cucumber.core.backend.StepDefinition) StubStepDefinition(io.cucumber.core.backend.StubStepDefinition) ByteArrayOutputStream(java.io.ByteArrayOutputStream) BytesContainsString.bytesContainsString(io.cucumber.core.plugin.BytesContainsString.bytesContainsString) StepExpression(io.cucumber.core.stepexpression.StepExpression) Test(org.junit.jupiter.api.Test)

Example 19 with StubStepDefinition

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

the class PrettyFormatterTest method should_print_error_message_for_before_hooks.

@Test
void should_print_error_message_for_before_hooks() {
    Feature feature = TestFeatureParser.parse("path/test.feature", "" + "Feature: feature name\n" + "  Scenario: scenario name\n" + "    Given first step\n");
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    Runtime.builder().withFeatureSupplier(new StubFeatureSupplier(feature)).withAdditionalPlugins(new PrettyFormatter(out)).withRuntimeOptions(new RuntimeOptionsBuilder().setMonochrome().build()).withBackendSupplier(new StubBackendSupplier(singletonList(new StubHookDefinition(new StubException())), singletonList(new StubStepDefinition("first step", "path/step_definitions.java:3")), emptyList())).build().run();
    assertThat(out, bytesContainsString("" + "Scenario: scenario name # path/test.feature:2\n" + "      the stack trace\n" + "  Given first step      # path/step_definitions.java:3\n"));
}
Also used : StubBackendSupplier(io.cucumber.core.runtime.StubBackendSupplier) StubFeatureSupplier(io.cucumber.core.runtime.StubFeatureSupplier) StubHookDefinition(io.cucumber.core.backend.StubHookDefinition) RuntimeOptionsBuilder(io.cucumber.core.options.RuntimeOptionsBuilder) StubStepDefinition(io.cucumber.core.backend.StubStepDefinition) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Feature(io.cucumber.core.gherkin.Feature) Test(org.junit.jupiter.api.Test)

Example 20 with StubStepDefinition

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

the class PrettyFormatterTest method should_align_the_indentation_of_location_strings.

@Test
void should_align_the_indentation_of_location_strings() {
    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");
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    Runtime.builder().withFeatureSupplier(new StubFeatureSupplier(feature)).withAdditionalPlugins(new PrettyFormatter(out)).withRuntimeOptions(new RuntimeOptionsBuilder().setMonochrome().build()).withBackendSupplier(new StubBackendSupplier(new StubStepDefinition("first step", "path/step_definitions.java:3"), new StubStepDefinition("second step", "path/step_definitions.java:7"), new StubStepDefinition("third step", "path/step_definitions.java:11"))).build().run();
    assertThat(out, isBytesEqualTo("" + "\n" + "Scenario: scenario name # path/test.feature:2\n" + "  Given first step      # path/step_definitions.java:3\n" + "  When second step      # path/step_definitions.java:7\n" + "  Then third step       # path/step_definitions.java:11\n"));
}
Also used : StubBackendSupplier(io.cucumber.core.runtime.StubBackendSupplier) StubFeatureSupplier(io.cucumber.core.runtime.StubFeatureSupplier) RuntimeOptionsBuilder(io.cucumber.core.options.RuntimeOptionsBuilder) StubStepDefinition(io.cucumber.core.backend.StubStepDefinition) ByteArrayOutputStream(java.io.ByteArrayOutputStream) 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