Search in sources :

Example 31 with StubStepDefinition

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

the class StepExpressionFactoryTest method unknown_target_type_does_no_transform_data_table.

@Test
void unknown_target_type_does_no_transform_data_table() {
    StepDefinition stepDefinition = new StubStepDefinition("Given some stuff:", UNKNOWN_TYPE);
    StepExpression expression = stepExpressionFactory.createExpression(stepDefinition);
    List<Argument> match = expression.match("Given some stuff:", table);
    assertThat(match.get(0).getValue(), is(equalTo(DataTable.create(table))));
}
Also used : StubStepDefinition(io.cucumber.core.backend.StubStepDefinition) StepDefinition(io.cucumber.core.backend.StepDefinition) StubStepDefinition(io.cucumber.core.backend.StubStepDefinition) Test(org.junit.jupiter.api.Test)

Example 32 with StubStepDefinition

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

the class StepExpressionFactoryTest method throws_for_unknown_parameter_types.

@Test
void throws_for_unknown_parameter_types() {
    StepDefinition stepDefinition = new StubStepDefinition("Given a {unknownParameterType}");
    List<Envelope> events = new ArrayList<>();
    bus.registerHandlerFor(Envelope.class, events::add);
    CucumberException exception = assertThrows(CucumberException.class, () -> stepExpressionFactory.createExpression(stepDefinition));
    assertThat(exception.getMessage(), is("" + "Could not create a cucumber expression for 'Given a {unknownParameterType}'.\n" + "It appears you did not register a parameter type."));
    assertThat(events, iterableWithSize(1));
    assertNotNull(events.get(0).getUndefinedParameterType());
}
Also used : ArrayList(java.util.ArrayList) StubStepDefinition(io.cucumber.core.backend.StubStepDefinition) StepDefinition(io.cucumber.core.backend.StepDefinition) StubStepDefinition(io.cucumber.core.backend.StubStepDefinition) CucumberException(io.cucumber.core.exception.CucumberException) Envelope(io.cucumber.messages.types.Envelope) Test(org.junit.jupiter.api.Test)

Example 33 with StubStepDefinition

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

the class StepExpressionFactoryTest method table_expression_with_type_creates_single_ingredients_from_table.

@Test
void table_expression_with_type_creates_single_ingredients_from_table() {
    registry.defineDataTableType(new DataTableType(Ingredient.class, beanMapper(registry)));
    StepDefinition stepDefinition = new StubStepDefinition("Given some stuff:", Ingredient.class);
    StepExpression expression = stepExpressionFactory.createExpression(stepDefinition);
    List<Argument> match = expression.match("Given some stuff:", tableTransposed);
    Ingredient ingredient = (Ingredient) match.get(0).getValue();
    assertThat(ingredient.name, is(equalTo("chocolate")));
}
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) Test(org.junit.jupiter.api.Test)

Example 34 with StubStepDefinition

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

the class JsonFormatterTest method should_format_scenario_with_a_rule.

@Test
void should_format_scenario_with_a_rule() {
    Feature feature = TestFeatureParser.parse("path/test.feature", "" + "Feature: Banana party\n" + "\n" + "  Rule: This is all monkey business\n" + "    Scenario: Monkey eats bananas\n" + "      Given there are bananas\n");
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    StepDurationTimeService timeService = new StepDurationTimeService(ofMillis(1));
    Runtime.builder().withFeatureSupplier(new StubFeatureSupplier(feature)).withAdditionalPlugins(timeService, new JsonFormatter(out)).withEventBus(new TimeServiceEventBus(timeService, UUID::randomUUID)).withBackendSupplier(new StubBackendSupplier(new StubStepDefinition("there are bananas", "StepDefs.there_are_bananas()"))).build().run();
    String expected = "" + "[\n" + "  {\n" + "    \"line\": 1,\n" + "    \"elements\": [\n" + "      {\n" + "        \"start_timestamp\": \"1970-01-01T00:00:00.000Z\",\n" + "        \"line\": 4,\n" + "        \"name\": \"Monkey eats bananas\",\n" + "        \"description\": \"\",\n" + "        \"id\": \";monkey-eats-bananas\",\n" + "        \"type\": \"scenario\",\n" + "        \"keyword\": \"Scenario\",\n" + "        \"steps\": [\n" + "          {\n" + "            \"result\": {\n" + "              \"duration\": 1000000,\n" + "              \"status\": \"passed\"\n" + "            },\n" + "            \"line\": 5,\n" + "            \"name\": \"there are bananas\",\n" + "            \"match\": {\n" + "              \"location\": \"StepDefs.there_are_bananas()\"\n" + "            },\n" + "            \"keyword\": \"Given \"\n" + "          }\n" + "        ]\n" + "      }\n" + "    ],\n" + "    \"name\": \"Banana party\",\n" + "    \"description\": \"\",\n" + "    \"id\": \"banana-party\",\n" + "    \"keyword\": \"Feature\",\n" + "    \"uri\": \"file:path/test.feature\",\n" + "    \"tags\": []\n" + "  }\n" + "]";
    assertJsonEquals(expected, out);
}
Also used : TimeServiceEventBus(io.cucumber.core.runtime.TimeServiceEventBus) StubBackendSupplier(io.cucumber.core.runtime.StubBackendSupplier) StubFeatureSupplier(io.cucumber.core.runtime.StubFeatureSupplier) StubStepDefinition(io.cucumber.core.backend.StubStepDefinition) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DocString(io.cucumber.docstring.DocString) UUID(java.util.UUID) Feature(io.cucumber.core.gherkin.Feature) StepDurationTimeService(io.cucumber.core.runner.StepDurationTimeService) Test(org.junit.jupiter.api.Test)

