Permalink
Browse files

Merge #671. Update History.md.

Also fix file modes and remove a wildcard import.
  • Loading branch information...
2 parents 63dca60 + 6d4e503 commit c3915bf182eb8b468a093a721c79f2d2fffee3fa @brasmusson brasmusson committed Feb 21, 2014
View
@@ -1,5 +1,6 @@
## [1-1-6-SNAPSHOT (Git master)](https://github.com/cucumber/cucumber-jvm/compare/v1.1.5...master)
+* [Core] Expose Scenario name to step definitions. ([#671](https://github.com/cucumber/cucumber-jvm/pull/671) Dominic Fox)
* [Clojure] Fixed bug in the snippet generation that caused an exception. ([#650](https://github.com/cucumber/cucumber-jvm/pull/650) shaolang)
* [Core] More precise handling of the XStream errors. ([#657](https://github.com/cucumber/cucumber-jvm/issues/657), [#658](https://github.com/cucumber/cucumber-jvm/pull/658) Mykola Gurov)
* [Core] Performance improvement: URLOutputStream can write several bytes, not just one-by-one. ([#654](https://github.com/cucumber/cucumber-jvm/issues/654) Aslak Hellesøy)
@@ -45,4 +45,6 @@
* @param text what to put in the report.
*/
void write(String text);
+
+ String getName();
}
@@ -133,14 +133,14 @@ private void writeStepdefsJson() {
glue.writeStepdefsJson(resourceLoader, runtimeOptions.getFeaturePaths(), runtimeOptions.getDotCucumber());
}
- public void buildBackendWorlds(Reporter reporter, Set<Tag> tags) {
+ public void buildBackendWorlds(Reporter reporter, Set<Tag> tags, String scenarioName) {
for (Backend backend : backends) {
backend.buildWorld();
}
undefinedStepsTracker.reset();
//TODO: this is the initial state of the state machine, it should not go here, but into something else
skipNextStep = false;
- scenarioResult = new ScenarioImpl(reporter, tags);
+ scenarioResult = new ScenarioImpl(reporter, tags, scenarioName);
}
public void disposeBackendWorlds() {
@@ -18,10 +18,12 @@
private final List<Result> stepResults = new ArrayList<Result>();
private final Reporter reporter;
private final Set<Tag> tags;
+ private final String scenarioName;
- public ScenarioImpl(Reporter reporter, Set<Tag> tags) {
+ public ScenarioImpl(Reporter reporter, Set<Tag> tags, String scenarioName) {
this.reporter = reporter;
this.tags = tags;
+ this.scenarioName = scenarioName;
}
void add(Result result) {
@@ -61,4 +63,9 @@ public void embed(byte[] data, String mimeType) {
public void write(String text) {
reporter.write(text);
}
+
+ @Override
+ public String getName() {
+ return scenarioName;
+ }
}
@@ -11,15 +11,18 @@
public class CucumberScenario extends CucumberTagStatement {
private final CucumberBackground cucumberBackground;
+ private final Scenario scenario;
public CucumberScenario(CucumberFeature cucumberFeature, CucumberBackground cucumberBackground, Scenario scenario) {
super(cucumberFeature, scenario);
this.cucumberBackground = cucumberBackground;
+ this.scenario = scenario;
}
public CucumberScenario(CucumberFeature cucumberFeature, CucumberBackground cucumberBackground, Scenario exampleScenario, Row example) {
super(cucumberFeature, exampleScenario, example);
this.cucumberBackground = cucumberBackground;
+ this.scenario = exampleScenario;
}
public CucumberBackground getCucumberBackground() {
@@ -32,7 +35,7 @@ public CucumberBackground getCucumberBackground() {
@Override
public void run(Formatter formatter, Reporter reporter, Runtime runtime) {
Set<Tag> tags = tagsAndInheritedTags();
- runtime.buildBackendWorlds(reporter, tags);
+ runtime.buildBackendWorlds(reporter, tags, scenario.getName());
try {
formatter.startOfScenarioLifeCycle((Scenario) getGherkinModel());
} catch (Throwable ignore) {
@@ -31,7 +31,7 @@ public void buildMockWorld() {
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
RuntimeOptions runtimeOptions = new RuntimeOptions("");
runtime = new Runtime(mock(ResourceLoader.class), classLoader, asList(mock(Backend.class)), runtimeOptions);
- runtime.buildBackendWorlds(null, Collections.<Tag>emptySet());
+ runtime.buildBackendWorlds(null, Collections.<Tag>emptySet(), "mock scenario");
glue = runtime.getGlue();
}
@@ -208,7 +208,7 @@ public void should_add_passed_result_to_the_summary_counter() throws Exception {
StepDefinitionMatch match = mock(StepDefinitionMatch.class);
Runtime runtime = createRuntimeWithMockedGlue(match, "--monochrome");
- runtime.buildBackendWorlds(reporter, Collections.<Tag>emptySet());
+ runtime.buildBackendWorlds(reporter, Collections.<Tag>emptySet(), "test scenario");
runStep(reporter, runtime);
runtime.disposeBackendWorlds();
runtime.printStats(new PrintStream(baos));
@@ -225,7 +225,7 @@ public void should_add_pending_result_to_the_summary_counter() throws Throwable
StepDefinitionMatch match = createExceptionThrowingMatch(new PendingException());
Runtime runtime = createRuntimeWithMockedGlue(match, "--monochrome");
- runtime.buildBackendWorlds(reporter, Collections.<Tag>emptySet());
+ runtime.buildBackendWorlds(reporter, Collections.<Tag>emptySet(), "test scenario");
runStep(reporter, runtime);
runtime.disposeBackendWorlds();
runtime.printStats(new PrintStream(baos));
@@ -242,7 +242,7 @@ public void should_add_failed_result_to_the_summary_counter() throws Throwable {
StepDefinitionMatch match = createExceptionThrowingMatch(new Exception());
Runtime runtime = createRuntimeWithMockedGlue(match, "--monochrome");
- runtime.buildBackendWorlds(reporter, Collections.<Tag>emptySet());
+ runtime.buildBackendWorlds(reporter, Collections.<Tag>emptySet(), "test scenario");
runStep(reporter, runtime);
runtime.disposeBackendWorlds();
runtime.printStats(new PrintStream(baos));
@@ -258,7 +258,7 @@ public void should_add_ambiguous_match_as_failed_result_to_the_summary_counter()
Reporter reporter = mock(Reporter.class);
Runtime runtime = createRuntimeWithMockedGlueWithAmbiguousMatch("--monochrome");
- runtime.buildBackendWorlds(reporter, Collections.<Tag>emptySet());
+ runtime.buildBackendWorlds(reporter, Collections.<Tag>emptySet(), "test scenario");
runStep(reporter, runtime);
runtime.disposeBackendWorlds();
runtime.printStats(new PrintStream(baos));
@@ -275,7 +275,7 @@ public void should_add_skipped_result_to_the_summary_counter() throws Throwable
StepDefinitionMatch match = createExceptionThrowingMatch(new Exception());
Runtime runtime = createRuntimeWithMockedGlue(match, "--monochrome");
- runtime.buildBackendWorlds(reporter, Collections.<Tag>emptySet());
+ runtime.buildBackendWorlds(reporter, Collections.<Tag>emptySet(), "test scenario");
runStep(reporter, runtime);
runStep(reporter, runtime);
runtime.disposeBackendWorlds();
@@ -292,7 +292,7 @@ public void should_add_undefined_result_to_the_summary_counter() throws Throwabl
Reporter reporter = mock(Reporter.class);
Runtime runtime = createRuntimeWithMockedGlue(null, "--monochrome");
- runtime.buildBackendWorlds(reporter, Collections.<Tag>emptySet());
+ runtime.buildBackendWorlds(reporter, Collections.<Tag>emptySet(), "test scenario");
runStep(reporter, runtime);
runtime.disposeBackendWorlds();
runtime.printStats(new PrintStream(baos));
@@ -310,7 +310,7 @@ public void should_fail_the_scenario_if_before_fails() throws Throwable {
HookDefinition hook = createExceptionThrowingHook();
Runtime runtime = createRuntimeWithMockedGlue(match, hook, true, "--monochrome");
- runtime.buildBackendWorlds(reporter, Collections.<Tag>emptySet());
+ runtime.buildBackendWorlds(reporter, Collections.<Tag>emptySet(), "test scenario");
runtime.runBeforeHooks(reporter, Collections.<Tag>emptySet());
runStep(reporter, runtime);
runtime.disposeBackendWorlds();
@@ -329,7 +329,7 @@ public void should_fail_the_scenario_if_after_fails() throws Throwable {
HookDefinition hook = createExceptionThrowingHook();
Runtime runtime = createRuntimeWithMockedGlue(match, hook, false, "--monochrome");
- runtime.buildBackendWorlds(reporter, Collections.<Tag>emptySet());
+ runtime.buildBackendWorlds(reporter, Collections.<Tag>emptySet(), "test scenario");
runStep(reporter, runtime);
runtime.runAfterHooks(reporter, Collections.<Tag>emptySet());
runtime.disposeBackendWorlds();
@@ -14,7 +14,7 @@
public class ScenarioResultTest {
private Reporter reporter = mock(Reporter.class);
- private ScenarioImpl s = new ScenarioImpl(reporter, Collections.<Tag>emptySet());
+ private ScenarioImpl s = new ScenarioImpl(reporter, Collections.<Tag>emptySet(), "test scenario");
@Test
public void no_steps_is_passed() throws Exception {
@@ -69,7 +69,7 @@ public void throws_ambiguous_when_two_matches_are_found() throws Throwable {
backend.addStepDefinition(THREE_BLIND_ANIMALS.getAnnotation(Given.class), THREE_BLIND_ANIMALS);
Reporter reporter = mock(Reporter.class);
- runtime.buildBackendWorlds(reporter, Collections.<Tag>emptySet());
+ runtime.buildBackendWorlds(reporter, Collections.<Tag>emptySet(), "test scenario");
Tag tag = new Tag("@foo", 0);
runtime.runBeforeHooks(reporter, asSet(tag));
runtime.runStep("some.feature", new Step(NO_COMMENTS, "Given ", "three blind mice", 1, null, null), reporter, ENGLISH);
@@ -113,7 +113,7 @@ public void embedding(String mimeType, byte[] data) {
public void write(String text) {
}
};
- runtime.buildBackendWorlds(reporter, Collections.<Tag>emptySet());
+ runtime.buildBackendWorlds(reporter, Collections.<Tag>emptySet(), "test scenario");
Tag tag = new Tag("@foo", 0);
Set<Tag> tags = asSet(tag);
runtime.runBeforeHooks(reporter, tags);
@@ -3,6 +3,7 @@
import cucumber.api.java.en.Given;
public class Stepdefs {
+
@Given("test")
public void test() {
@@ -0,0 +1,34 @@
+package cucumber.runtime.java.test;
+
+import cucumber.api.Scenario;
+import cucumber.api.java.Before;
+import cucumber.api.java.en.Given;
+import cucumber.api.java.en.Then;
+import cucumber.api.java.en.When;
+
+import static junit.framework.Assert.assertEquals;
+
+public class ScenarioStepDefs {
+
+ private String scenarioName = "";
+
+ @Before
+ public void get_scenario_name(Scenario scenario) {
+ scenarioName = scenario.getName();
+ }
+
+ @Given("^I am running a scenario$")
+ public void i_am_running_a_scenario() {
+
+ }
+
+ @When("^I try to get the scenario name$")
+ public void i_try_to_get_the_scenario_name() {
+
+ }
+
+ @Then("^The scenario name is \"([^\"]*)\"$")
+ public void the_scenario_name_is(String scenarioName) {
+ assertEquals(this.scenarioName, scenarioName);
+ }
+}
@@ -0,0 +1,11 @@
+Feature: Scenario information is available during step execution
+
+ Scenario: My first scenario
+ Given I am running a scenario
+ When I try to get the scenario name
+ Then The scenario name is "My first scenario"
+
+ Scenario: My second scenario
+ Given I am running a scenario
+ When I try to get the scenario name
+ Then The scenario name is "My second scenario"
@@ -19,6 +19,8 @@ class ScalaDslTest {
def embed(p1: Array[Byte], p2: String) {}
def write(p1: String) {}
+
+ def getName = ""
}
@Test
@@ -127,7 +129,7 @@ class ScalaDslTest {
assertEquals(1, Dummy.stepDefinitions.size)
val step = Dummy.stepDefinitions.head
- assertEquals("ScalaDslTest.scala:123", step.getLocation(true)) // be careful with formatting or this test will break
+ assertEquals("ScalaDslTest.scala:125", step.getLocation(true)) // be careful with formatting or this test will break
assertEquals("x", step.getPattern)
step.execute(new I18n("en"), Array())
assertTrue(called)

0 comments on commit c3915bf

Please sign in to comment.