Skip to content

Commit c2b8bd1

Browse files
committed
List all scenarios making the exit code non-zero
Currently only failed scenarios are listed in the summary, but also scenarios of other result types can force the exit code to be non-zero. Therefore list the scenarios of all result type the each would have made the exit code non-zero.
1 parent f574ba1 commit c2b8bd1

File tree

3 files changed

+32
-9
lines changed

3 files changed

+32
-9
lines changed

features/docs/cli/dry_run.feature

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ Feature: Dry Run
6464
Undefined step: "this step is undefined" (Cucumber::Undefined)
6565
features/test.feature:3:in `Given this step is undefined'
6666
67+
Undefined Scenarios:
68+
cucumber features/test.feature:2 # Scenario:
69+
6770
1 scenario (1 undefined)
6871
1 step (1 undefined)
6972

features/docs/cli/strict_mode.feature

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ Feature: Strict mode
2828
Undefined step: "this step passes" (Cucumber::Undefined)
2929
features/missing.feature:3:in `Given this step passes'
3030
31+
Undefined Scenarios:
32+
cucumber features/missing.feature:2
33+
3134
1 scenario (1 undefined)
3235
1 step (1 undefined)
3336
"""
@@ -45,6 +48,9 @@ Feature: Strict mode
4548
./features/step_definitions/steps.rb:3:in `/^this step is pending$/'
4649
features/pending.feature:3:in `Given this step is pending'
4750
51+
Pending Scenarios:
52+
cucumber features/pending.feature:2
53+
4854
1 scenario (1 pending)
4955
1 step (1 pending)
5056
"""

lib/cucumber/formatter/console_issues.rb

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,42 @@ class ConsoleIssues
66
include Console
77

88
def initialize(config)
9-
@failures = []
9+
@issues = Hash.new { |h, k| h[k] = [] }
1010
@config = config
1111
@config.on_event(:test_case_finished) do |event|
12-
@failures << event.test_case if event.result.failed?
12+
@issues[event.result.to_sym] << event.test_case unless event.result.ok?(@config.strict?)
1313
end
1414
end
1515

1616
def to_s
17-
return if @failures.empty?
18-
result = [ format_string('Failing Scenarios:', :failed) ] + @failures.map { |failure|
19-
source = @config.source? ? format_string(" # #{failure.keyword}: #{failure.name}", :comment) : ''
20-
format_string("cucumber #{profiles_string}" + failure.location, :failed) + source
21-
}
22-
result.join("\n")
17+
return if @issues.empty?
18+
result = Cucumber::Core::Test::Result::TYPES.map { |type| scenario_listing(type, @issues[type]) }
19+
result.flatten.join("\n")
2320
end
2421

2522
def any?
26-
@failures.any?
23+
@issues.any?
2724
end
2825

2926
private
3027

28+
def scenario_listing(type, test_cases)
29+
return [] if test_cases.empty?
30+
[ format_string("#{type_heading(type)} Scenarios:", type) ] + test_cases.map { |test_case|
31+
source = @config.source? ? format_string(" # #{test_case.keyword}: #{test_case.name}", :comment) : ''
32+
format_string("cucumber #{profiles_string}" + test_case.location, type) + source
33+
}
34+
end
35+
36+
def type_heading(type)
37+
case type
38+
when :failed
39+
'Failing'
40+
else
41+
type.to_s.slice(0, 1).capitalize + type.to_s.slice(1..-1)
42+
end
43+
end
44+
3145
def profiles_string
3246
return if @config.custom_profiles.empty?
3347
@config.custom_profiles.map { |profile| "-p #{profile}" }.join(' ') + ' '

0 commit comments

Comments
 (0)