Sha256: 68f5cd7b48ebc2b44a76e331c685ad90b5f37d28bfbb3008f41e00ac0dd0563c

Contents?: true

Size: 1.07 KB

Versions: 5

Compression:

Stored size: 1.07 KB

Contents

require 'cucumber/formatter/console'

module Cucumber
  module Formatter
    class ConsoleCounts
      include Console

      def initialize(config)
        @summary = Core::Report::Summary.new(config.event_bus)
      end

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

      private

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

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

      def status_counts(summary)
        counts = Core::Test::Result::TYPES.map { |status|
          count = summary.total(status)
          [status, count]
        }.select { |status, count|
          count > 0
        }.map { |status, count|
          format_string("#{count} #{status}", status)
        }
        "(#{counts.join(", ")})" if counts.any?
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
cucumber-3.1.0 lib/cucumber/formatter/console_counts.rb
cucumber-3.0.2 lib/cucumber/formatter/console_counts.rb
cucumber-3.0.1 lib/cucumber/formatter/console_counts.rb
cucumber-3.0.0 lib/cucumber/formatter/console_counts.rb
cucumber-3.0.0.pre.2 lib/cucumber/formatter/console_counts.rb