Skip to content

Commit

Permalink
Merge branch 'master' into android
Browse files Browse the repository at this point in the history
# By Aslak Hellesøy (9) and others
# Via Dmytro Chyzhykov (2) and others
* master:
  [TestNG] Java Calculator TestNG example project - #579 issue.
  [Jython] Access to scenario in Before and After hooks. Closes #582.
  Scenario Outlines: Replace tokens in the names of the generated "Example Scenario"s.
  Change some remaining Cucumber.Options to CucumberOptions
  No longer used
  No longer used
  master is SNAPSHOT
  Java Calculator TestNG example project.
  Enable Wicket example, using HtmlUnitDriver so it runs on Travis. Upgraded maven plugins.
  is deprecated in favour of . Closes #549
  Disable wicket example for now
  Updated History.md with Android improvements. Ref #547 and #574.
  Attribution. Fix broken test. Closes #568
  Enable wicket example. Removed incorrect comment about cargo requiring Java 7. It does not. (Jetty 9 does, but we're on 8 now).
  #568 Inherit Information of @Cucumber.Options
  • Loading branch information
mfellner committed Sep 6, 2013
2 parents 18d44c1 + df3cfc9 commit b2ac1f8
Show file tree
Hide file tree
Showing 41 changed files with 784 additions and 253 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@ libpeerconnection.log
ehthumbs.db
Icon?
Thumbs.db
test-json-report.json
4 changes: 0 additions & 4 deletions Gemfile

This file was deleted.

8 changes: 7 additions & 1 deletion History.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
## [Git master](https://github.com/cucumber/cucumber-jvm/compare/v1.1.4...master)
## [1-1-5-SNAPSHOT (Git master)](https://github.com/cucumber/cucumber-jvm/compare/v1.1.4...master)

* [TestNG] Java Calculator TestNG example project ([#579](https://github.com/cucumber/cucumber-jvm/pull/579) Dmytro Chyzhykov)
* [Jython] Access to scenario in Before and After hooks ([#582](https://github.com/cucumber/cucumber-jvm/issues/582) Aslak Hellesøy)
* [Core] Replace placeholders in the Scenario Outline title ([#580](https://github.com/cucumber/cucumber-jvm/pull/580), [#510](https://github.com/cucumber/cucumber-jvm/issues/510) Jamie W. Astin)
* [JUnit/Core] `@cucumber.junit.api.Cucumber.Options` is deprecated in favour of `@cucumber.api.Options` ([#549](https://github.com/cucumber/cucumber-jvm/issues/549) Aslak Hellesøy)
* [JUnit] Inherit Information of @Cucumber.Options ([#568](https://github.com/cucumber/cucumber-jvm/issues/568) Klaus Bayrhammer)
* [JUnit] JUnitFormatter does not put required name attribute in testsuite root element ([#480](https://github.com/cucumber/cucumber-jvm/pull/480), [#477](https://github.com/cucumber/cucumber-jvm/issues/477) ericmaxwell2003)
* [Core] Output embedded text in HTML report ([#501](https://github.com/cucumber/cucumber-jvm/pull/501) Tom Dunstan)
* [Core] Fix for Lexing Error message not useful ([#519](https://github.com/cucumber/cucumber-jvm/issues/519), [#523](https://github.com/cucumber/cucumber-jvm/pull/523) Alpar Gal)
Expand All @@ -9,6 +14,7 @@
* [Core] Bugfix: StringIndexOutOfBoundsException when optional argument not present. ([#394](https://github.com/cucumber/cucumber-jvm/issues/394), [#558](https://github.com/cucumber/cucumber-jvm/pull/558) Guy Burton)
* [Java, Jython] New `--snippet [underscore|camelcase]` option for more control over snippet style. ([#561](https://github.com/cucumber/cucumber-jvm/pull/561), [302](https://github.com/cucumber/cucumber-jvm/pull/302) Márton Mészáros, Aslak Hellesøy)
* [Windows] Use uri instead of path in CucumberFeature ([#562](https://github.com/cucumber/cucumber-jvm/pull/562) Björn Rasmusson)
* [Android] Better example for Cucumber-Android. ([#547](https://github.com/cucumber/cucumber-jvm/issues/547), [#574](https://github.com/cucumber/cucumber-jvm/issues/574))

## [1.1.4](https://github.com/cucumber/cucumber-jvm/compare/v1.1.3...v1.1.4) (2013-08-11)

Expand Down
7 changes: 0 additions & 7 deletions Rakefile

This file was deleted.

62 changes: 62 additions & 0 deletions core/src/main/java/cucumber/api/CucumberOptions.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package cucumber.api;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
* This annotation provides the same options as the cucumber command line, {@link cucumber.api.cli.Main}.
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE})
public @interface CucumberOptions {
/**
* @return true if this is a dry run
*/
boolean dryRun() default false;

/**
* @return true if strict mode is enabled (fail if there are undefined or pending steps)
*/
boolean strict() default false;

/**
* @return the paths to the feature(s)
*/
String[] features() default {};

/**
* @return where to look for glue code (stepdefs and hooks)
*/
String[] glue() default {};

/**
* @return what tags in the features should be executed
*/
String[] tags() default {};

/**
* @return what formatter(s) to use
*/
String[] format() default {};

/**
* @return whether or not to use monochrome output
*/
boolean monochrome() default false;

/**
* Specify a patternfilter for features or scenarios
*
* @return a list of patterns
*/
String[] name() default {};

String dotcucumber() default "";

/**
* @return what format should the snippets use. underscore, camelcase
*/
SnippetType snippets() default SnippetType.UNDERSCORE;
}
3 changes: 3 additions & 0 deletions core/src/main/java/cucumber/api/Scenario.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
* It allows writing text and embedding media into reports, as well as inspecting results (in an After block).
*/
public interface Scenario {
/**
* @return source_tag_names. Needed for compatibility with Capybara.
*/
Collection<String> getSourceTagNames();

/**
Expand Down
182 changes: 182 additions & 0 deletions core/src/main/java/cucumber/runtime/RuntimeOptionsFactory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
package cucumber.runtime;

import cucumber.api.SnippetType;
import cucumber.runtime.io.MultiLoader;

import java.lang.annotation.Annotation;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class RuntimeOptionsFactory {
private final Class clazz;
private final Class<? extends Annotation>[] annotationClasses;

public RuntimeOptionsFactory(Class clazz, Class<? extends Annotation>[] annotationClasses) {
this.clazz = clazz;
this.annotationClasses = annotationClasses;
}

public RuntimeOptions create() {
List<String> args = buildArgsFromOptions();

return new RuntimeOptions(System.getProperties(), args.toArray(new String[args.size()]));
}

private List<String> buildArgsFromOptions() {
List<String> args = new ArrayList<String>();

for (Class classWithOptions = clazz; hasSuperClass(classWithOptions); classWithOptions = classWithOptions.getSuperclass()) {
Annotation[] optionsArray = getOptions(classWithOptions);
for (Annotation options : optionsArray) {
if (options != null) {
addDryRun(options, args);
addMonochrome(options, args);
addTags(options, args);
addFormats(options, args);
addStrict(options, args);
addName(options, args);
addDotCucumber(options, args);
addSnippets(options, args);
}
}
addGlue(optionsArray, args, classWithOptions);
addFeatures(optionsArray, args, classWithOptions);
}
return args;
}

private void addDotCucumber(Annotation options, List<String> args) {
String dotcucumber = this.invoke(options, "dotcucumber");
if (!dotcucumber.isEmpty()) {
args.add("--dotcucumber");
args.add(dotcucumber);
}
}

private void addName(Annotation options, List<String> args) {
for (String name : this.<String[]>invoke(options, "name")) {
args.add("--name");
args.add(name);
}
}

private void addSnippets(Annotation options, List<String> args) {
args.add("--snippets");
args.add(this.<SnippetType>invoke(options, "snippets").toString());
}

private void addDryRun(Annotation options, List<String> args) {
if (this.<Boolean>invoke(options, "dryRun")) {
args.add("--dry-run");
}
}

private void addMonochrome(Annotation options, List<String> args) {
if (this.<Boolean>invoke(options, "monochrome") || runningInEnvironmentWithoutAnsiSupport()) {
args.add("--monochrome");
}
}

private void addTags(Annotation options, List<String> args) {
for (String tags : this.<String[]>invoke(options, "tags")) {
args.add("--tags");
args.add(tags);
}
}

private void addFormats(Annotation options, List<String> args) {
if (this.<String[]>invoke(options, "format").length != 0) {
for (String format : this.<String[]>invoke(options, "format")) {
args.add("--format");
args.add(format);
}
} else {
args.add("--format");
args.add("null");
}
}

private void addFeatures(Annotation[] optionsArray, List<String> args, Class clazz) {
boolean specified = false;
for (Annotation options : optionsArray) {
if (options != null && this.<String[]>invoke(options, "features").length != 0) {
Collections.addAll(args, this.<String[]>invoke(options, "features"));
specified = true;
}
}
if (!specified) {
args.add(MultiLoader.CLASSPATH_SCHEME + packagePath(clazz));
}
}

private void addGlue(Annotation[] optionsArray, List<String> args, Class clazz) {
boolean specified = false;
for (Annotation options : optionsArray) {
if (options != null && this.<String[]>invoke(options, "glue").length != 0) {
for (String glue : this.<String[]>invoke(options, "glue")) {
args.add("--glue");
args.add(glue);
}
specified = true;
}
}
if (!specified) {
args.add("--glue");
args.add(MultiLoader.CLASSPATH_SCHEME + packagePath(clazz));
}
}


private void addStrict(Annotation options, List<String> args) {
if (this.<Boolean>invoke(options, "strict")) {
args.add("--strict");
}
}

static String packagePath(Class clazz) {
return packagePath(packageName(clazz.getName()));
}

static String packagePath(String packageName) {
return packageName.replace('.', '/');
}

static String packageName(String className) {
return className.substring(0, Math.max(0, className.lastIndexOf(".")));
}

private boolean runningInEnvironmentWithoutAnsiSupport() {
boolean intelliJidea = System.getProperty("idea.launcher.bin.path") != null;
// TODO: What does Eclipse use?
return intelliJidea;
}

private boolean hasSuperClass(Class classWithOptions) {
return classWithOptions != Object.class;
}

private Annotation[] getOptions(Class<?> clazz) {
Annotation[] annotations = new Annotation[annotationClasses.length];
for (int i = 0; i < annotations.length; i++) {
annotations[i] = clazz.getAnnotation(annotationClasses[i]);
}
return annotations;
}

private <T> T invoke(Annotation options, String name) {
try {
Method method = options.annotationType().getMethod(name);
return (T) method.invoke(options);
} catch (NoSuchMethodException e) {
throw new CucumberException(e);
} catch (InvocationTargetException e) {
throw new CucumberException(e);
} catch (IllegalAccessException e) {
throw new CucumberException(e);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@ public void run(Formatter formatter, Reporter reporter, Runtime runtime) {
}

CucumberScenario createExampleScenario(ExamplesTableRow header, ExamplesTableRow example, List<Tag> examplesTags) {
Scenario exampleScenario = new Scenario(example.getComments(), examplesTags, getGherkinModel().getKeyword(), getGherkinModel().getName(), "", example.getLine(), example.getId());
// Make sure we replace the tokens in the name of the scenario
String exampleScenarioName = replaceTokens(new HashSet<Integer>(), header.getCells(), example.getCells(), getGherkinModel().getName());

Scenario exampleScenario = new Scenario(example.getComments(), examplesTags, getGherkinModel().getKeyword(), exampleScenarioName, "", example.getLine(), example.getId());
CucumberScenario cucumberScenario = new CucumberScenario(cucumberFeature, cucumberBackground, exampleScenario, example);
for (Step step : getSteps()) {
cucumberScenario.step(createExampleStep(step, header, example));
Expand Down
Loading

0 comments on commit b2ac1f8

Please sign in to comment.