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"));
}
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));
}
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));
}
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());
}
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)));
}
Aggregations