Skip to content

Commit

Permalink
Fix #136: handle case when all scenarios in story are filtered out (#140
Browse files Browse the repository at this point in the history
)
  • Loading branch information
valfirst authored Jun 19, 2018
1 parent 9fc8943 commit 1c1f87d
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ public List<Description> createDescriptionFrom(PerformableTree performableTree)
if (performableStory.isAllowed()) {
Story story = performableStory.getStory();
Lifecycle lifecycle = story.getLifecycle();
List<Description> scenarioDescriptions = getScenarioDescriptions(lifecycle,
performableStory.getScenarios());
if (!scenarioDescriptions.isEmpty()) {
List<PerformableScenario> scenarios = performableStory.getScenarios();
List<Description> scenarioDescriptions = getScenarioDescriptions(lifecycle, scenarios);
if (!scenarios.isEmpty()) {
Description storyDescription = createDescriptionForStory(story);
addBeforeOrAfterStep(Stage.BEFORE, beforeOrAfterStory, storyDescription, BEFORE_STORY_STEP_NAME);
addSteps(storyDescription, lifecycle.getBeforeSteps(Scope.STORY));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,33 +69,33 @@ public void beforeStory(Story story, boolean isGivenStory) {
if (testCounter.get() == 0) {
notifier.fireTestRunStarted(rootDescription);
}
for (Description storyDescription : rootDescription.getChildren()) {
if (storyDescription.isSuite()
&& storyDescription.getDisplayName().equals(
JUnitStringDecorator.getJunitSafeString(story.getName()))) {
testState.currentStoryDescription = storyDescription;
notifier.fireTestStarted(storyDescription);

testState.scenarioDescriptions = storyDescription.getChildren().iterator();
testState.moveToNextScenario();
processBeforeStory();
testState.currentStep = testState.currentStoryDescription;
} else
// Related to issue #28: When a story does not contain any
// scenarios, isTest returns true, but getMethodName
// still returns null, because it cannot be parsed by JUnit as a
// method name.
if (storyDescription.isTest()
&& storyDescription.getMethodName() != null
&& storyDescription.getMethodName().equals(
story.getName())) {
// Story BeforeStories or After Stories
testState.currentStoryDescription = storyDescription;
notifier.fireTestStarted(testState.currentStoryDescription);
testState.currentStep = testState.currentStoryDescription;
}
Description storyDescription = findStoryDescription(story.getName());
testState.currentStoryDescription = storyDescription;
notifier.fireTestStarted(storyDescription);
if (storyDescription.isSuite()) {
testState.scenarioDescriptions = storyDescription.getChildren().iterator();
testState.moveToNextScenario();
processBeforeStory();
}
testState.currentStep = testState.currentStoryDescription;
}
}

private Description findStoryDescription(String storyName) {
String escapedStoryName = JUnitStringDecorator.getJunitSafeString(storyName);
for (Description storyDescription : rootDescription.getChildren()) {
if (storyDescription.getDisplayName().equals(escapedStoryName)) {
return storyDescription;
} else
// Related to issue #28: When a story does not contain any scenarios, isTest returns true,
// but getMethodName still returns null, because it cannot be parsed by JUnit as a method name.
if (storyDescription.isTest() && storyDescription.getMethodName() != null
&& storyDescription.getMethodName().equals(storyName)) {
// Story BeforeStories or AfterStories
return storyDescription;
}
}
throw new IllegalStateException("No JUnit description found for story with name: " + storyName);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.github.valfirst.jbehave.junit.monitoring;

import java.util.Arrays;

import com.github.valfirst.jbehave.junit.monitoring.step.ExampleSteps;

import org.jbehave.core.configuration.Configuration;
import org.jbehave.core.configuration.MostUsefulConfiguration;
import org.jbehave.core.embedder.EmbedderControls;
import org.jbehave.core.junit.JUnitStory;
import org.jbehave.core.steps.InjectableStepsFactory;
import org.jbehave.core.steps.InstanceStepsFactory;
import org.junit.runner.RunWith;

@RunWith(JUnitReportingRunner.class)
public class FilteredOutScenariosNotStory extends JUnitStory {

public FilteredOutScenariosNotStory() {
EmbedderControls embedderControls = JUnitReportingRunner.recommendedControls(configuredEmbedder());
embedderControls.doVerboseFailures(true);
embedderControls.doIgnoreFailureInStories(false);
configuredEmbedder().useMetaFilters(Arrays.asList("-first", "-second"));
}

@Override
public InjectableStepsFactory stepsFactory() {
return new InstanceStepsFactory(configuration(), new ExampleSteps());
}

@Override
public Configuration configuration() {
return new MostUsefulConfiguration();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Meta:
@all

Narrative:
As a user
I want to perform an action
So that I can achieve a business goal

Scenario: First scenario filtered by tag first
Meta: @first
Given a variable x with value 2
When I multiply x by 2
Then x should equal 4

Scenario: Second scenario filtered by tag second
Meta: @second
Then this step is not executed

0 comments on commit 1c1f87d

Please sign in to comment.