Search in sources :

Example 1 with Step

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;
}
Also used : DocString(gherkin.formatter.model.DocString) Step(gherkin.formatter.model.Step) Scenario(gherkin.formatter.model.Scenario)

Example 2 with Step

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);
}
Also used : Step(gherkin.formatter.model.Step) DataTableRow(gherkin.formatter.model.DataTableRow) Test(org.junit.Test)

Example 3 with Step

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;
}
Also used : Argument(gherkin.formatter.Argument) ArrayList(java.util.ArrayList) Step(gherkin.formatter.model.Step) CucumberFeature(cucumber.runtime.model.CucumberFeature) StepDefinition(cucumber.runtime.StepDefinition) CucumberTagStatement(cucumber.runtime.model.CucumberTagStatement)

Example 4 with Step

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());
}
Also used : Step(gherkin.formatter.model.Step) Feature(gherkin.formatter.model.Feature) ExamplesTableRow(gherkin.formatter.model.ExamplesTableRow) ScenarioOutline(gherkin.formatter.model.ScenarioOutline) Tag(gherkin.formatter.model.Tag) Examples(gherkin.formatter.model.Examples) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 5 with Step

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());
    }
}
Also used : Argument(gherkin.formatter.Argument) Step(gherkin.formatter.model.Step) LocalizedXStreams(cucumber.runtime.xstream.LocalizedXStreams) I18n(gherkin.I18n) Test(org.junit.Test)

Aggregations

Step (gherkin.formatter.model.Step)50 Test (org.junit.Test)34 LocalizedXStreams (cucumber.runtime.xstream.LocalizedXStreams)9 Argument (gherkin.formatter.Argument)9 ExamplesTableRow (gherkin.formatter.model.ExamplesTableRow)7 Scenario (gherkin.formatter.model.Scenario)7 DocString (gherkin.formatter.model.DocString)6 Description (org.junit.runner.Description)6 I18n (gherkin.I18n)5 CucumberFeature (cucumber.runtime.model.CucumberFeature)4 DataTableRow (gherkin.formatter.model.DataTableRow)4 Match (gherkin.formatter.model.Match)4 CucumberException (cucumber.runtime.CucumberException)3 SnippetGenerator (cucumber.runtime.snippets.SnippetGenerator)3 Tag (gherkin.formatter.model.Tag)3 GherkinStep (org.jetbrains.plugins.cucumber.psi.GherkinStep)3 RunNotifier (org.junit.runner.notification.RunNotifier)3 Given (cucumber.api.java.en.Given)2 StepDefinition (cucumber.runtime.StepDefinition)2 StepDefinitionMatch (cucumber.runtime.StepDefinitionMatch)2