Skip to content

Commit

Permalink
Merge efcab84 into 9dbc928
Browse files Browse the repository at this point in the history
  • Loading branch information
valfirst committed May 21, 2019
2 parents 9dbc928 + efcab84 commit 87cbeef
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 10 deletions.
Expand Up @@ -100,7 +100,7 @@ public Description createDescriptionFrom(Lifecycle lifecycle, PerformableScenari
private void addScenarioSteps(Lifecycle lifecycle, ScenarioType scenarioType, Scenario scenario, Description scenarioDescription) {
addBeforeOrAfterScenarioStep(scenarioType, Stage.BEFORE, scenarioDescription, BEFORE_SCENARIO_STEP_NAME);
addSteps(scenarioDescription, lifecycle.getBeforeSteps(Scope.SCENARIO));
addSteps(scenarioDescription, scenario.getSteps());
addScenarioSteps(lifecycle, scenarioDescription, scenario);
addSteps(scenarioDescription, lifecycle.getAfterSteps(Scope.SCENARIO, Outcome.ANY));
addBeforeOrAfterScenarioStep(scenarioType, Stage.AFTER, scenarioDescription, AFTER_SCENARIO_STEP_NAME);
}
Expand All @@ -113,6 +113,20 @@ private void addBeforeOrAfterScenarioStep(ScenarioType scenarioType, Stage stage
addBeforeOrAfterStep(stage, beforeOrAfterSteps, description, stepName);
}

private void addScenarioSteps(Lifecycle lifecycle, Description scenarioDescription, Scenario scenario) {
List<String> beforeSteps = lifecycle.getBeforeSteps(Scope.STEP);
List<String> afterSteps = lifecycle.getAfterSteps(Scope.STEP);
previousNonAndStep = null;
String tempPreviousNonAndStep = null;
for (String scenarioStep : scenario.getSteps()) {
addSteps(scenarioDescription, beforeSteps);
previousNonAndStep = tempPreviousNonAndStep;
addStep(scenarioDescription, scenarioStep);
tempPreviousNonAndStep = previousNonAndStep;
addSteps(scenarioDescription, afterSteps);
}
}

private void addBeforeOrAfterStep(Stage stage, List<BeforeOrAfterStep> beforeOrAfterSteps, Description description,
String stepName)
{
Expand Down Expand Up @@ -181,13 +195,17 @@ private void insertDescriptionForExamples(Lifecycle lifecycle, PerformableScenar
private void addSteps(Description description, List<String> steps) {
previousNonAndStep = null;
for (String stringStep : steps) {
String stringStepOneLine = stripLinebreaks(stringStep);
StepCandidate matchingStep = findMatchingStep(stringStep);
if (matchingStep == null) {
addNonExistingStep(description, stringStepOneLine, stringStep);
} else {
addExistingStep(description, stringStepOneLine, matchingStep);
}
addStep(description, stringStep);
}
}

private void addStep(Description description, String step) {
String stringStepOneLine = stripLinebreaks(step);
StepCandidate matchingStep = findMatchingStep(step);
if (matchingStep == null) {
addNonExistingStep(description, stringStepOneLine, step);
} else {
addExistingStep(description, stringStepOneLine, matchingStep);
}
}

Expand Down
Expand Up @@ -134,7 +134,7 @@ public void shouldGenerateDescriptionForStory() {
Scenario scenario = createScenario(step1, step2);
Story story = createStory(lifecycle, scenario);
List<Description> storyDescriptions = createDescriptionFrom(story);
assertEquals(6, generator.getTestCases());
assertEquals(10, generator.getTestCases());
assertEquals(1, storyDescriptions.size());
Description storyDescription = storyDescriptions.get(0);
assertEquals(Description.createSuiteDescription(story.getName()), storyDescription);
Expand All @@ -146,8 +146,12 @@ public void shouldGenerateDescriptionForStory() {
Description scenarioDescription = storyDescription.getChildren().get(1);
List<Description> scenarioLevelDescriptions = asList(
Description.createTestDescription(STEPS_TYPE, "Then before SCENARIO"),
Description.createTestDescription(STEPS_TYPE, "Then before STEP"),
Description.createTestDescription(STEPS_TYPE, step1),
Description.createTestDescription(STEPS_TYPE, "Then after STEP"),
Description.createTestDescription(STEPS_TYPE, "Then before STEP\u200B"),
Description.createTestDescription(Object.class, "And step with table param:"),
Description.createTestDescription(STEPS_TYPE, "Then after STEP\u200B"),
Description.createTestDescription(STEPS_TYPE, "Then after ANY SCENARIO"));
assertEquals(scenarioLevelDescriptions, scenarioDescription.getChildren());
}
Expand Down Expand Up @@ -414,11 +418,12 @@ private List<Steps> createBeforeLifecycleSteps() {

private List<Steps> createAfterLifecycleSteps() {
List<Steps> steps = new ArrayList<>();
for (Scope scope : Scope.values()) {
for (Scope scope : new Scope[] { Scope.SCENARIO, Scope.STORY }) {
for (Outcome outcome : Outcome.values()) {
steps.add(new Steps(scope, outcome, singletonList("Then after " + outcome + " " + scope)));
}
}
steps.add(new Steps(Scope.STEP, Outcome.ANY, singletonList("Then after "+ Scope.STEP)));
return steps;
}

Expand Down

0 comments on commit 87cbeef

Please sign in to comment.