Skip to content

Commit 9c593a1

Browse files
authored
JBEHAVE-1608 Do not reset story controls after Given stories
1 parent b934ebc commit 9c593a1

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

jbehave-core/src/main/java/org/jbehave/core/embedder/PerformableTree.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1108,7 +1108,9 @@ public void perform(RunContext context) throws InterruptedException {
11081108
}
11091109
);
11101110

1111-
context.configuration().storyControls().resetCurrentStoryControls();
1111+
if (!givenStory) {
1112+
context.configuration().storyControls().resetCurrentStoryControls();
1113+
}
11121114
if (context.restartStory()) {
11131115
context.reporter().afterStory(true);
11141116
} else {

jbehave-core/src/test/java/org/jbehave/core/embedder/PerformableTreeBehaviour.java

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -137,25 +137,35 @@ void shouldAddExcludedPerformableScenariosToPerformableStory() {
137137

138138
@Test
139139
void shouldNotSkipStoryWhenGivenStoryIsFailed() {
140-
RunContext context = performStoryRun(false, GIVEN_SCENARIO_FAIL);
140+
RunContext context = performStoryRun(new StoryControls().doSkipStoryIfGivenStoryFailed(false),
141+
GIVEN_SCENARIO_FAIL);
141142
assertThat(context.failureOccurred(), is(false));
142143
assertThat(context.configuration().storyControls().skipStoryIfGivenStoryFailed(), is(false));
143144
}
144145

145146
@Test
146147
void shouldSkipStoryWhenGivenStoryIsFailed() {
147-
RunContext context = performStoryRun(true, GIVEN_SCENARIO_FAIL);
148+
RunContext context = performStoryRun(new StoryControls().doSkipStoryIfGivenStoryFailed(true),
149+
GIVEN_SCENARIO_FAIL);
148150
assertThat(context.failureOccurred(), is(true));
149151
assertThat(context.configuration().storyControls().skipStoryIfGivenStoryFailed(), is(true));
150152
}
151153

152154
@Test
153155
void shouldNotSkipStoryWhenGivenStoryIsPassed() {
154-
RunContext context = performStoryRun(true, "Scenario: given scenario title");
156+
RunContext context = performStoryRun(new StoryControls().doSkipStoryIfGivenStoryFailed(true),
157+
"Scenario: given scenario title");
155158
assertThat(context.failureOccurred(), is(false));
156159
assertThat(context.configuration().storyControls().skipStoryIfGivenStoryFailed(), is(true));
157160
}
158161

162+
@Test
163+
void shouldResetCurrentStoryControlsOnlyForRootStory() {
164+
StoryControls storyControls = mock(StoryControls.class);
165+
performStoryRun(storyControls, GIVEN_SCENARIO_FAIL);
166+
verify(storyControls).resetCurrentStoryControls();
167+
}
168+
159169
@Test
160170
void shouldResetCurrentStoryControls() {
161171
Configuration configuration = new MostUsefulConfiguration();
@@ -334,14 +344,13 @@ private Map<String, String> createExamplesRow(String key1, String value1, String
334344
return storyExampleFirstRow;
335345
}
336346

337-
private RunContext performStoryRun(boolean skipScenariosAfterGivenStoriesFailure, String givenStoryAsString) {
347+
private RunContext performStoryRun(StoryControls storyControls, String givenStoryAsString) {
338348
String givenStoryPath = "given/path";
339349
Scenario scenario = new Scenario("base scenario title", Meta.EMPTY);
340350
Story story = new Story(STORY_PATH, null, null, null, new GivenStories(givenStoryPath),
341351
singletonList(scenario));
342352

343-
Configuration configuration = new MostUsefulConfiguration().useStoryControls(
344-
new StoryControls().doSkipStoryIfGivenStoryFailed(skipScenariosAfterGivenStoriesFailure));
353+
Configuration configuration = new MostUsefulConfiguration().useStoryControls(storyControls);
345354
StoryLoader storyLoader = mock(StoryLoader.class);
346355
configuration.useStoryLoader(storyLoader);
347356
when(storyLoader.loadStoryAsText(givenStoryPath)).thenReturn(givenStoryAsString);

0 commit comments

Comments
 (0)