Search in sources :

Example 1 with Formatter

use of gherkin.formatter.Formatter in project cucumber-jvm by cucumber.

the class FormatterMissingLifecycleMethods method set_monochrome_on_color_aware_formatters.

@Test
public void set_monochrome_on_color_aware_formatters() throws Exception {
    PluginFactory factory = mock(PluginFactory.class);
    Formatter colorAwareFormatter = mock(Formatter.class, withSettings().extraInterfaces(ColorAware.class));
    when(factory.create("progress")).thenReturn(colorAwareFormatter);
    RuntimeOptions options = new RuntimeOptions(new Env(), factory, asList("--monochrome", "--plugin", "progress"));
    options.getPlugins();
    verify((ColorAware) colorAwareFormatter).setMonochrome(true);
}
Also used : ColorAware(cucumber.runtime.formatter.ColorAware) Formatter(gherkin.formatter.Formatter) PluginFactory(cucumber.runtime.formatter.PluginFactory) Test(org.junit.Test)

Example 2 with Formatter

use of gherkin.formatter.Formatter in project cucumber-jvm by cucumber.

the class Runtime method run.

/**
     * This is the main entry point. Used from CLI, but not from JUnit.
     */
public void run() throws IOException {
    // Make sure all features parse before initialising any reporters/formatters
    List<CucumberFeature> features = runtimeOptions.cucumberFeatures(resourceLoader);
    // TODO: This is duplicated in cucumber.api.android.CucumberInstrumentationCore - refactor or keep uptodate
    Formatter formatter = runtimeOptions.formatter(classLoader);
    Reporter reporter = runtimeOptions.reporter(classLoader);
    StepDefinitionReporter stepDefinitionReporter = runtimeOptions.stepDefinitionReporter(classLoader);
    glue.reportStepDefinitions(stepDefinitionReporter);
    for (CucumberFeature cucumberFeature : features) {
        cucumberFeature.run(formatter, reporter, this);
    }
    formatter.done();
    formatter.close();
    printSummary();
}
Also used : CucumberFeature(cucumber.runtime.model.CucumberFeature) Formatter(gherkin.formatter.Formatter) StepDefinitionReporter(cucumber.api.StepDefinitionReporter) Reporter(gherkin.formatter.Reporter) StepDefinitionReporter(cucumber.api.StepDefinitionReporter)

Example 3 with Formatter

use of gherkin.formatter.Formatter in project cucumber-jvm by cucumber.

the class JUnitReporterTest method forward_calls_to_formatter_interface_methods.

@Test
public void forward_calls_to_formatter_interface_methods() throws Exception {
    String uri = "uri";
    Feature feature = mock(Feature.class);
    Background background = mock(Background.class);
    ScenarioOutline scenarioOutline = mock(ScenarioOutline.class);
    Examples examples = mock(Examples.class);
    Scenario scenario = mock(Scenario.class);
    Step step = mock(Step.class);
    Formatter formatter = mock(Formatter.class);
    jUnitReporter = new JUnitReporter(mock(Reporter.class), formatter, false, new JUnitOptions(Collections.<String>emptyList()));
    jUnitReporter.uri(uri);
    jUnitReporter.feature(feature);
    jUnitReporter.scenarioOutline(scenarioOutline);
    jUnitReporter.examples(examples);
    jUnitReporter.startOfScenarioLifeCycle(scenario);
    jUnitReporter.background(background);
    jUnitReporter.scenario(scenario);
    jUnitReporter.step(step);
    jUnitReporter.endOfScenarioLifeCycle(scenario);
    jUnitReporter.eof();
    jUnitReporter.done();
    jUnitReporter.close();
    verify(formatter).uri(uri);
    verify(formatter).feature(feature);
    verify(formatter).scenarioOutline(scenarioOutline);
    verify(formatter).examples(examples);
    verify(formatter).startOfScenarioLifeCycle(scenario);
    ;
    verify(formatter).background(background);
    verify(formatter).scenario(scenario);
    verify(formatter).step(step);
    verify(formatter).endOfScenarioLifeCycle(scenario);
    verify(formatter).eof();
    verify(formatter).done();
    verify(formatter).close();
}
Also used : Background(gherkin.formatter.model.Background) ScenarioOutline(gherkin.formatter.model.ScenarioOutline) Formatter(gherkin.formatter.Formatter) Step(gherkin.formatter.model.Step) Feature(gherkin.formatter.model.Feature) Examples(gherkin.formatter.model.Examples) Scenario(gherkin.formatter.model.Scenario) Test(org.junit.Test)

