Skip to content

Commit

Permalink
Set a description for Scenario Outline scenarios. Fixes #837.
Browse files Browse the repository at this point in the history
Both Scenario Outlines and Examples tables can have a description. The
description for an example scenario created from a Scenario Outline is
set to the contatenation of these description (if they both exists).
  • Loading branch information
brasmusson committed Mar 15, 2015
1 parent 3fc886e commit 72e2d05
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public List<CucumberScenario> createExampleScenarios() {
List<ExamplesTableRow> rows = examples.getRows();
List<Tag> tags = new ArrayList<Tag>(tagsAndInheritedTags());
for (int i = 1; i < rows.size(); i++) {
exampleScenarios.add(cucumberScenarioOutline.createExampleScenario(rows.get(0), rows.get(i), tags));
exampleScenarios.add(cucumberScenarioOutline.createExampleScenario(rows.get(0), rows.get(i), tags, examples.getDescription()));
}
return exampleScenarios;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,12 @@ public void formatOutlineScenario(Formatter formatter) {
format(formatter);
}

CucumberScenario createExampleScenario(ExamplesTableRow header, ExamplesTableRow example, List<Tag> examplesTags) {
CucumberScenario createExampleScenario(ExamplesTableRow header, ExamplesTableRow example, List<Tag> examplesTags, String examplesDescription) {
// Make sure we replace the tokens in the name of the scenario
String exampleScenarioName = replaceTokens(new HashSet<Integer>(), header.getCells(), example.getCells(), getGherkinModel().getName());
String exampleScenarioDescription = createExampleScenarioDescription(getGherkinModel().getDescription(), examplesDescription);

Scenario exampleScenario = new Scenario(example.getComments(), examplesTags, getGherkinModel().getKeyword(), exampleScenarioName, "", example.getLine(), example.getId());
Scenario exampleScenario = new Scenario(example.getComments(), examplesTags, getGherkinModel().getKeyword(), exampleScenarioName, exampleScenarioDescription, example.getLine(), example.getId());
CucumberScenario cucumberScenario = new CucumberScenario(cucumberFeature, cucumberBackground, exampleScenario, example);
for (Step step : getSteps()) {
cucumberScenario.step(createExampleStep(step, header, example));
Expand Down Expand Up @@ -123,4 +124,16 @@ private static String replaceTokens(Set<Integer> matchedColumns, List<String> he
}
return text;
}

private String createExampleScenarioDescription(String scenarioOutlineDescription, String examplesDescription) {
if (!examplesDescription.isEmpty()) {
if (!scenarioOutlineDescription.isEmpty()) {
return scenarioOutlineDescription + ", " + examplesDescription;
} else {
return examplesDescription;
}
} else {
return scenarioOutlineDescription;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package cucumber.runtime.model;

import cucumber.runtime.TestHelper;
import gherkin.formatter.model.Comment;
import gherkin.formatter.model.Examples;
import gherkin.formatter.model.ExamplesTableRow;
Expand All @@ -9,6 +10,7 @@
import gherkin.formatter.model.Tag;
import org.junit.Test;

import java.io.IOException;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
Expand Down Expand Up @@ -49,4 +51,58 @@ public void should_create_example_scenarios() {
assertEquals("I have 5 cukes in my belly", step.getName());
}

@Test
public void should_concatenate_outline_description_and_examples_description() throws IOException {
CucumberFeature feature = TestHelper.feature("path/test.feature", "" +
"Feature: feature name\n" +
" Scenario Outline: outline name\n" +
" outline description\n" +
" Given first step\n" +
" Examples: examples name\n "+
" examples description\n" +
" | dummy |\n" +
" | 1 |\n");
CucumberScenarioOutline cso = (CucumberScenarioOutline) feature.getFeatureElements().get(0);
CucumberExamples cucumberExamples = cso.getCucumberExamplesList().get(0);

List<CucumberScenario> exampleScenarios = cucumberExamples.createExampleScenarios();

assertEquals("outline description, examples description", exampleScenarios.get(0).getGherkinModel().getDescription());
}

@Test
public void should_use_outline_description_when_examples_description_is_empty() throws IOException {
CucumberFeature feature = TestHelper.feature("path/test.feature", "" +
"Feature: feature name\n" +
" Scenario Outline: outline name\n" +
" outline description\n" +
" Given first step\n" +
" Examples: examples name\n "+
" | dummy |\n" +
" | 1 |\n");
CucumberScenarioOutline cso = (CucumberScenarioOutline) feature.getFeatureElements().get(0);
CucumberExamples cucumberExamples = cso.getCucumberExamplesList().get(0);

List<CucumberScenario> exampleScenarios = cucumberExamples.createExampleScenarios();

assertEquals("outline description", exampleScenarios.get(0).getGherkinModel().getDescription());
}

@Test
public void should_use_examples_description_when_outline_description_is_empty() throws IOException {
CucumberFeature feature = TestHelper.feature("path/test.feature", "" +
"Feature: feature name\n" +
" Scenario Outline: outline name\n" +
" Given first step\n" +
" Examples: examples name\n "+
" examples description\n" +
" | dummy |\n" +
" | 1 |\n");
CucumberScenarioOutline cso = (CucumberScenarioOutline) feature.getFeatureElements().get(0);
CucumberExamples cucumberExamples = cso.getCucumberExamplesList().get(0);

List<CucumberScenario> exampleScenarios = cucumberExamples.createExampleScenarios();

assertEquals("examples description", exampleScenarios.get(0).getGherkinModel().getDescription());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public void replaces_tokens_in_scenario_names() {

// ... then the Cukes implementation
CucumberScenarioOutline cukeOutline = new CucumberScenarioOutline(null, null, outline);
CucumberScenario exampleScenario = cukeOutline.createExampleScenario(new ExamplesTableRow(C, asList("LOCATION_NAME"), 1, ""), new ExamplesTableRow(C, asList("London"), 1, ""), T);
CucumberScenario exampleScenario = cukeOutline.createExampleScenario(new ExamplesTableRow(C, asList("LOCATION_NAME"), 1, ""), new ExamplesTableRow(C, asList("London"), 1, ""), T, "");

assertEquals("Time offset check for London", exampleScenario.getGherkinModel().getName());
}
Expand Down

0 comments on commit 72e2d05

Please sign in to comment.