Search in sources :

Example 11 with StepDefinition

use of io.cucumber.core.backend.StepDefinition 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 12 with StepDefinition

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

the class CachingGlueTest method returns_match_from_cache_for_ste_with_doc_string.

@Test
void returns_match_from_cache_for_ste_with_doc_string() throws AmbiguousStepDefinitionsException {
    StepDefinition stepDefinition1 = new MockedStepDefinition("^pattern1", String.class);
    StepDefinition stepDefinition2 = new MockedStepDefinition("^pattern2", String.class);
    glue.addStepDefinition(stepDefinition1);
    glue.addStepDefinition(stepDefinition2);
    glue.prepareGlue(stepTypeRegistry);
    URI uri = URI.create("file:path/to.feature");
    String stepText = "pattern1";
    Step pickleStep1 = getPickleStepWithDocString(stepText, "doc string 1");
    PickleStepDefinitionMatch match1 = glue.stepDefinitionMatch(uri, pickleStep1);
    assertThat(((CoreStepDefinition) match1.getStepDefinition()).getStepDefinition(), is(equalTo(stepDefinition1)));
    // check cache
    assertThat(glue.getStepPatternByStepText().get(stepText), is(equalTo(stepDefinition1.getPattern())));
    CoreStepDefinition coreStepDefinition = glue.getStepDefinitionsByPattern().get(stepDefinition1.getPattern());
    assertThat(coreStepDefinition.getStepDefinition(), is(equalTo(stepDefinition1)));
    // check arguments
    assertThat(match1.getArguments().get(0).getValue(), is(equalTo("doc string 1")));
    // check second match
    Step pickleStep2 = getPickleStepWithDocString(stepText, "doc string 2");
    PickleStepDefinitionMatch match2 = glue.stepDefinitionMatch(uri, pickleStep2);
    // check arguments
    assertThat(match2.getArguments().get(0).getValue(), is(equalTo("doc string 2")));
}
Also used : StepDefinition(io.cucumber.core.backend.StepDefinition) Step(io.cucumber.core.gherkin.Step) URI(java.net.URI) Test(org.junit.jupiter.api.Test)

Example 13 with StepDefinition

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

the class CachingGlueTest method returns_no_match_after_evicting_scenario_scoped.

@Test
void returns_no_match_after_evicting_scenario_scoped() throws AmbiguousStepDefinitionsException {
    URI uri = URI.create("file:path/to.feature");
    String stepText = "pattern1";
    Step pickleStep1 = getPickleStep(stepText);
    StepDefinition stepDefinition1 = new MockedScenarioScopedStepDefinition("^pattern1");
    glue.addStepDefinition(stepDefinition1);
    glue.prepareGlue(stepTypeRegistry);
    PickleStepDefinitionMatch pickleStepDefinitionMatch = glue.stepDefinitionMatch(uri, pickleStep1);
    assertThat(((CoreStepDefinition) pickleStepDefinitionMatch.getStepDefinition()).getStepDefinition(), is(equalTo(stepDefinition1)));
    glue.removeScenarioScopedGlue();
    glue.prepareGlue(stepTypeRegistry);
    PickleStepDefinitionMatch pickleStepDefinitionMatch2 = glue.stepDefinitionMatch(uri, pickleStep1);
    assertThat(pickleStepDefinitionMatch2, nullValue());
}
Also used : StepDefinition(io.cucumber.core.backend.StepDefinition) Step(io.cucumber.core.gherkin.Step) URI(java.net.URI) Test(org.junit.jupiter.api.Test)

Example 14 with StepDefinition

use of io.cucumber.core.backend.StepDefinition 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 15 with StepDefinition

use of io.cucumber.core.backend.StepDefinition 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

StepDefinition (io.cucumber.core.backend.StepDefinition)43 Test (org.junit.jupiter.api.Test)42 StubStepDefinition (io.cucumber.core.backend.StubStepDefinition)29 Step (io.cucumber.core.gherkin.Step)22 Feature (io.cucumber.core.gherkin.Feature)18 Argument (io.cucumber.core.stepexpression.Argument)18 StepExpression (io.cucumber.core.stepexpression.StepExpression)18 Executable (org.junit.jupiter.api.function.Executable)14 CucumberException (io.cucumber.core.exception.CucumberException)13 URI (java.net.URI)9 DataTableType (io.cucumber.datatable.DataTableType)6 CucumberBackendException (io.cucumber.core.backend.CucumberBackendException)5 CucumberInvocationTargetException (io.cucumber.core.backend.CucumberInvocationTargetException)5 StepExpressionFactory (io.cucumber.core.stepexpression.StepExpressionFactory)5 StepTypeRegistry (io.cucumber.core.stepexpression.StepTypeRegistry)5 DocString (io.cucumber.docstring.DocString)4 InvocationTargetException (java.lang.reflect.InvocationTargetException)4 Arrays.asList (java.util.Arrays.asList)4 List (java.util.List)4 BytesContainsString.bytesContainsString (io.cucumber.core.plugin.BytesContainsString.bytesContainsString)3