Skip to content

Commit 73a660a

Browse files
committed
Reduce duplication between ConsoleCounts and Cucumber-Ruby-Core
Use the Cucumber::Core::Test::Result::TYPES and Cucumber::Core::Report::Summary to reduce the duplication between ConsoleCounts and Cucumber-Ruby-Core.
1 parent c2b8bd1 commit 73a660a

File tree

1 file changed

+6
-19
lines changed

1 file changed

+6
-19
lines changed

lib/cucumber/formatter/console_counts.rb

Lines changed: 6 additions & 19 deletions
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 = Cucumber::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 = Cucumber::Core::Test::Result::TYPES.map { |status|
4633
count = summary.total(status)
4734
[status, count]
4835
}.select { |status, count|

0 commit comments

Comments
 (0)