Search in sources :

Example 76 with StubStepDefinition

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

the class StepDefinitionMatchTest method rethrows_target_invocation_exceptions_from_parameter_type.

@Test
void rethrows_target_invocation_exceptions_from_parameter_type() {
    RuntimeException userException = new RuntimeException();
    stepTypeRegistry.defineParameterType(new ParameterType<>("itemQuantity", "(few|some|lots of) (cukes|gherkins)", ItemQuantity.class, (String[] s) -> {
        throw new CucumberInvocationTargetException(stubbedLocation, new InvocationTargetException(userException));
    }));
    Feature feature = TestFeatureParser.parse("" + "Feature: Test feature\n" + "  Scenario: Test scenario\n" + "     Given I have some cukes in my belly\n");
    Step step = feature.getPickles().get(0).getSteps().get(0);
    StepDefinition stepDefinition = new StubStepDefinition("I have {itemQuantity} in my belly", ItemQuantity.class);
    StepExpression expression = stepExpressionFactory.createExpression(stepDefinition);
    CoreStepDefinition coreStepDefinition = new CoreStepDefinition(id, stepDefinition, expression);
    List<Argument> arguments = coreStepDefinition.matchedArguments(step);
    StepDefinitionMatch stepDefinitionMatch = new PickleStepDefinitionMatch(arguments, stepDefinition, null, step);
    Executable testMethod = () -> stepDefinitionMatch.runStep(null);
    RuntimeException actualThrown = assertThrows(RuntimeException.class, testMethod);
    assertThat(actualThrown, sameInstance(userException));
}
Also used : Argument(io.cucumber.core.stepexpression.Argument) Step(io.cucumber.core.gherkin.Step) Feature(io.cucumber.core.gherkin.Feature) CucumberInvocationTargetException(io.cucumber.core.backend.CucumberInvocationTargetException) InvocationTargetException(java.lang.reflect.InvocationTargetException) CucumberInvocationTargetException(io.cucumber.core.backend.CucumberInvocationTargetException) StubStepDefinition(io.cucumber.core.backend.StubStepDefinition) StepDefinition(io.cucumber.core.backend.StepDefinition) StubStepDefinition(io.cucumber.core.backend.StubStepDefinition) Executable(org.junit.jupiter.api.function.Executable) StepExpression(io.cucumber.core.stepexpression.StepExpression) Test(org.junit.jupiter.api.Test)

Example 77 with StubStepDefinition

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

the class StepExpressionFactoryTest method unknown_target_type_transform_doc_string_to_doc_string.

@Test
void unknown_target_type_transform_doc_string_to_doc_string() {
    String docString = "A rather long and boring string of documentation";
    StepDefinition stepDefinition = new StubStepDefinition("Given some stuff:", UNKNOWN_TYPE);
    StepExpression expression = stepExpressionFactory.createExpression(stepDefinition);
    List<Argument> match = expression.match("Given some stuff:", docString, null);
    assertThat(match.get(0).getValue(), is(equalTo(DocString.create(docString))));
}
Also used : StubStepDefinition(io.cucumber.core.backend.StubStepDefinition) StepDefinition(io.cucumber.core.backend.StepDefinition) StubStepDefinition(io.cucumber.core.backend.StubStepDefinition) DocString(io.cucumber.docstring.DocString) Test(org.junit.jupiter.api.Test)

Example 78 with StubStepDefinition

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

the class StepExpressionFactoryTest method docstring_and_datatable_match_same_step_definition.

@Test
void docstring_and_datatable_match_same_step_definition() {
    String docString = "A rather long and boring string of documentation";
    StepDefinition stepDefinition = new StubStepDefinition("Given some stuff:", UNKNOWN_TYPE);
    StepExpression expression = stepExpressionFactory.createExpression(stepDefinition);
    List<Argument> match = expression.match("Given some stuff:", docString, null);
    assertThat(match.get(0).getValue(), is(equalTo(DocString.create(docString))));
    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) DocString(io.cucumber.docstring.DocString) Test(org.junit.jupiter.api.Test)

Example 79 with StubStepDefinition

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

the class PrettyFormatterTest method should_mark_nested_arguments_as_part_of_enclosing_argument.

@Test
void should_mark_nested_arguments_as_part_of_enclosing_argument() {
    Formats formats = ansi();
    PrettyFormatter prettyFormatter = new PrettyFormatter(new ByteArrayOutputStream());
    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);
    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 80 with StubStepDefinition

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

the class PrettyFormatterTest method should_skip_missing_location_strings.

@Test
void should_skip_missing_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", (String) null), 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\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