Search in sources :

Example 26 with StubStepDefinition

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

the class PrettyFormatterTest method should_print_error_message_for_after_hooks.

@Test
void should_print_error_message_for_after_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(emptyList(), singletonList(new StubStepDefinition("first step", "path/step_definitions.java:3")), singletonList(new StubHookDefinition(new StubException())))).build().run();
    assertThat(out, bytesContainsString("" + "  Given first step      # path/step_definitions.java:3\n" + "      the stack trace\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 27 with StubStepDefinition

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

the class PrettyFormatterTest method should_mark_subsequent_arguments_in_steps.

@Test
void should_mark_subsequent_arguments_in_steps() {
    Formats formats = ansi();
    StepTypeRegistry registry = new StepTypeRegistry(Locale.ENGLISH);
    StepExpressionFactory stepExpressionFactory = new StepExpressionFactory(registry, bus);
    StepDefinition stepDefinition = new StubStepDefinition("text {string} text {string}", String.class);
    StepExpression expression = stepExpressionFactory.createExpression(stepDefinition);
    PrettyFormatter prettyFormatter = new PrettyFormatter(new ByteArrayOutputStream());
    String stepText = "text 'arg1' text 'arg2'";
    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 + "text " + AnsiEscapes.RESET + AnsiEscapes.GREEN + AnsiEscapes.INTENSITY_BOLD + "'arg1'" + AnsiEscapes.RESET + AnsiEscapes.GREEN + " text " + AnsiEscapes.RESET + AnsiEscapes.GREEN + AnsiEscapes.INTENSITY_BOLD + "'arg2'" + 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 28 with StubStepDefinition

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

the class PrettyFormatterTest method should_color_code_steps_according_to_the_result.

@Test
void should_color_code_steps_according_to_the_result() {
    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)).withBackendSupplier(new StubBackendSupplier(new StubStepDefinition("first step", "path/step_definitions.java:3"))).build().run();
    assertThat(out, bytesContainsString("" + "  " + AnsiEscapes.GREEN + "Given " + AnsiEscapes.RESET + AnsiEscapes.GREEN + "first step" + AnsiEscapes.RESET));
}
Also used : StubBackendSupplier(io.cucumber.core.runtime.StubBackendSupplier) StubFeatureSupplier(io.cucumber.core.runtime.StubFeatureSupplier) StubStepDefinition(io.cucumber.core.backend.StubStepDefinition) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Feature(io.cucumber.core.gherkin.Feature) Test(org.junit.jupiter.api.Test)

Example 29 with StubStepDefinition

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

the class HookOrderTest method before_hooks_execute_in_order.

@Test
void before_hooks_execute_in_order() {
    final List<HookDefinition> hooks = mockHooks(3, Integer.MAX_VALUE, 1, -1, 0, 10000, Integer.MIN_VALUE);
    TestRunnerSupplier runnerSupplier = new TestRunnerSupplier(bus, runtimeOptions) {

        @Override
        public void loadGlue(Glue glue, List<URI> gluePaths) {
            glue.addStepDefinition(new StubStepDefinition("pattern1"));
            for (HookDefinition hook : hooks) {
                glue.addBeforeHook(hook);
            }
        }
    };
    runnerSupplier.get().runPickle(pickle);
    InOrder inOrder = inOrder(hooks.toArray());
    inOrder.verify(hooks.get(6)).execute(ArgumentMatchers.any());
    inOrder.verify(hooks.get(3)).execute(ArgumentMatchers.any());
    inOrder.verify(hooks.get(4)).execute(ArgumentMatchers.any());
    inOrder.verify(hooks.get(2)).execute(ArgumentMatchers.any());
    inOrder.verify(hooks.get(0)).execute(ArgumentMatchers.any());
    inOrder.verify(hooks.get(5)).execute(ArgumentMatchers.any());
    inOrder.verify(hooks.get(1)).execute(ArgumentMatchers.any());
}
Also used : InOrder(org.mockito.InOrder) Glue(io.cucumber.core.backend.Glue) StubStepDefinition(io.cucumber.core.backend.StubStepDefinition) ArrayList(java.util.ArrayList) List(java.util.List) HookDefinition(io.cucumber.core.backend.HookDefinition) Test(org.junit.jupiter.api.Test)

Example 30 with StubStepDefinition

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

the class StepExpressionFactoryTest method table_expression_with_list_type_creates_list_of_ingredients_from_table.

@SuppressWarnings("unchecked")
@Test
void table_expression_with_list_type_creates_list_of_ingredients_from_table() {
    registry.defineDataTableType(new DataTableType(Ingredient.class, listBeanMapper(registry)));
    StepDefinition stepDefinition = new StubStepDefinition("Given some stuff:", getTypeFromStepDefinition());
    StepExpression expression = stepExpressionFactory.createExpression(stepDefinition);
    List<Argument> match = expression.match("Given some stuff:", table);
    List<Ingredient> ingredients = (List<Ingredient>) match.get(0).getValue();
    Ingredient ingredient = ingredients.get(0);
    assertThat(ingredient.amount, is(equalTo(2)));
}
Also used : DataTableType(io.cucumber.datatable.DataTableType) StubStepDefinition(io.cucumber.core.backend.StubStepDefinition) StepDefinition(io.cucumber.core.backend.StepDefinition) StubStepDefinition(io.cucumber.core.backend.StubStepDefinition) ArrayList(java.util.ArrayList) Arrays.asList(java.util.Arrays.asList) Collections.emptyList(java.util.Collections.emptyList) List(java.util.List) 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