diff --git a/features/docs/cli/dry_run.feature b/features/docs/cli/dry_run.feature index 42f644a6ce..544eb881b5 100644 --- a/features/docs/cli/dry_run.feature +++ b/features/docs/cli/dry_run.feature @@ -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) diff --git a/features/docs/cli/strict_mode.feature b/features/docs/cli/strict_mode.feature index 755a04091b..a15256c27e 100644 --- a/features/docs/cli/strict_mode.feature +++ b/features/docs/cli/strict_mode.feature @@ -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) """ @@ -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) """ diff --git a/lib/cucumber/formatter/console_counts.rb b/lib/cucumber/formatter/console_counts.rb index 00ebf932aa..90991c7402 100644 --- a/lib/cucumber/formatter/console_counts.rb +++ b/lib/cucumber/formatter/console_counts.rb @@ -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| diff --git a/lib/cucumber/formatter/console_issues.rb b/lib/cucumber/formatter/console_issues.rb index 0b7766a845..e6520cdd36 100644 --- a/lib/cucumber/formatter/console_issues.rb +++ b/lib/cucumber/formatter/console_issues.rb @@ -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(' ') + ' ' diff --git a/lib/cucumber/runtime.rb b/lib/cucumber/runtime.rb index 2a80b3b426..72679d5d1a 100644 --- a/lib/cucumber/runtime.rb +++ b/lib/cucumber/runtime.rb @@ -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?