use of gherkin.formatter.model.Step in project cucumber-jvm by cucumber.
the class CucumberScenarioOutline method createExampleScenario.
CucumberScenario createExampleScenario(ExamplesTableRow header, ExamplesTableRow example, List<Tag> examplesTags, String examplesDescription) {
// Make sure we replace the tokens in the name of the scenario
String exampleScenarioName = replaceTokens(new HashSet<Integer>(), header.getCells(), example.getCells(), getGherkinModel().getName());
String exampleScenarioDescription = createExampleScenarioDescription(getGherkinModel().getDescription(), examplesDescription);
Scenario exampleScenario = new Scenario(example.getComments(), examplesTags, getGherkinModel().getKeyword(), exampleScenarioName, exampleScenarioDescription, example.getLine(), example.getId());
CucumberScenario cucumberScenario = new CucumberScenario(cucumberFeature, cucumberBackground, exampleScenario, example);
for (Step step : getSteps()) {
cucumberScenario.step(createExampleStep(step, header, example));
}
return cucumberScenario;
}
use of gherkin.formatter.model.Step in project cucumber-jvm by cucumber.
the class ClojureSnippetTest method generatesSnippetWithDataTable.
@Test
public void generatesSnippetWithDataTable() throws Exception {
List<DataTableRow> dataTable = asList(new DataTableRow(NO_COMMENTS, asList("col1"), 1));
Step step = new Step(NO_COMMENTS, "Given ", "I have:", 0, dataTable, null);
String snippet = (newBackend()).getSnippet(step, null);
String expected = "" + "(Given #\"^I have:$\" [arg1]\n" + " (comment Write code here that turns the phrase above into concrete actions )\n" + " (throw (cucumber.api.PendingException.)))\n";
assertEquals(expected, snippet);
}
use of gherkin.formatter.model.Step in project cucumber-jvm by cucumber.
the class StepdefGenerator method generate.
public List<MetaStepdef> generate(Collection<StepDefinition> stepDefinitions, List<CucumberFeature> features) {
List<MetaStepdef> result = new ArrayList<MetaStepdef>();
List<StepDefinition> sortedStepdefs = new ArrayList<StepDefinition>();
sortedStepdefs.addAll(stepDefinitions);
Collections.sort(sortedStepdefs, STEP_DEFINITION_COMPARATOR);
for (StepDefinition stepDefinition : sortedStepdefs) {
MetaStepdef metaStepdef = new MetaStepdef();
metaStepdef.source = stepDefinition.getPattern();
// TODO = get the flags too
metaStepdef.flags = "";
for (CucumberFeature feature : features) {
List<CucumberTagStatement> cucumberTagStatements = feature.getFeatureElements();
for (CucumberTagStatement tagStatement : cucumberTagStatements) {
List<Step> steps = tagStatement.getSteps();
for (Step step : steps) {
List<Argument> arguments = stepDefinition.matchedArguments(step);
if (arguments != null) {
MetaStepdef.MetaStep ms = new MetaStepdef.MetaStep();
ms.name = step.getName();
for (Argument argument : arguments) {
MetaStepdef.MetaArgument ma = new MetaStepdef.MetaArgument();
ma.offset = argument.getOffset();
ma.val = argument.getVal();
ms.args.add(ma);
}
metaStepdef.steps.add(ms);
}
}
}
Collections.sort(cucumberTagStatements, CUCUMBER_TAG_STATEMENT_COMPARATOR);
}
result.add(metaStepdef);
}
return result;
}
use of gherkin.formatter.model.Step in project cucumber-jvm by cucumber.
the class CucumberExamplesTest method should_create_example_scenarios.
@Test
public void should_create_example_scenarios() {
CucumberFeature cucumberFeature = new CucumberFeature(new Feature(COMMENTS, FEATURE_TAGS, "Feature", "", "", 2, "fid"), "f.feature");
ScenarioOutline so = new ScenarioOutline(COMMENTS, SO_TAGS, "Scenario Outline", "", "", 4, "");
CucumberScenarioOutline cso = new CucumberScenarioOutline(cucumberFeature, null, so);
cso.step(new Step(COMMENTS, "Given ", "I have 5 <what> in my <where>", 5, null, null));
Examples examples = new Examples(COMMENTS, E_TAGS, "Examples", "", "", 6, "", asList(new ExamplesTableRow(COMMENTS, asList("what", "where"), 7, ""), new ExamplesTableRow(COMMENTS, asList("cukes", "belly"), 8, ""), new ExamplesTableRow(COMMENTS, asList("apples", "basket"), 9, "")));
CucumberExamples cucumberExamples = new CucumberExamples(cso, examples);
List<CucumberScenario> exampleScenarios = cucumberExamples.createExampleScenarios();
assertEquals(2, exampleScenarios.size());
Set<Tag> expectedTags = new HashSet<Tag>();
expectedTags.addAll(FEATURE_TAGS);
expectedTags.addAll(SO_TAGS);
expectedTags.addAll(E_TAGS);
assertEquals(expectedTags, exampleScenarios.get(0).tagsAndInheritedTags());
CucumberScenario cucumberScenario = exampleScenarios.get(0);
Step step = cucumberScenario.getSteps().get(0);
assertEquals("I have 5 cukes in my belly", step.getName());
}
use of gherkin.formatter.model.Step in project cucumber-jvm by cucumber.
the class StepDefinitionMatchTest method throws_arity_mismatch_exception_when_there_are_fewer_parameters_than_arguments.
@Test
public void throws_arity_mismatch_exception_when_there_are_fewer_parameters_than_arguments() throws Throwable {
Step step = new Step(null, "Given ", "I have 4 cukes in my belly", 1, null, null);
StepDefinition stepDefinition = new StubStepDefinition(new Object(), Object.class.getMethod("toString"), "some pattern");
StepDefinitionMatch stepDefinitionMatch = new StepDefinitionMatch(asList(new Argument(7, "4")), stepDefinition, null, step, new LocalizedXStreams(getClass().getClassLoader()));
try {
stepDefinitionMatch.runStep(new I18n("en"));
fail();
} catch (CucumberException expected) {
assertEquals("Arity mismatch: Step Definition 'toString' with pattern [some pattern] is declared with 0 parameters. However, the gherkin step has 1 arguments [4]. \n" + "Step: Given I have 4 cukes in my belly", expected.getMessage());
}
}
Aggregations