Skip to content

Commit 9a7147d

Browse files
committed
Merge #1158 'List all not ok scenarios in the summary'
Also update History.md.
2 parents f574ba1 + c5453f7 commit 9a7147d

File tree

6 files changed

+41
-31
lines changed

6 files changed

+41
-31
lines changed

History.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77

88
### New Features
99

10-
* Emulate Cucumber-JS's new i18n CLI options ([#1140(https://api.github.com/repos/cucumber/cucumber-ruby/pulls/1140) @aidamanna)
10+
* List all not ok scenarios in the summary ([#1158](https://github.com/cucumber/cucumber-ruby/pull/1158) @brasmusson)
11+
* Emulate Cucumber-JS's new i18n CLI options ([#1140](https://github.com/cucumber/cucumber-ruby/pull/1140) @aidamanna)
1112
* Use the event bus in Cucumber-Ruby-Core ([#973](https://github.com/cucumber/cucumber-ruby/pull/973) @mattwynne)
1213
* Add --retry option to retry failed tests as part of the same run ([#920](https://github.com/cucumber/cucumber-ruby/pull/920) @DanaScheider)
1314
* Add a summary formatter ([#999](https://github.com/cucumber/cucumber-ruby/pull/999) @mattwynne)

features/docs/cli/dry_run.feature

+3
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

+6
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_counts.rb

+6-19
Original file line numberDiff line numberDiff line change
@@ -6,43 +6,30 @@ class ConsoleCounts
66
include Console
77

88
def initialize(config)
9-
@test_case_summary = Core::Test::Result::Summary.new
10-
@test_step_summary = Core::Test::Result::Summary.new
11-
12-
config.on_event :test_case_finished do |event|
13-
event.result.describe_to @test_case_summary
14-
end
15-
16-
config.on_event :test_step_finished do |event|
17-
event.result.describe_to @test_step_summary if from_gherkin?(event.test_step)
18-
end
9+
@summary = Core::Report::Summary.new(config.event_bus)
1910
end
2011

2112
def to_s
2213
[
23-
[scenario_count, status_counts(@test_case_summary)].compact.join(' '),
24-
[step_count, status_counts(@test_step_summary)].compact.join(' ')
14+
[scenario_count, status_counts(@summary.test_cases)].compact.join(' '),
15+
[step_count, status_counts(@summary.test_steps)].compact.join(' ')
2516
].join("\n")
2617
end
2718

2819
private
2920

30-
def from_gherkin?(test_step)
31-
test_step.source.last.location.file.match(/\.feature$/)
32-
end
33-
3421
def scenario_count
35-
count = @test_case_summary.total
22+
count = @summary.test_cases.total
3623
"#{count} scenario" + (count == 1 ? '' : 's')
3724
end
3825

3926
def step_count
40-
count = @test_step_summary.total
27+
count = @summary.test_steps.total
4128
"#{count} step" + (count == 1 ? '' : 's')
4229
end
4330

4431
def status_counts(summary)
45-
counts = [:failed, :skipped, :undefined, :pending, :passed].map { |status|
32+
counts = Core::Test::Result::TYPES.map { |status|
4633
count = summary.total(status)
4734
[status, count]
4835
}.select { |status, count|

lib/cucumber/formatter/console_issues.rb

+23-9
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 = 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(' ') + ' '

lib/cucumber/runtime.rb

+1-2
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,7 @@ def failure?
229229
if @configuration.wip?
230230
summary_report.test_cases.total_passed > 0
231231
else
232-
summary_report.test_cases.total_failed > 0 || summary_report.test_steps.total_failed > 0 ||
233-
(@configuration.strict? && (summary_report.test_steps.total_undefined > 0 || summary_report.test_steps.total_pending > 0))
232+
!summary_report.ok?(@configuration.strict?)
234233
end
235234
end
236235
public :failure?

0 commit comments

Comments
 (0)