Skip to content

List all not ok scenarios in the summary #1158

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

Merged
merged 3 commits into from
Jul 14, 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
3 changes: 3 additions & 0 deletions features/docs/cli/dry_run.feature
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ Feature: Dry Run
Undefined step: "this step is undefined" (Cucumber::Undefined)
features/test.feature:3:in `Given this step is undefined'

Undefined Scenarios:
cucumber features/test.feature:2 # Scenario:

1 scenario (1 undefined)
1 step (1 undefined)

Expand Down
6 changes: 6 additions & 0 deletions features/docs/cli/strict_mode.feature
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ Feature: Strict mode
Undefined step: "this step passes" (Cucumber::Undefined)
features/missing.feature:3:in `Given this step passes'

Undefined Scenarios:
cucumber features/missing.feature:2

1 scenario (1 undefined)
1 step (1 undefined)
"""
Expand All @@ -45,6 +48,9 @@ Feature: Strict mode
./features/step_definitions/steps.rb:3:in `/^this step is pending$/'
features/pending.feature:3:in `Given this step is pending'

Pending Scenarios:
cucumber features/pending.feature:2

1 scenario (1 pending)
1 step (1 pending)
"""
Expand Down
25 changes: 6 additions & 19 deletions lib/cucumber/formatter/console_counts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,43 +6,30 @@ class ConsoleCounts
include Console

def initialize(config)
@test_case_summary = Core::Test::Result::Summary.new
@test_step_summary = Core::Test::Result::Summary.new

config.on_event :test_case_finished do |event|
event.result.describe_to @test_case_summary
end

config.on_event :test_step_finished do |event|
event.result.describe_to @test_step_summary if from_gherkin?(event.test_step)
end
@summary = Core::Report::Summary.new(config.event_bus)
end

def to_s
[
[scenario_count, status_counts(@test_case_summary)].compact.join(' '),
[step_count, status_counts(@test_step_summary)].compact.join(' ')
[scenario_count, status_counts(@summary.test_cases)].compact.join(' '),
[step_count, status_counts(@summary.test_steps)].compact.join(' ')
].join("\n")
end

private

def from_gherkin?(test_step)
test_step.source.last.location.file.match(/\.feature$/)
end

def scenario_count
count = @test_case_summary.total
count = @summary.test_cases.total
"#{count} scenario" + (count == 1 ? '' : 's')
end

def step_count
count = @test_step_summary.total
count = @summary.test_steps.total
"#{count} step" + (count == 1 ? '' : 's')
end

def status_counts(summary)
counts = [:failed, :skipped, :undefined, :pending, :passed].map { |status|
counts = Core::Test::Result::TYPES.map { |status|
count = summary.total(status)
[status, count]
}.select { |status, count|
Expand Down
32 changes: 23 additions & 9 deletions lib/cucumber/formatter/console_issues.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,42 @@ class ConsoleIssues
include Console

def initialize(config)
@failures = []
@issues = Hash.new { |h, k| h[k] = [] }
@config = config
@config.on_event(:test_case_finished) do |event|
@failures << event.test_case if event.result.failed?
@issues[event.result.to_sym] << event.test_case unless event.result.ok?(@config.strict?)
end
end

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

def any?
@failures.any?
@issues.any?
end

private

def scenario_listing(type, test_cases)
return [] if test_cases.empty?
[ format_string("#{type_heading(type)} Scenarios:", type) ] + test_cases.map { |test_case|
source = @config.source? ? format_string(" # #{test_case.keyword}: #{test_case.name}", :comment) : ''
format_string("cucumber #{profiles_string}" + test_case.location, type) + source
}
end

def type_heading(type)
case type
when :failed
'Failing'
else
type.to_s.slice(0, 1).capitalize + type.to_s.slice(1..-1)
end
end

def profiles_string
return if @config.custom_profiles.empty?
@config.custom_profiles.map { |profile| "-p #{profile}" }.join(' ') + ' '
Expand Down
3 changes: 1 addition & 2 deletions lib/cucumber/runtime.rb
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,7 @@ def failure?
if @configuration.wip?
summary_report.test_cases.total_passed > 0
else
summary_report.test_cases.total_failed > 0 || summary_report.test_steps.total_failed > 0 ||
(@configuration.strict? && (summary_report.test_steps.total_undefined > 0 || summary_report.test_steps.total_pending > 0))
!summary_report.ok?(@configuration.strict?)
end
end
public :failure?
Expand Down