Sha256: 1824b0bf71682b0f8cc89eb6dc2177ae8f47de28834cddc12198d3b343953e36

Contents?: true

Size: 1.52 KB

Versions: 4

Compression:

Stored size: 1.52 KB

Contents

# frozen_string_literal: true

module Cucumber
  module Formatter
    # The formatter used for <tt>--format steps</tt>
    class Steps
      def initialize(runtime, path_or_io, options)
        @io = ensure_io(path_or_io)
        @options = options
        @step_definition_files = collect_steps(runtime)
      end

      def after_features(_features)
        print_summary
      end

      private

      def print_summary
        count = 0
        @step_definition_files.keys.sort.each do |step_definition_file|
          @io.puts step_definition_file

          sources = @step_definition_files[step_definition_file]
          source_indent = source_indent(sources)
          sources.sort.each do |file_colon_line, regexp_source|
            @io.print regexp_source.indent(2)
            @io.print " # #{file_colon_line}".indent(source_indent - regexp_source.unpack('U*').length)
            @io.puts
          end
          @io.puts
          count += sources.size
        end
        @io.puts "#{count} step definition(s) in #{@step_definition_files.size} source file(s)."
      end

      def collect_steps(runtime)
        runtime.step_definitions.inject({}) do |step_definitions, step_definition|
          step_definitions[step_definition.file] ||= []
          step_definitions[step_definition.file] << [step_definition.file_colon_line, step_definition.regexp_source]
          step_definitions
        end
      end

      def source_indent(sources)
        sources.map { |file_colon_line, regexp| regexp.size }.max + 1
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 2 rubygems

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