Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Core] Running empty Pickles should yield the result undefined. #1274

Merged
merged 1 commit into from
Oct 26, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions core/src/main/java/cucumber/runner/Runner.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,14 @@ public void reportStepDefinitions(StepDefinitionReporter stepDefinitionReporter)

private TestCase createTestCaseForPickle(PickleEvent pickleEvent) {
List<TestStep> testSteps = new ArrayList<TestStep>();
if (!runtimeOptions.isDryRun()) {
addTestStepsForBeforeHooks(testSteps, pickleEvent.pickle.getTags());
}
addTestStepsForPickleSteps(testSteps, pickleEvent);
if (!runtimeOptions.isDryRun()) {
addTestStepsForAfterHooks(testSteps, pickleEvent.pickle.getTags());
if (!pickleEvent.pickle.getSteps().isEmpty()) {
if (!runtimeOptions.isDryRun()) {
addTestStepsForBeforeHooks(testSteps, pickleEvent.pickle.getTags());
}
addTestStepsForPickleSteps(testSteps, pickleEvent);
if (!runtimeOptions.isDryRun()) {
addTestStepsForAfterHooks(testSteps, pickleEvent.pickle.getTags());
}
}
return new TestCase(testSteps, pickleEvent, runtimeOptions.isDryRun());
}
Expand Down
3 changes: 3 additions & 0 deletions core/src/main/java/cucumber/runtime/ScenarioImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ public Collection<String> getSourceTagNames() {

@Override
public Result.Type getStatus() {
if (stepResults.isEmpty()) {
return Result.Type.UNDEFINED;
}
int pos = 0;
for (Result stepResult : stepResults) {
pos = Math.max(pos, SEVERITY.indexOf(stepResult.getStatus()));
Expand Down
26 changes: 20 additions & 6 deletions core/src/test/java/cucumber/runner/RunnerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,14 @@ public class RunnerTest {
private final Backend backend = mock(Backend.class);
private final Runtime runtime = createRuntime(backend);
private final Runner runner = runtime.getRunner();

@Test
public void hooks_execute_when_world_exist() throws Throwable {
PickleStep step = mock(PickleStep.class);
HookDefinition beforeHook = addBeforeHook(runtime);
HookDefinition afterHook = addAfterHook(runtime);

runner.runPickle(createEmptyPickleEvent());
runner.runPickle(createPickleEventWithSteps(asList(step)));

InOrder inOrder = inOrder(beforeHook, afterHook, backend);
inOrder.verify(backend).buildWorld();
Expand All @@ -70,19 +71,20 @@ public void steps_are_skipped_after_failure() throws Throwable {

@Test
public void hooks_execute_also_after_failure() throws Throwable {
PickleStep step = mock(PickleStep.class);
HookDefinition failingBeforeHook = addBeforeHook(runtime);
doThrow(RuntimeException.class).when(failingBeforeHook).execute(Matchers.<Scenario>any());
HookDefinition beforeHook = addBeforeHook(runtime);
HookDefinition afterHook = addAfterHook(runtime);

runner.runPickle(createEmptyPickleEvent());
runner.runPickle(createPickleEventWithSteps(asList(step)));

InOrder inOrder = inOrder(failingBeforeHook, beforeHook, afterHook);
inOrder.verify(failingBeforeHook).execute(Matchers.<Scenario>any());
inOrder.verify(beforeHook).execute(Matchers.<Scenario>any());
inOrder.verify(afterHook).execute(Matchers.<Scenario>any());
}

@Test
public void steps_are_executed() throws Throwable {
final StepDefinition stepDefinition = mock(StepDefinition.class);
Expand All @@ -96,12 +98,24 @@ public void steps_are_not_executed_on_dry_run() throws Throwable {
final Runtime dryRuntime = createRuntime(backend, "--dry-run");
dryRuntime.getRunner().runPickle(createPickleEventMatchingStepDefinitions(asList(stepDefinition), dryRuntime));
verify(stepDefinition, never()).execute(Matchers.anyString(), Matchers.<Object[]>any());
}
}

@Test
public void hooks_not_executed_in_dry_run_mode() throws Throwable {
Runtime runtime = createRuntime(backend, "--dry-run");
Runner runner = runtime.getRunner();
PickleStep step = mock(PickleStep.class);
HookDefinition beforeHook = addBeforeHook(runtime);
HookDefinition afterHook = addAfterHook(runtime);

runner.runPickle(createPickleEventWithSteps(asList(step)));

verify(beforeHook, never()).execute(Matchers.<Scenario>any());
verify(afterHook, never()).execute(Matchers.<Scenario>any());
}

@Test
public void hooks_not_executed_for_empty_pickles() throws Throwable {
HookDefinition beforeHook = addBeforeHook(runtime);
HookDefinition afterHook = addAfterHook(runtime);

Expand Down
3 changes: 2 additions & 1 deletion core/src/test/java/cucumber/runtime/HookOrderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ public void buildMockWorld() {
Runtime runtime = new Runtime(mock(ResourceLoader.class), classLoader, asList(mock(Backend.class)), runtimeOptions);
runner = runtime.getRunner();
glue = runtime.getGlue();
pickleEvent = new PickleEvent("uri", new Pickle("name", ENGLISH, Collections.<PickleStep>emptyList(), Collections.<PickleTag>emptyList(), asList(mock(PickleLocation.class))));
PickleStep step = mock(PickleStep.class);
pickleEvent = new PickleEvent("uri", new Pickle("name", ENGLISH, asList(step), Collections.<PickleTag>emptyList(), asList(mock(PickleLocation.class))));
}

@Test
Expand Down
3 changes: 2 additions & 1 deletion core/src/test/java/cucumber/runtime/HookTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ public void after_hooks_execute_before_objects_are_disposed() throws Throwable {
Runtime runtime = new Runtime(new ClasspathResourceLoader(classLoader), classLoader, asList(backend), runtimeOptions);
runtime.getGlue().addAfterHook(hook);
Runner runner = runtime.getRunner();
PickleEvent pickleEvent = new PickleEvent("uri", new Pickle("name", ENGLISH, Collections.<PickleStep>emptyList(), Collections.<PickleTag>emptyList(), asList(mock(PickleLocation.class))));
PickleStep step = mock(PickleStep.class);
PickleEvent pickleEvent = new PickleEvent("uri", new Pickle("name", ENGLISH, asList(step), Collections.<PickleTag>emptyList(), asList(mock(PickleLocation.class))));

runner.runPickle(pickleEvent);

Expand Down
8 changes: 7 additions & 1 deletion core/src/test/java/cucumber/runtime/ScenarioResultTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,13 @@ public class ScenarioResultTest {
private ScenarioImpl s = new ScenarioImpl(bus, pickleEvent());

@Test
public void no_steps_is_passed() throws Exception {
public void no_steps_is_undefined() throws Exception {
assertEquals(Result.Type.UNDEFINED, s.getStatus());
}

@Test
public void one_passed_step_is_passed() throws Exception {
s.add(new Result(Result.Type.PASSED, 0L, null));
assertEquals(Result.Type.PASSED, s.getStatus());
}

Expand Down