use of io.cucumber.core.backend.StepDefinition in project cucumber-jvm by cucumber.
the class StepDefinitionMatchTest method throws_arity_mismatch_exception_when_there_are_fewer_parameters_than_arguments_with_data_table.
@Test
void throws_arity_mismatch_exception_when_there_are_fewer_parameters_than_arguments_with_data_table() {
Feature feature = TestFeatureParser.parse("" + "Feature: Test feature\n" + " Scenario: Test scenario\n" + " Given I have 4 cukes in my belly\n" + " | A | B | \n" + " | C | D | \n");
Step step = feature.getPickles().get(0).getSteps().get(0);
StepDefinition stepDefinition = new StubStepDefinition("I have {int} cukes in my belly");
StepExpression expression = stepExpressionFactory.createExpression(stepDefinition);
CoreStepDefinition coreStepDefinition = new CoreStepDefinition(id, stepDefinition, expression);
List<Argument> arguments = coreStepDefinition.matchedArguments(step);
PickleStepDefinitionMatch stepDefinitionMatch = new PickleStepDefinitionMatch(arguments, stepDefinition, null, step);
Executable testMethod = () -> stepDefinitionMatch.runStep(null);
CucumberException actualThrown = assertThrows(CucumberException.class, testMethod);
assertThat("Unexpected exception message", actualThrown.getMessage(), is(equalTo("Step [I have {int} cukes in my belly] is defined with 0 parameters at '{stubbed location with details}'.\n" + "However, the gherkin step has 2 arguments:\n" + " * 4\n" + " * Table:\n" + " | A | B |\n" + " | C | D |\n" + "\n" + "Step text: I have 4 cukes in my belly")));
}
use of io.cucumber.core.backend.StepDefinition in project cucumber-jvm by cucumber.
the class StepDefinitionMatchTest method throws_could_not_convert_exception_for_transformer_and_capture_group_mismatch.
@Test
void throws_could_not_convert_exception_for_transformer_and_capture_group_mismatch() {
stepTypeRegistry.defineParameterType(new ParameterType<>("itemQuantity", "(few|some|lots of) (cukes|gherkins)", ItemQuantity.class, // Wrong number of capture groups
(String s) -> null));
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);
CucumberException actualThrown = assertThrows(CucumberException.class, testMethod);
assertThat("Unexpected exception message", actualThrown.getMessage(), is(equalTo("Could not convert arguments for step [I have {itemQuantity} in my belly] defined at '{stubbed location with details}'.")));
}
use of io.cucumber.core.backend.StepDefinition 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));
}
use of io.cucumber.core.backend.StepDefinition in project cucumber-jvm by cucumber.
the class CoreStepDefinitionTest method should_apply_identity_transform_to_doc_string_when_target_type_is_object.
@Test
void should_apply_identity_transform_to_doc_string_when_target_type_is_object() {
Feature feature = TestFeatureParser.parse("" + "Feature: Test feature\n" + " Scenario: Test scenario\n" + " Given I have some step\n" + " \"\"\"\n" + " content\n" + " \"\"\"\n");
StepDefinition stepDefinition = new StubStepDefinition("I have some step", Object.class);
StepExpression expression = stepExpressionFactory.createExpression(stepDefinition);
CoreStepDefinition coreStepDefinition = new CoreStepDefinition(id, stepDefinition, expression);
Step step = feature.getPickles().get(0).getSteps().get(0);
List<Argument> arguments = coreStepDefinition.matchedArguments(step);
assertThat(arguments.get(0).getValue(), is(equalTo(DocString.create("content"))));
}
use of io.cucumber.core.backend.StepDefinition 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))));
}
Aggregations