Search in sources :

Example 11 with StubStepDefinition

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

the class RuntimeTest method should_call_formatter_for_two_scenarios_with_background.

@Test
void should_call_formatter_for_two_scenarios_with_background() {
    Feature feature = TestFeatureParser.parse("path/test.feature", "" + "Feature: feature name\n" + "  Background: background\n" + "    Given first step\n" + "  Scenario: scenario_1 name\n" + "    When second step\n" + "    Then third step\n" + "  Scenario: scenario_2 name\n" + "    Then second step\n");
    FormatterSpy formatterSpy = new FormatterSpy();
    Runtime.builder().withFeatureSupplier(new StubFeatureSupplier(feature)).withAdditionalPlugins(formatterSpy).withBackendSupplier(new StubBackendSupplier(new StubStepDefinition("first step"), new StubStepDefinition("second step"), new StubStepDefinition("third step"))).build().run();
    assertThat(formatterSpy.toString(), is(equalTo("" + "TestRun started\n" + "  TestCase started\n" + "    TestStep started\n" + "    TestStep finished\n" + "    TestStep started\n" + "    TestStep finished\n" + "    TestStep started\n" + "    TestStep finished\n" + "  TestCase finished\n" + "  TestCase started\n" + "    TestStep started\n" + "    TestStep finished\n" + "    TestStep started\n" + "    TestStep finished\n" + "  TestCase finished\n" + "TestRun finished\n")));
}
Also used : StubStepDefinition(io.cucumber.core.backend.StubStepDefinition) Feature(io.cucumber.core.gherkin.Feature) Test(org.junit.jupiter.api.Test)

Example 12 with StubStepDefinition

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

the class StepExpressionFactoryTest method creates_a_step_expression.

@Test
void creates_a_step_expression() {
    StepDefinition stepDefinition = new StubStepDefinition("Given a step");
    StepExpression expression = stepExpressionFactory.createExpression(stepDefinition);
    assertThat(expression.getSource(), is("Given a step"));
    assertThat(expression.getExpressionType(), is(CucumberExpression.class));
    assertThat(expression.match("Given a step"), is(emptyList()));
}
Also used : StubStepDefinition(io.cucumber.core.backend.StubStepDefinition) StepDefinition(io.cucumber.core.backend.StepDefinition) StubStepDefinition(io.cucumber.core.backend.StubStepDefinition) CucumberExpression(io.cucumber.cucumberexpressions.CucumberExpression) Test(org.junit.jupiter.api.Test)

Example 13 with StubStepDefinition

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

the class StepExpressionFactoryTest method empty_table_cells_are_presented_as_null_to_transformer.

@SuppressWarnings("unchecked")
@Test
void empty_table_cells_are_presented_as_null_to_transformer() {
    registry.setDefaultDataTableEntryTransformer((map, valueType, tableCellByTypeTransformer) -> objectMapper.convertValue(map, objectMapper.constructType(valueType)));
    StepDefinition stepDefinition = new StubStepDefinition("Given some stuff:", getTypeFromStepDefinition());
    StepExpression expression = stepExpressionFactory.createExpression(stepDefinition);
    List<List<String>> table = asList(asList("name", "amount", "unit"), asList("chocolate", null, "tbsp"));
    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.name, is(equalTo("chocolate")));
}
Also used : 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)

Example 14 with StubStepDefinition

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

the class PrettyFormatterTest method should_print_output_from_after_hooks.

@Test
void should_print_output_from_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(testCaseState -> testCaseState.log("printed from hook"))))).build().run();
    assertThat(out, bytesContainsString("" + "  Given first step      # path/step_definitions.java:3\n" + "\n" + "    printed from hook\n"));
}
Also used : StubBackendSupplier(io.cucumber.core.runtime.StubBackendSupplier) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Runtime(io.cucumber.core.runtime.Runtime) Formats.ansi(io.cucumber.core.plugin.Formats.ansi) StubStepDefinition(io.cucumber.core.backend.StubStepDefinition) IsEqual.equalTo(org.hamcrest.core.IsEqual.equalTo) Collections.singletonList(java.util.Collections.singletonList) StepDefinition(io.cucumber.core.backend.StepDefinition) StubStaticHookDefinition(io.cucumber.core.backend.StubStaticHookDefinition) StepExpression(io.cucumber.core.stepexpression.StepExpression) Locale(java.util.Locale) Arrays.asList(java.util.Arrays.asList) BytesContainsString.bytesContainsString(io.cucumber.core.plugin.BytesContainsString.bytesContainsString) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) DataTable(io.cucumber.datatable.DataTable) BytesEqualTo.isBytesEqualTo(io.cucumber.core.plugin.BytesEqualTo.isBytesEqualTo) StubHookDefinition(io.cucumber.core.backend.StubHookDefinition) EventBus(io.cucumber.core.eventbus.EventBus) TestFeatureParser(io.cucumber.core.feature.TestFeatureParser) StubFeatureSupplier(io.cucumber.core.runtime.StubFeatureSupplier) StepTypeRegistry(io.cucumber.core.stepexpression.StepTypeRegistry) Collections.emptyList(java.util.Collections.emptyList) StepExpressionFactory(io.cucumber.core.stepexpression.StepExpressionFactory) TimeServiceEventBus(io.cucumber.core.runtime.TimeServiceEventBus) UUID(java.util.UUID) TestDefinitionArgument.createArguments(io.cucumber.core.runner.TestDefinitionArgument.createArguments) Test(org.junit.jupiter.api.Test) RuntimeOptionsBuilder(io.cucumber.core.options.RuntimeOptionsBuilder) Feature(io.cucumber.core.gherkin.Feature) Clock(java.time.Clock) 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 15 with StubStepDefinition

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

the class PrettyFormatterTest method should_handle_background.

@Test
void should_handle_background() {
    Feature feature = TestFeatureParser.parse("path/test.feature", "" + "Feature: feature name\n" + "  Background: background name\n" + "    Given first step\n" + "  Scenario: s1\n" + "    Then second step\n" + "  Scenario: s2\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, bytesContainsString("" + "\n" + "Scenario: s1       # path/test.feature:4\n" + "  Given first step # path/step_definitions.java:3\n" + "  Then second step # path/step_definitions.java:7\n" + "\n" + "Scenario: s2       # path/test.feature:6\n" + "  Given first step # path/step_definitions.java:3\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