Skip to content

Commit

Permalink
[Core] Remove UnreportedStepExecutor
Browse files Browse the repository at this point in the history
  • Loading branch information
mpkorstanje committed Jun 14, 2017
1 parent c8c9eab commit e384c25
Show file tree
Hide file tree
Showing 11 changed files with 38 additions and 100 deletions.
39 changes: 2 additions & 37 deletions core/src/main/java/cucumber/runner/Runner.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import cucumber.api.StepDefinitionReporter;
import cucumber.api.TestCase;
import cucumber.api.TestStep;
import cucumber.runtime.AmbiguousStepDefinitionsMatch;
import cucumber.runtime.AmbiguousStepDefinitionsException;
import cucumber.runtime.AmbiguousStepDefinitionsMatch;
import cucumber.runtime.Backend;
import cucumber.runtime.FailedStepInstantiationMatch;
import cucumber.runtime.Glue;
Expand All @@ -14,22 +14,15 @@
import cucumber.runtime.RuntimeOptions;
import cucumber.runtime.StepDefinitionMatch;
import cucumber.runtime.UndefinedStepDefinitionMatch;
import cucumber.runtime.UnreportedStepExecutor;
import gherkin.events.PickleEvent;
import gherkin.pickles.Argument;
import gherkin.pickles.PickleLocation;
import gherkin.pickles.PickleRow;
import gherkin.pickles.PickleStep;
import gherkin.pickles.PickleString;
import gherkin.pickles.PickleTable;
import gherkin.pickles.PickleTag;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;

