Search in sources :

Example 1 with CucumberFeature

use of cucumber.runtime.model.CucumberFeature in project cucumber-jvm by cucumber.

the class FeatureBuilder method feature.

@Override
public void feature(Feature feature) {
    currentCucumberFeature = new CucumberFeature(feature, featurePath);
    cucumberFeatures.add(currentCucumberFeature);
}
Also used : CucumberFeature(cucumber.runtime.model.CucumberFeature)

Example 2 with CucumberFeature

use of cucumber.runtime.model.CucumberFeature in project cucumber-jvm by cucumber.

the class BackgroundTest method should_run_background.

@Test
public void should_run_background() throws IOException {
    ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
    RuntimeOptions runtimeOptions = new RuntimeOptions("");
    Runtime runtime = new Runtime(new ClasspathResourceLoader(classLoader), classLoader, asList(mock(Backend.class)), runtimeOptions);
    CucumberFeature feature = feature("test.feature", "" + "Feature:\n" + "  Background:\n" + "    Given b\n" + "  Scenario:\n" + "    When s\n");
    StringBuilder out = new StringBuilder();
    PrettyFormatter pretty = new PrettyFormatter(out, true, true);
    feature.run(pretty, pretty, runtime);
    String expectedOutput = "" + "Feature: \n" + "\n" + "  Background:  # test.feature:2\n" + "    Given b\n" + "\n" + "  Scenario:  # test.feature:4\n" + "    When s\n";
    assertEquals(expectedOutput, out.toString());
}
Also used : CucumberFeature(cucumber.runtime.model.CucumberFeature) ClasspathResourceLoader(cucumber.runtime.io.ClasspathResourceLoader) PrettyFormatter(gherkin.formatter.PrettyFormatter) Test(org.junit.Test)

Example 3 with CucumberFeature

use of cucumber.runtime.model.CucumberFeature in project cucumber-jvm by cucumber.

the class FeatureBuilderTest method works_when_path_and_uri_are_the_same.

@Test
public void works_when_path_and_uri_are_the_same() throws IOException {
    char fileSeparatorChar = '/';
    String featurePath = "path" + fileSeparatorChar + "foo.feature";
    Resource resource = createResourceMock(featurePath);
    List<CucumberFeature> features = new ArrayList<CucumberFeature>();
    FeatureBuilder builder = new FeatureBuilder(features, fileSeparatorChar);
    builder.parse(resource, NO_FILTERS);
    assertEquals(1, features.size());
    assertEquals(featurePath, features.get(0).getPath());
}
Also used : CucumberFeature(cucumber.runtime.model.CucumberFeature) Resource(cucumber.runtime.io.Resource) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 4 with CucumberFeature

use of cucumber.runtime.model.CucumberFeature in project cucumber-jvm by cucumber.

the class ScenarioCounterTest method createCucumberFeaturesWithScenarioOutlines.

private List<CucumberFeature> createCucumberFeaturesWithScenarioOutlines(final int numberOfCucumberFeatures, final int numberOfScenarioOutlines, final int numberOfCucumberExamples, final int numberOfExampleRows) {
    final int numberOfExampleRowsIncludingHeaderRow = numberOfExampleRows + 1;
    final List<CucumberFeature> cucumberFeatures = new ArrayList<CucumberFeature>();
    for (int f = 0; f < numberOfCucumberFeatures; f++) {
        final CucumberFeature cucumberFeature = mock(CucumberFeature.class);
        cucumberFeatures.add(cucumberFeature);
        // set up 2 scenarios outlines
        final List<CucumberTagStatement> cucumberTagStatements = new ArrayList<CucumberTagStatement>();
        for (int o = 0; o < numberOfScenarioOutlines; o++) {
            cucumberTagStatements.add(mock(CucumberScenarioOutline.class));
        }
        when(cucumberFeature.getFeatureElements()).thenReturn(cucumberTagStatements);
        // with 2 examples for each scenario outline
        for (final CucumberTagStatement cucumberTagStatement : cucumberTagStatements) {
            final CucumberScenarioOutline cucumberScenarioOutline = (CucumberScenarioOutline) cucumberTagStatement;
            final List<CucumberExamples> cucumberExamplesList = createMockList(CucumberExamples.class, numberOfCucumberExamples);
            when(cucumberScenarioOutline.getCucumberExamplesList()).thenReturn(cucumberExamplesList);
            // each example should have two rows (excluding the header row)
            for (final CucumberExamples cucumberExamples : cucumberExamplesList) {
                final Examples examples = mock(Examples.class);
                when(examples.getRows()).thenReturn(createMockList(ExamplesTableRow.class, numberOfExampleRowsIncludingHeaderRow));
                when(cucumberExamples.getExamples()).thenReturn(examples);
            }
        }
    }
    return cucumberFeatures;
}
Also used : CucumberScenarioOutline(cucumber.runtime.model.CucumberScenarioOutline) ExamplesTableRow(gherkin.formatter.model.ExamplesTableRow) CucumberFeature(cucumber.runtime.model.CucumberFeature) ArrayList(java.util.ArrayList) CucumberTagStatement(cucumber.runtime.model.CucumberTagStatement) CucumberExamples(cucumber.runtime.model.CucumberExamples) CucumberExamples(cucumber.runtime.model.CucumberExamples) Examples(gherkin.formatter.model.Examples)

Example 5 with CucumberFeature

use of cucumber.runtime.model.CucumberFeature 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)

Aggregations

CucumberFeature (cucumber.runtime.model.CucumberFeature)65 Test (org.junit.Test)53 HashMap (java.util.HashMap)33 Result (gherkin.formatter.model.Result)32 ArrayList (java.util.ArrayList)19 SimpleEntry (java.util.AbstractMap.SimpleEntry)10 ClasspathResourceLoader (cucumber.runtime.io.ClasspathResourceLoader)6 Resource (cucumber.runtime.io.Resource)6 Formatter (gherkin.formatter.Formatter)5 Reporter (gherkin.formatter.Reporter)5 StepDefinitionReporter (cucumber.api.StepDefinitionReporter)4 CucumberTagStatement (cucumber.runtime.model.CucumberTagStatement)4 Step (gherkin.formatter.model.Step)4 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)4 Matchers.anyString (org.mockito.Matchers.anyString)4 CucumberJSONFormatter (cucumber.runtime.formatter.CucumberJSONFormatter)3 JSONFormatter (gherkin.formatter.JSONFormatter)3 Tag (gherkin.formatter.model.Tag)3 Description (org.junit.runner.Description)3 Scenario (cucumber.api.Scenario)2