Search in sources :

Example 1 with ResourceLoader

use of cucumber.runtime.io.ResourceLoader in project cucumber-jvm by cucumber.

the class FormatterMissingLifecycleMethods method applies_line_filters_only_to_own_feature.

@Test
public void applies_line_filters_only_to_own_feature() throws Exception {
    String featurePath1 = "path/bar.feature";
    String feature1 = "" + "Feature: bar\n" + "  Scenario: scenario_1_1\n" + "    * step\n" + "  Scenario: scenario_1_2\n" + "    * step\n";
    String featurePath2 = "path/foo.feature";
    String feature2 = "" + "Feature: foo\n" + "  Scenario: scenario_2_1\n" + "    * step\n" + "  Scenario: scenario_2_2\n" + "    * step\n";
    ResourceLoader resourceLoader = mock(ResourceLoader.class);
    mockResource(resourceLoader, featurePath1, feature1);
    mockResource(resourceLoader, featurePath2, feature2);
    RuntimeOptions options = new RuntimeOptions(featurePath1 + ":2 " + featurePath2 + ":4");
    List<CucumberFeature> features = options.cucumberFeatures(resourceLoader);
    assertEquals(2, features.size());
    assertOnlyScenarioName(features.get(0), "scenario_1_1");
    assertOnlyScenarioName(features.get(1), "scenario_2_2");
}
Also used : ResourceLoader(cucumber.runtime.io.ResourceLoader) CucumberFeature(cucumber.runtime.model.CucumberFeature) Test(org.junit.Test)

Example 2 with ResourceLoader

use of cucumber.runtime.io.ResourceLoader in project cucumber-jvm by cucumber.

the class CalculatorTest method cucumber.

@Test
public void cucumber() throws Exception {
    assertNotNull(injector);
    assertNotNull(bundleContext);
    final ResourceLoader resourceLoader = new FileResourceLoader();
    final ClassLoader classLoader = Runtime.class.getClassLoader();
    final ObjectFactory objectFactory = new PaxExamObjectFactory(injector);
    final ClassFinder classFinder = new OsgiClassFinder(bundleContext);
    final Backend backend = new JavaBackend(objectFactory, classFinder);
    final RuntimeOptionsFactory runtimeOptionsFactory = new RuntimeOptionsFactory(getClass());
    final RuntimeOptions runtimeOptions = runtimeOptionsFactory.create();
    final Runtime runtime = new Runtime(resourceLoader, classLoader, Collections.singleton(backend), runtimeOptions);
    runtime.run();
    if (!runtime.getErrors().isEmpty()) {
        throw new CucumberException(runtime.getErrors().get(0));
    } else if (runtime.exitStatus() != 0x00) {
        throw new CucumberException("There are pending or undefined steps.");
    }
    assertEquals(runtime.getErrors().size(), 0);
}
Also used : ResourceLoader(cucumber.runtime.io.ResourceLoader) FileResourceLoader(cucumber.runtime.io.FileResourceLoader) JavaBackend(cucumber.runtime.java.JavaBackend) OsgiClassFinder(cucumber.java.runtime.osgi.OsgiClassFinder) Backend(cucumber.runtime.Backend) JavaBackend(cucumber.runtime.java.JavaBackend) Runtime(cucumber.runtime.Runtime) ObjectFactory(cucumber.api.java.ObjectFactory) PaxExamObjectFactory(cucumber.java.runtime.osgi.PaxExamObjectFactory) FileResourceLoader(cucumber.runtime.io.FileResourceLoader) PaxExamObjectFactory(cucumber.java.runtime.osgi.PaxExamObjectFactory) ClassFinder(cucumber.runtime.ClassFinder) OsgiClassFinder(cucumber.java.runtime.osgi.OsgiClassFinder) CucumberException(cucumber.runtime.CucumberException) RuntimeOptionsFactory(cucumber.runtime.RuntimeOptionsFactory) RuntimeOptions(cucumber.runtime.RuntimeOptions) Test(org.junit.Test)

Example 3 with ResourceLoader

use of cucumber.runtime.io.ResourceLoader in project cucumber-jvm by cucumber.