public class Runner implements UnreportedStepExecutor {
public class Runner {
private final Glue glue;
private final EventBus bus;
private final Collection<? extends Backend> backends;
Expand All @@ -42,35 +35,7 @@ public Runner(Glue glue, EventBus bus, Collection<? extends Backend> backends, R
this.backends = backends;
for (Backend backend : backends) {
backend.loadGlue(glue, runtimeOptions.getGlue());
backend.setUnreportedStepExecutor(this);
}

}

//TODO: Maybe this should go into the cucumber step execution model and it should return the result of that execution!
@Override
public void runUnreportedStep(String featurePath, String language, String stepName, int line, List<PickleRow> dataTableRows, PickleString docString) throws Throwable {
List<Argument> arguments = new ArrayList<Argument>();
if (dataTableRows != null && !dataTableRows.isEmpty()) {
arguments.add(new PickleTable(dataTableRows));
} else if (docString != null) {
arguments.add(docString);
}
PickleStep step = new PickleStep(stepName, arguments, Collections.<PickleLocation>emptyList());

StepDefinitionMatch match = glue.stepDefinitionMatch(featurePath, step);
if (match == null) {
UndefinedStepException error = new UndefinedStepException(step);

StackTraceElement[] originalTrace = error.getStackTrace();
StackTraceElement[] newTrace = new StackTraceElement[originalTrace.length + 1];
newTrace[0] = new StackTraceElement("✽", "StepDefinition", featurePath, line);
System.arraycopy(originalTrace, 0, newTrace, 1, originalTrace.length);
error.setStackTrace(newTrace);

throw error;
}
match.runStep(language, null);
}

public void runPickle(PickleEvent pickle) {
Expand Down
6 changes: 0 additions & 6 deletions core/src/main/java/cucumber/runtime/Backend.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,6 @@ public interface Backend {
*/
void loadGlue(Glue glue, List<String> gluePaths);

/**
* invoked once, handing the backend a reference to a step executor
* in case the backend needs to call steps defined within other steps
*/
void setUnreportedStepExecutor(UnreportedStepExecutor executor);

/**
* Invoked before a new scenario starts. Implementations should do any necessary
* setup of new, isolated state here.
Expand Down
11 changes: 0 additions & 11 deletions core/src/main/java/cucumber/runtime/UnreportedStepExecutor.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import cucumber.runtime.ClassFinder;
import cucumber.runtime.CucumberException;
import cucumber.runtime.Glue;
import cucumber.runtime.UnreportedStepExecutor;
import cucumber.runtime.TagPredicate;
import cucumber.runtime.io.Resource;
import cucumber.runtime.io.ResourceLoader;
Expand Down Expand Up @@ -97,11 +96,6 @@ private void runIfScript(Binding context, Script script) {
}
}

@Override
public void setUnreportedStepExecutor(UnreportedStepExecutor executor) {
//Not used yet
}

@Override
public void buildWorld() {
world = new GroovyWorld();
Expand Down
6 changes: 0 additions & 6 deletions java/src/main/java/cucumber/runtime/java/JavaBackend.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import cucumber.runtime.DuplicateStepDefinitionException;
import cucumber.runtime.Env;
import cucumber.runtime.Glue;
import cucumber.runtime.UnreportedStepExecutor;
import cucumber.runtime.Utils;
import cucumber.runtime.io.MultiLoader;
import cucumber.runtime.io.ResourceLoader;
Expand Down Expand Up @@ -113,11 +112,6 @@ public void loadGlue(Glue glue, Method method, Class<?> glueCodeClass) {
methodScanner.scan(this, method, glueCodeClass);
}

@Override
public void setUnreportedStepExecutor(UnreportedStepExecutor executor) {
//Not used here yet
}

@Override
public void buildWorld() {
objectFactory.start();
Expand Down
44 changes: 34 additions & 10 deletions jruby/src/main/java/cucumber/runtime/jruby/JRubyBackend.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,17 @@
import cucumber.runtime.CucumberException;
import cucumber.runtime.Env;
import cucumber.runtime.Glue;
import cucumber.runtime.UnreportedStepExecutor;
import cucumber.runtime.StepDefinitionMatch;
import cucumber.runtime.io.Resource;
import cucumber.runtime.io.ResourceLoader;
import cucumber.runtime.snippets.FunctionNameGenerator;
import cucumber.runtime.snippets.SnippetGenerator;
import gherkin.pickles.Argument;
import gherkin.pickles.PickleLocation;
import gherkin.pickles.PickleRow;
import gherkin.pickles.PickleString;
import gherkin.pickles.PickleStep;
import org.jruby.CompatVersion;
import gherkin.pickles.PickleString;
import gherkin.pickles.PickleTable;
import org.jruby.Ruby;
import org.jruby.RubyModule;
import org.jruby.RubyObject;
Expand All @@ -27,6 +29,7 @@
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
Expand All @@ -40,7 +43,6 @@ public class JRubyBackend implements Backend {
private final RubyModule CucumberRuntimeJRubyWorld;

private Glue glue;
private UnreportedStepExecutor unreportedStepExecutor;
private RubyObject currentWorld;

public JRubyBackend(ResourceLoader resourceLoader) throws UnsupportedEncodingException {
Expand Down Expand Up @@ -83,11 +85,6 @@ public void loadGlue(Glue glue, List<String> gluePaths) {
}
}

@Override
public void setUnreportedStepExecutor(UnreportedStepExecutor executor) {
this.unreportedStepExecutor = executor;
}

@Override
public void buildWorld() {
currentWorld = (RubyObject) JavaEmbedUtils.javaToRuby(jruby.getProvider().getRuntime(), new World());
Expand Down Expand Up @@ -140,7 +137,32 @@ public void runStep(String featurePath, String language, String stepName, int li
dataTableRows = dataTable.getPickleRows();
}

unreportedStepExecutor.runUnreportedStep(featurePath, language, stepName, line, dataTableRows, docString);
runUnreportedStep(featurePath, language, stepName, line, dataTableRows, docString);
}

//TODO: Maybe this should go into the cucumber step execution model and it should return the result of that execution!
private void runUnreportedStep(String featurePath, String language, String stepName, int line, List<PickleRow> dataTableRows, PickleString docString) throws Throwable {
List<Argument> arguments = new ArrayList<Argument>();
if (dataTableRows != null && !dataTableRows.isEmpty()) {
arguments.add(new PickleTable(dataTableRows));
} else if (docString != null) {
arguments.add(docString);
}
PickleStep step = new PickleStep(stepName, arguments, Collections.<PickleLocation>emptyList());

StepDefinitionMatch match = glue.stepDefinitionMatch(featurePath, step);
if (match == null) {
UndefinedStepException error = new UndefinedStepException(step);

StackTraceElement[] originalTrace = error.getStackTrace();
StackTraceElement[] newTrace = new StackTraceElement[originalTrace.length + 1];
newTrace[0] = new StackTraceElement("✽", "StepDefinition", featurePath, line);
System.arraycopy(originalTrace, 0, newTrace, 1, originalTrace.length);
error.setStackTrace(newTrace);

throw error;
}
match.runStep(language, null);
}

public void executeHook(RubyObject hookRunner, Scenario scenario) {
Expand Down Expand Up @@ -172,4 +194,6 @@ void executeStepdef(RubyObject stepdef, String language, Object[] args) {

stepdef.callMethod("execute", jrubyArgs.toArray(new IRubyObject[jrubyArgs.size()]));
}


}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package cucumber.runner;
package cucumber.runtime.jruby;

import gherkin.pickles.PickleStep;

class UndefinedStepException extends Throwable {
public UndefinedStepException(PickleStep step) {
UndefinedStepException(PickleStep step) {
super(String.format("Undefined Step: %s", step.getText()));
}
}
5 changes: 0 additions & 5 deletions junit/src/test/java/cucumber/runtime/stub/StubBackend.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import cucumber.runtime.Backend;
import cucumber.runtime.Glue;
import cucumber.runtime.UnreportedStepExecutor;
import cucumber.runtime.io.ResourceLoader;
import cucumber.runtime.snippets.FunctionNameGenerator;
import gherkin.pickles.PickleStep;
Expand All @@ -21,10 +20,6 @@ public StubBackend(ResourceLoader resourceLoader) {
public void loadGlue(Glue glue, List<String> gluePaths) {
}

@Override
public void setUnreportedStepExecutor(UnreportedStepExecutor executor) {
}

@Override
public void buildWorld() {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import cucumber.runtime.Backend;
import cucumber.runtime.CucumberException;
import cucumber.runtime.Glue;
import cucumber.runtime.UnreportedStepExecutor;
import cucumber.runtime.io.Resource;
import cucumber.runtime.io.ResourceLoader;
import cucumber.runtime.snippets.FunctionNameGenerator;
Expand Down Expand Up @@ -56,11 +55,6 @@ public void loadGlue(Glue glue, List<String> gluePaths) {
}
}

@Override
public void setUnreportedStepExecutor(UnreportedStepExecutor executor) {
//Not used yet
}

@Override
public void buildWorld() {
this.pyWorld = jython.eval("World()");
Expand Down
6 changes: 0 additions & 6 deletions rhino/src/main/java/cucumber/runtime/rhino/RhinoBackend.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import cucumber.runtime.Backend;
import cucumber.runtime.CucumberException;
import cucumber.runtime.Glue;
import cucumber.runtime.UnreportedStepExecutor;
import cucumber.runtime.io.Resource;
import cucumber.runtime.io.ResourceLoader;
import cucumber.runtime.snippets.FunctionNameGenerator;
Expand Down Expand Up @@ -61,11 +60,6 @@ private void runScript(Resource resource) {
}
}

@Override
public void setUnreportedStepExecutor(UnreportedStepExecutor executor) {
// Not used yet
}

@Override
public void buildWorld() {
if (buildWorldFn != null) buildWorldFn.call(cx, scope, scope, new Object[0]);
Expand Down
5 changes: 0 additions & 5 deletions testng/src/test/java/cucumber/runtime/stub/StubBackend.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import cucumber.runtime.Backend;
import cucumber.runtime.Glue;
import cucumber.runtime.UnreportedStepExecutor;
import cucumber.runtime.io.ResourceLoader;
import cucumber.runtime.snippets.FunctionNameGenerator;
import gherkin.pickles.PickleStep;
Expand All @@ -21,10 +20,6 @@ public StubBackend(ResourceLoader resourceLoader) {
public void loadGlue(Glue glue, List<String> gluePaths) {
}

@Override
public void setUnreportedStepExecutor(UnreportedStepExecutor executor) {
}

@Override
public void buildWorld() {
}
Expand Down

0 comments on commit e384c25

Please sign in to comment.