Example 4 with Formatter

use of gherkin.formatter.Formatter in project cucumber-jvm by cucumber.

the class FeatureBuilder method parse.

public void parse(Resource resource, List<Object> filters) {
    String gherkin = read(resource);
    String checksum = checksum(gherkin);
    String path = pathsByChecksum.get(checksum);
    if (path != null) {
        return;
    }
    pathsByChecksum.put(checksum, resource.getPath());
    Formatter formatter = this;
    if (!filters.isEmpty()) {
        formatter = new FilterFormatter(this, filters);
    }
    Parser parser = new Parser(formatter);
    try {
        parser.parse(gherkin, convertFileSeparatorToForwardSlash(resource.getPath()), 0);
    } catch (Exception e) {
        throw new CucumberException(String.format("Error parsing feature file %s", convertFileSeparatorToForwardSlash(resource.getPath())), e);
    }
    I18n i18n = parser.getI18nLanguage();
    if (currentCucumberFeature != null) {
        // The current feature may be null if we used a very restrictive filter, say a tag that isn't used.
        // Might also happen if the feature file itself is empty.
        currentCucumberFeature.setI18n(i18n);
    }
}
Also used : Formatter(gherkin.formatter.Formatter) FilterFormatter(gherkin.formatter.FilterFormatter) FilterFormatter(gherkin.formatter.FilterFormatter) IOException(java.io.IOException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) Parser(gherkin.parser.Parser) I18n(gherkin.I18n)

Example 5 with Formatter

use of gherkin.formatter.Formatter in project cucumber-jvm by cucumber.

the class CucumberExecutor method execute.

/**
     * Runs the cucumber scenarios with the specified arguments.
     */
public void execute() {
    runtimeOptions.addPlugin(new AndroidInstrumentationReporter(runtime, instrumentation, getNumberOfConcreteScenarios()));
    runtimeOptions.addPlugin(new AndroidLogcatReporter(runtime, TAG));
    // TODO: This is duplicated in info.cucumber.Runtime.
    final Reporter reporter = runtimeOptions.reporter(classLoader);
    final Formatter formatter = runtimeOptions.formatter(classLoader);
    final StepDefinitionReporter stepDefinitionReporter = runtimeOptions.stepDefinitionReporter(classLoader);
    runtime.getGlue().reportStepDefinitions(stepDefinitionReporter);
    for (final CucumberFeature cucumberFeature : cucumberFeatures) {
        cucumberFeature.run(formatter, reporter, runtime);
    }
    formatter.done();
    formatter.close();
}
Also used : CucumberFeature(cucumber.runtime.model.CucumberFeature) Formatter(gherkin.formatter.Formatter) Reporter(gherkin.formatter.Reporter) StepDefinitionReporter(cucumber.api.StepDefinitionReporter) StepDefinitionReporter(cucumber.api.StepDefinitionReporter)

Aggregations

Formatter (gherkin.formatter.Formatter)8 Reporter (gherkin.formatter.Reporter)3 Test (org.junit.Test)3 StepDefinitionReporter (cucumber.api.StepDefinitionReporter)2 PluginFactory (cucumber.runtime.formatter.PluginFactory)2 CucumberFeature (cucumber.runtime.model.CucumberFeature)2 ColorAware (cucumber.runtime.formatter.ColorAware)1 StrictAware (cucumber.runtime.formatter.StrictAware)1 I18n (gherkin.I18n)1 FilterFormatter (gherkin.formatter.FilterFormatter)1 Background (gherkin.formatter.model.Background)1 Examples (gherkin.formatter.model.Examples)1 Feature (gherkin.formatter.model.Feature)1 Scenario (gherkin.formatter.model.Scenario)1 ScenarioOutline (gherkin.formatter.model.ScenarioOutline)1 Step (gherkin.formatter.model.Step)1 Parser (gherkin.parser.Parser)1 IOException (java.io.IOException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1