the class CucumberFeatureTest method succeds_if_no_features_are_found.

@Test
public void succeds_if_no_features_are_found() {
    ResourceLoader resourceLoader = mock(ResourceLoader.class);
    when(resourceLoader.resources("does/not/exist", ".feature")).thenReturn(Collections.<Resource>emptyList());
    CucumberFeature.load(resourceLoader, singletonList("does/not/exist"), emptyList(), new PrintStream(new ByteArrayOutputStream()));
}
Also used : ResourceLoader(cucumber.runtime.io.ResourceLoader) PrintStream(java.io.PrintStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Example 4 with ResourceLoader

use of cucumber.runtime.io.ResourceLoader in project cucumber-jvm by cucumber.

the class CucumberFeatureTest method loads_features_specified_in_rerun_file_from_classpath_when_not_in_file_system.

@Test
public void loads_features_specified_in_rerun_file_from_classpath_when_not_in_file_system() throws Exception {
    String featurePath = "path/bar.feature";
    String feature = "" + "Feature: bar\n" + "  Scenario: scenario bar\n" + "    * step\n";
    String rerunPath = "path/rerun.txt";
    String rerunFile = featurePath + ":2";
    ResourceLoader resourceLoader = mockFeatureFileResource("classpath:" + featurePath, feature);
    mockFeaturePathToNotExist(resourceLoader, featurePath);
    mockFileResource(resourceLoader, rerunPath, suffix(null), rerunFile);
    List<CucumberFeature> features = CucumberFeature.load(resourceLoader, singletonList("@" + rerunPath), new ArrayList<Object>(), new PrintStream(new ByteArrayOutputStream()));
    assertEquals(1, features.size());
    assertEquals(1, features.get(0).getFeatureElements().size());
    assertEquals("Scenario: scenario bar", features.get(0).getFeatureElements().get(0).getVisualName());
}
Also used : ResourceLoader(cucumber.runtime.io.ResourceLoader) PrintStream(java.io.PrintStream) Matchers.anyString(org.mockito.Matchers.anyString) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Example 5 with ResourceLoader

use of cucumber.runtime.io.ResourceLoader in project cucumber-jvm by cucumber.

the class CucumberFeatureTest method logs_message_if_features_are_found_but_filters_are_too_strict.

@Test
public void logs_message_if_features_are_found_but_filters_are_too_strict() throws IOException {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ResourceLoader resourceLoader = mockFeatureFileResource("features", "Feature: foo");
    CucumberFeature.load(resourceLoader, singletonList("features"), singletonList((Object) "@nowhere"), new PrintStream(baos));
    assertEquals(String.format("None of the features at [features] matched the filters: [@nowhere]%n"), baos.toString());
}
Also used : ResourceLoader(cucumber.runtime.io.ResourceLoader) PrintStream(java.io.PrintStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Aggregations

ResourceLoader (cucumber.runtime.io.ResourceLoader)26 Test (org.junit.Test)15 ByteArrayOutputStream (java.io.ByteArrayOutputStream)11 PrintStream (java.io.PrintStream)11 MultiLoader (cucumber.runtime.io.MultiLoader)7 Matchers.anyString (org.mockito.Matchers.anyString)7 RuntimeOptions (cucumber.runtime.RuntimeOptions)5 ClasspathResourceLoader (cucumber.runtime.io.ClasspathResourceLoader)4 ClassFinder (cucumber.runtime.ClassFinder)3 Runtime (cucumber.runtime.Runtime)3 ResourceLoaderClassFinder (cucumber.runtime.io.ResourceLoaderClassFinder)3 ObjectFactory (cucumber.api.java.ObjectFactory)2 JavaBackend (cucumber.runtime.java.JavaBackend)2 CucumberFeature (cucumber.runtime.model.CucumberFeature)2 Injector (com.google.inject.Injector)1 Module (com.google.inject.Module)1 OsgiClassFinder (cucumber.java.runtime.osgi.OsgiClassFinder)1 PaxExamObjectFactory (cucumber.java.runtime.osgi.PaxExamObjectFactory)1 Backend (cucumber.runtime.Backend)1 CucumberException (cucumber.runtime.CucumberException)1