Skip to content

Commit

Permalink
[Core] Implement cucumber expressions (#1248)
Browse files Browse the repository at this point in the history
 * Implements Cucumber expressions
 * Removes XStream
 * Adds DataTables from cucumber/common#291
 * Introduces the concept of StepExpressions which combines a CucumberExpression and DataTable expression. Currently data table expressions are limited to a java type. Currently only the implicit type derived from the method argument is used.

For a working example check the calculator examples.
  • Loading branch information
mpkorstanje committed May 14, 2018
1 parent 8c69975 commit a4a3ad5
Show file tree
Hide file tree
Showing 217 changed files with 2,647 additions and 6,659 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -48,7 +48,7 @@ You're most likely going to paste code and output, so familiarise yourself with
<pre>
```java
// Why doesn't this work?
@Given("I have (\\d+) cukes in my (.*)")
@Given("I have {int} cukes in my {string}")
public void some_cukes(int howMany, String what) {
// HALP!
}
Expand Down
Expand Up @@ -3,19 +3,24 @@
import android.app.Instrumentation;
import android.content.Context;
import android.util.Log;
import cucumber.api.TypeRegistryConfigurer;
import cucumber.api.CucumberOptions;
import cucumber.api.StepDefinitionReporter;
import io.cucumber.stepexpression.TypeRegistry;
import cucumber.api.event.TestRunFinished;
import cucumber.api.java.ObjectFactory;
import cucumber.runtime.Backend;
import cucumber.runtime.ClassFinder;
import cucumber.runtime.CucumberException;
import cucumber.runtime.DefaultTypeRegistryConfiguration;
import cucumber.runtime.Env;
import cucumber.runtime.Reflections;
import cucumber.runtime.Runtime;
import cucumber.runtime.RuntimeOptions;
import cucumber.runtime.RuntimeOptionsFactory;
import cucumber.runtime.formatter.AndroidInstrumentationReporter;
import cucumber.runtime.formatter.AndroidLogcatReporter;
import cucumber.runtime.io.MultiLoader;
import cucumber.runtime.io.ResourceLoader;
import cucumber.runtime.java.JavaBackend;
import cucumber.runtime.java.ObjectFactoryLoader;
Expand All @@ -24,10 +29,11 @@
import gherkin.events.PickleEvent;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import static java.util.Collections.singletonList;

/**
* Executes the cucumber scenarios.
*/
Expand Down Expand Up @@ -159,10 +165,12 @@ private RuntimeOptions createRuntimeOptions(final Context context) {
}

private Collection<? extends Backend> createBackends() {
final Reflections reflections = new Reflections(classFinder);
final ObjectFactory delegateObjectFactory = ObjectFactoryLoader.loadObjectFactory(classFinder, Env.INSTANCE.get(ObjectFactory.class.getName()));
final AndroidObjectFactory objectFactory = new AndroidObjectFactory(delegateObjectFactory, instrumentation);
final List<Backend> backends = new ArrayList<Backend>();
backends.add(new JavaBackend(objectFactory, classFinder));
return backends;
final TypeRegistryConfigurer typeRegistryConfigurer = reflections.instantiateExactlyOneSubclass(TypeRegistryConfigurer.class, MultiLoader.packageName(runtimeOptions.getGlue()), new Class[0], new Object[0], new DefaultTypeRegistryConfiguration());
final TypeRegistry typeRegistry = new TypeRegistry(typeRegistryConfigurer.locale());
typeRegistryConfigurer.configureTypeRegistry(typeRegistry);
return singletonList(new JavaBackend(objectFactory, classFinder, typeRegistry));
}
}
19 changes: 9 additions & 10 deletions core/pom.xml
Expand Up @@ -18,17 +18,20 @@
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-jvm-deps</artifactId>
<artifactId>gherkin</artifactId>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>gherkin</artifactId>
<artifactId>tag-expressions</artifactId>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>tag-expressions</artifactId>
<artifactId>cucumber-expressions</artifactId>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>datatable</artifactId>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
Expand All @@ -49,11 +52,7 @@
<artifactId>jsoup</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.webbitserver</groupId>
<artifactId>webbit</artifactId>
Expand All @@ -64,6 +63,7 @@
<artifactId>webbit-rest</artifactId>
<scope>test</scope>
</dependency>

</dependencies>

<build>
Expand Down Expand Up @@ -101,7 +101,6 @@
<configuration>
<instructions>
<Bundle-Description />
<Export-Package>cucumber.*</Export-Package>
<DynamicImport-Package>*</DynamicImport-Package>
</instructions>
</configuration>
Expand Down
14 changes: 12 additions & 2 deletions core/src/main/java/cucumber/api/Argument.java
@@ -1,7 +1,17 @@
package cucumber.api;

/**
* Represents an argument in for a step definition.
* <p>
* The step definition {@code I have {long} cukes in my belly}
* when matched with {@code I have 7 cukes in my belly} will produce
* one argument with value {@code "4"}, starting at {@code 7} and
* ending at {@code 8}.
*/
public interface Argument {
Integer getOffset();
String getValue();

String getVal();
int getStart();

int getEnd();
}

0 comments on commit a4a3ad5

Please sign in to comment.