Search in sources :

Example 16 with Resource

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

the class GroovyBackend method loadGlue.

@Override
public void loadGlue(Glue glue, List<String> gluePaths) {
    this.glue = glue;
    final Binding context = shell.getContext();
    for (String gluePath : gluePaths) {
        // Load sources
        for (Resource resource : resourceLoader.resources(gluePath, ".groovy")) {
            Script script = parse(resource);
            runIfScript(context, script);
        }
        // Load compiled scripts
        for (Class<? extends Script> glueClass : classFinder.getDescendants(Script.class, packageName(gluePath))) {
            try {
                Script script = glueClass.getConstructor(Binding.class).newInstance(context);
                runIfScript(context, script);
            } catch (Exception e) {
                throw new CucumberException(e);
            }
        }
    }
}
Also used : Binding(groovy.lang.Binding) Script(groovy.lang.Script) Resource(cucumber.runtime.io.Resource) CucumberException(cucumber.runtime.CucumberException) InvokerInvocationException(org.codehaus.groovy.runtime.InvokerInvocationException) CucumberException(cucumber.runtime.CucumberException) IOException(java.io.IOException)

Example 17 with Resource

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

the class StepdefGeneratorTest method features.

private List<CucumberFeature> features() throws IOException {
    List<CucumberFeature> features = new ArrayList<CucumberFeature>();
    FeatureBuilder fb = new FeatureBuilder(features);
    fb.parse(new Resource() {

        @Override
        public String getPath() {
            return "test.feature";
        }

        @Override
        public String getAbsolutePath() {
            throw new UnsupportedOperationException();
        }

        @Override
        public InputStream getInputStream() {
            try {
                return new ByteArrayInputStream(("" + "Feature: Test\n" + "  Scenario: Test\n" + "    Given I have 4 cukes in my belly\n" + "    And I have 3 bananas in my basket\n" + "    Given I have 42 cukes in my belly\n").getBytes("UTF-8"));
            } catch (UnsupportedEncodingException e) {
                throw new RuntimeException(e);
            }
        }

        @Override
        public String getClassName(String extension) {
            throw new UnsupportedOperationException();
        }
    }, emptyList());
    return features;
}
Also used : FeatureBuilder(cucumber.runtime.FeatureBuilder) CucumberFeature(cucumber.runtime.model.CucumberFeature) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) Resource(cucumber.runtime.io.Resource) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Aggregations

Resource (cucumber.runtime.io.Resource)17 ArrayList (java.util.ArrayList)9 CucumberFeature (cucumber.runtime.model.CucumberFeature)6 ByteArrayInputStream (java.io.ByteArrayInputStream)6 Test (org.junit.Test)3 CucumberException (cucumber.runtime.CucumberException)2 FeatureBuilder (cucumber.runtime.FeatureBuilder)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 AssetManager (android.content.res.AssetManager)1 ResourceLoader (cucumber.runtime.io.ResourceLoader)1 DocString (gherkin.formatter.model.DocString)1 Binding (groovy.lang.Binding)1 Script (groovy.lang.Script)1 Gosu (gw.lang.Gosu)1 Map (java.util.Map)1 SWClassLoader (org.apache.openejb.arquillian.openejb.SWClassLoader)1 InvokerInvocationException (org.codehaus.groovy.runtime.InvokerInvocationException)1 Archive (org.jboss.shrinkwrap.api.Archive)1