Example 35 with StubStepDefinition

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

the class JsonFormatterTest method should_handle_write_from_a_hook.

@Test
void should_handle_write_from_a_hook() {
    Feature feature = TestFeatureParser.parse("path/test.feature", "" + "Feature: Banana party\n" + "\n" + "  Scenario: Monkey eats bananas\n" + "    Given there are bananas\n");
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    StepDurationTimeService timeService = new StepDurationTimeService(ofMillis(1));
    Runtime.builder().withFeatureSupplier(new StubFeatureSupplier(feature)).withAdditionalPlugins(timeService, new JsonFormatter(out)).withEventBus(new TimeServiceEventBus(timeService, UUID::randomUUID)).withBackendSupplier(new StubBackendSupplier(singletonList(new StubHookDefinition("Hooks.before_hook_1()", testCaseState -> testCaseState.log("printed from hook"))), singletonList(new StubStepDefinition("there are bananas", "StepDefs.there_are_bananas()")), emptyList())).build().run();
    String expected = "" + "[\n" + "  {\n" + "    \"id\": \"banana-party\",\n" + "    \"uri\": \"file:path/test.feature\",\n" + "    \"keyword\": \"Feature\",\n" + "    \"name\": \"Banana party\",\n" + "    \"line\": 1,\n" + "    \"description\": \"\",\n" + "    \"elements\": [\n" + "      {\n" + "        \"id\": \"banana-party;monkey-eats-bananas\",\n" + "        \"keyword\": \"Scenario\",\n" + "        \"start_timestamp\": \"1970-01-01T00:00:00.000Z\",\n" + "        \"name\": \"Monkey eats bananas\",\n" + "        \"line\": 3,\n" + "        \"description\": \"\",\n" + "        \"type\": \"scenario\",\n" + "        \"before\": [\n" + "          {\n" + "            \"match\": {\n" + "              \"location\": \"Hooks.before_hook_1()\"\n" + "            },\n" + "            \"output\": [\n" + "              \"printed from hook\"\n" + "            ],\n" + "            \"result\": {\n" + "              \"status\": \"passed\",\n" + "              \"duration\": 1000000\n" + "            }\n" + "          }\n" + "        ],\n" + "        \"steps\": [\n" + "          {\n" + "            \"keyword\": \"Given \",\n" + "            \"name\": \"there are bananas\",\n" + "            \"line\": 4,\n" + "            \"match\": {\n" + "              \"location\": \"StepDefs.there_are_bananas()\"\n" + "            },\n" + "            \"result\": {\n" + "              \"status\": \"passed\",\n" + "              \"duration\": 1000000\n" + "            }\n" + "          }\n" + "        ]\n" + "      }\n" + "    ],\n" + "    \"tags\": []\n" + "  }\n" + "]";
    assertJsonEquals(expected, out);
}
Also used : TimeServiceEventBus(io.cucumber.core.runtime.TimeServiceEventBus) StubBackendSupplier(io.cucumber.core.runtime.StubBackendSupplier) Builder(io.cucumber.core.runtime.Runtime.Builder) ZoneId.of(java.time.ZoneId.of) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Runtime(io.cucumber.core.runtime.Runtime) StubStepDefinition(io.cucumber.core.backend.StubStepDefinition) DocString(io.cucumber.docstring.DocString) Scanner(java.util.Scanner) Collections.singletonList(java.util.Collections.singletonList) Arrays.asList(java.util.Arrays.asList) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) DataTable(io.cucumber.datatable.DataTable) StubHookDefinition(io.cucumber.core.backend.StubHookDefinition) Clock.fixed(java.time.Clock.fixed) TestFeatureParser(io.cucumber.core.feature.TestFeatureParser) StubFeatureSupplier(io.cucumber.core.runtime.StubFeatureSupplier) StepDurationTimeService(io.cucumber.core.runner.StepDurationTimeService) UTF_8(java.nio.charset.StandardCharsets.UTF_8) Collections.emptyList(java.util.Collections.emptyList) TimeServiceEventBus(io.cucumber.core.runtime.TimeServiceEventBus) UUID(java.util.UUID) Test(org.junit.jupiter.api.Test) RuntimeOptionsBuilder(io.cucumber.core.options.RuntimeOptionsBuilder) Feature(io.cucumber.core.gherkin.Feature) StubBackendSupplier(io.cucumber.core.runtime.StubBackendSupplier) SameJSONAs.sameJSONAs(uk.co.datumedge.hamcrest.json.SameJSONAs.sameJSONAs) EPOCH(java.time.Instant.EPOCH) Duration.ofMillis(java.time.Duration.ofMillis) InputStream(java.io.InputStream) StubFeatureSupplier(io.cucumber.core.runtime.StubFeatureSupplier) StubHookDefinition(io.cucumber.core.backend.StubHookDefinition) StubStepDefinition(io.cucumber.core.backend.StubStepDefinition) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DocString(io.cucumber.docstring.DocString) UUID(java.util.UUID) Feature(io.cucumber.core.gherkin.Feature) StepDurationTimeService(io.cucumber.core.runner.StepDurationTimeService) 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