Sha256: ad916394b9b3d82a38b361bc07b77ce829f19519f202ec0e819091a8283816a2

Contents?: true

Size: 1.75 KB

Versions: 4

Compression:

Stored size: 1.75 KB

Contents

require 'cucumber/formatter/console'

module Cucumber
  module Formatter
    class ConsoleIssues
      include Console

      def initialize(config)
        @previous_test_case = nil
        @issues = Hash.new { |h, k| h[k] = [] }
        @config = config
        @config.on_event(:test_case_finished) do |event|
          if event.test_case != @previous_test_case
            @previous_test_case = event.test_case
            @issues[event.result.to_sym] << event.test_case unless event.result.ok?(@config.strict)
          elsif event.result.passed?
            @issues[:flaky] << event.test_case unless Core::Test::Result::Flaky.ok?(@config.strict.strict?(:flaky))
            @issues[:failed].delete(event.test_case)
          end
        end
      end

      def to_s
        return if @issues.empty?
        result = Core::Test::Result::TYPES.map { |type| scenario_listing(type, @issues[type]) }
        result.flatten.join("\n")
      end

      def 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 do |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
      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(' ') + ' '
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 2 rubygems

Version Path
cucumber-3.2.0 lib/cucumber/formatter/console_issues.rb
honeybadger-4.5.3 vendor/bundle/ruby/2.6.0/gems/cucumber-3.1.2/lib/cucumber/formatter/console_issues.rb
cucumber-3.1.2 lib/cucumber/formatter/console_issues.rb
cucumber-3.1.1 lib/cucumber/formatter/console_issues.rb