Search in sources :

Example 1 with StepDefinition

use of cucumber.runtime.StepDefinition 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 2 with StepDefinition

use of cucumber.runtime.StepDefinition in project cucumber-jvm by cucumber.

the class FromDataTableTest method runStepDef.

private StepDefs runStepDef(Method method, List<DataTableRow> rows) throws Throwable {
    StepDefs stepDefs = new StepDefs();
    StepDefinition stepDefinition = new StubStepDefinition(stepDefs, method, "some pattern");
    Step stepWithRows = new Step(NO_COMMENTS, "Given ", "something", 10, rows, null);
    ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
    StepDefinitionMatch stepDefinitionMatch = new StepDefinitionMatch(NO_ARGS, stepDefinition, "some.feature", stepWithRows, new LocalizedXStreams(classLoader));
    stepDefinitionMatch.runStep(new I18n("en"));
    return stepDefs;
}
Also used : StubStepDefinition(cucumber.runtime.StubStepDefinition) StepDefinition(cucumber.runtime.StepDefinition) StubStepDefinition(cucumber.runtime.StubStepDefinition) Step(gherkin.formatter.model.Step) StepDefinitionMatch(cucumber.runtime.StepDefinitionMatch) LocalizedXStreams(cucumber.runtime.xstream.LocalizedXStreams) I18n(gherkin.I18n)

Aggregations

StepDefinition (cucumber.runtime.StepDefinition)2 Step (gherkin.formatter.model.Step)2 StepDefinitionMatch (cucumber.runtime.StepDefinitionMatch)1 StubStepDefinition (cucumber.runtime.StubStepDefinition)1 CucumberFeature (cucumber.runtime.model.CucumberFeature)1 CucumberTagStatement (cucumber.runtime.model.CucumberTagStatement)1 LocalizedXStreams (cucumber.runtime.xstream.LocalizedXStreams)1 I18n (gherkin.I18n)1 Argument (gherkin.formatter.Argument)1 ArrayList (java.util.ArrayList)1