use of io.cucumber.core.gherkin.Step 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.gherkin.Step 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)));
}
use of io.cucumber.core.gherkin.Step 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")));
}
use of io.cucumber.core.gherkin.Step 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());
}
use of io.cucumber.core.gherkin.Step in project cucumber-jvm by cucumber.
the class AmbiguousStepDefinitionsExceptionTest method can_report_ambiguous_step_definitions.
@Test
void can_report_ambiguous_step_definitions() {
Feature feature = TestFeatureParser.parse("" + "Feature: Test feature\n" + " Scenario: Test scenario\n" + " Given I have 4 cukes in my belly\n");
Step mockPickleStep = feature.getPickles().get(0).getSteps().get(0);
PickleStepDefinitionMatch mockPickleStepDefinitionMatchOne = mock(PickleStepDefinitionMatch.class);
when(mockPickleStepDefinitionMatchOne.getPattern()).thenReturn("PickleStepDefinitionMatchOne_Pattern");
when(mockPickleStepDefinitionMatchOne.getLocation()).thenReturn("PickleStepDefinitionMatchOne_Location");
PickleStepDefinitionMatch mockPickleStepDefinitionMatchTwo = mock(PickleStepDefinitionMatch.class);
when(mockPickleStepDefinitionMatchTwo.getPattern()).thenReturn("PickleStepDefinitionMatchTwo_Pattern");
when(mockPickleStepDefinitionMatchTwo.getLocation()).thenReturn("PickleStepDefinitionMatchTwo_Location");
List<PickleStepDefinitionMatch> matches = asList(mockPickleStepDefinitionMatchOne, mockPickleStepDefinitionMatchTwo);
AmbiguousStepDefinitionsException expectedThrown = new AmbiguousStepDefinitionsException(mockPickleStep, matches);
assertAll(() -> assertThat(expectedThrown.getMessage(), is(equalTo("" + "\"I have 4 cukes in my belly\" matches more than one step definition:\n" + " \"PickleStepDefinitionMatchOne_Pattern\" in PickleStepDefinitionMatchOne_Location\n" + " \"PickleStepDefinitionMatchTwo_Pattern\" in PickleStepDefinitionMatchTwo_Location"))), () -> assertThat(expectedThrown.getCause(), is(nullValue())), () -> assertThat(expectedThrown.getMatches(), is(equalTo(matches))));
}
Aggregations