use of io.cucumber.core.backend.StepDefinition in project cucumber-jvm by cucumber.
the class StepDefinitionMatchTest method throws_arity_mismatch_exception_when_there_are_more_parameters_than_arguments.
@Test
void throws_arity_mismatch_exception_when_there_are_more_parameters_than_arguments() {
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", Integer.TYPE, Short.TYPE, List.class);
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 3 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 StepExpressionFactoryTest method creates_a_step_expression.
@Test
void creates_a_step_expression() {
StepDefinition stepDefinition = new StubStepDefinition("Given a step");
StepExpression expression = stepExpressionFactory.createExpression(stepDefinition);
assertThat(expression.getSource(), is("Given a step"));
assertThat(expression.getExpressionType(), is(CucumberExpression.class));
assertThat(expression.match("Given a step"), is(emptyList()));
}
use of io.cucumber.core.backend.StepDefinition in project cucumber-jvm by cucumber.
the class StepExpressionFactoryTest method empty_table_cells_are_presented_as_null_to_transformer.
@SuppressWarnings("unchecked")
@Test
void empty_table_cells_are_presented_as_null_to_transformer() {
registry.setDefaultDataTableEntryTransformer((map, valueType, tableCellByTypeTransformer) -> objectMapper.convertValue(map, objectMapper.constructType(valueType)));
StepDefinition stepDefinition = new StubStepDefinition("Given some stuff:", getTypeFromStepDefinition());
StepExpression expression = stepExpressionFactory.createExpression(stepDefinition);
List<List<String>> table = asList(asList("name", "amount", "unit"), asList("chocolate", null, "tbsp"));
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.name, is(equalTo("chocolate")));
}
use of io.cucumber.core.backend.StepDefinition in project cucumber-jvm by cucumber.
the class CachingGlueTest method throws_duplicate_error_on_dupe_stepdefs.
@Test
void throws_duplicate_error_on_dupe_stepdefs() {
StepDefinition a = mock(StepDefinition.class);
when(a.getPattern()).thenReturn("hello");
when(a.getLocation()).thenReturn("foo.bf:10");
glue.addStepDefinition(a);
StepDefinition b = mock(StepDefinition.class);
when(b.getPattern()).thenReturn("hello");
when(b.getLocation()).thenReturn("bar.bf:90");
glue.addStepDefinition(b);
DuplicateStepDefinitionException exception = assertThrows(DuplicateStepDefinitionException.class, () -> glue.prepareGlue(stepTypeRegistry));
assertThat(exception.getMessage(), equalTo("Duplicate step definitions in foo.bf:10 and bar.bf:90"));
}
use of io.cucumber.core.backend.StepDefinition in project cucumber-jvm by cucumber.
the class CachingGlueTest method returns_match_from_cache_if_single_found.
@Test
void returns_match_from_cache_if_single_found() throws AmbiguousStepDefinitionsException {
StepDefinition stepDefinition1 = new MockedStepDefinition("^pattern1");
StepDefinition stepDefinition2 = new MockedStepDefinition("^pattern2");
glue.addStepDefinition(stepDefinition1);
glue.addStepDefinition(stepDefinition2);
glue.prepareGlue(stepTypeRegistry);
URI uri = URI.create("file:path/to.feature");
String stepText = "pattern1";
Step pickleStep1 = getPickleStep(stepText);
PickleStepDefinitionMatch pickleStepDefinitionMatch = glue.stepDefinitionMatch(uri, pickleStep1);
assertThat(((CoreStepDefinition) pickleStepDefinitionMatch.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)));
Step pickleStep2 = getPickleStep(stepText);
PickleStepDefinitionMatch pickleStepDefinitionMatch2 = glue.stepDefinitionMatch(uri, pickleStep2);
assertThat(((CoreStepDefinition) pickleStepDefinitionMatch2.getStepDefinition()).getStepDefinition(), is(equalTo(stepDefinition1)));
}
Aggregations