Sha256: cb59f7d80962204c926587f056f39da7bbad7186a3fce6b47abcc498c37a9938

Contents?: true

Size: 1.57 KB

Versions: 19

Compression:

Stored size: 1.57 KB

Contents

# frozen_string_literal: true

require 'cucumber/formatter/console'

module Cucumber
  module Formatter
    # The formatter used for <tt>--format steps</tt>
    class Steps
      include Console
      def initialize(runtime, path_or_io, options)
        @io = ensure_io(path_or_io, nil)
        @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 indent(regexp_source, 2)
            @io.print indent(" # #{file_colon_line}", 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.each_with_object({}) do |step_definition, step_definitions|
          step_definitions[step_definition.file] ||= []
          step_definitions[step_definition.file] << [step_definition.file_colon_line, step_definition.regexp_source]
        end
      end

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

Version data entries

19 entries across 19 versions & 4 rubygems

Version Path
cucumber-9.2.1 lib/cucumber/formatter/steps.rb
cucumber-9.2.0 lib/cucumber/formatter/steps.rb
cucumber-9.1.2 lib/cucumber/formatter/steps.rb
cucumber-9.1.1 lib/cucumber/formatter/steps.rb
honeybadger-5.4.0 vendor/bundle/ruby/3.2.0/gems/cucumber-9.1.0/lib/cucumber/formatter/steps.rb
cucumber-9.1.0 lib/cucumber/formatter/steps.rb
honeybadger-5.3.0 vendor/bundle/ruby/3.2.0/gems/cucumber-9.0.2/lib/cucumber/formatter/steps.rb
cucumber-9.0.2 lib/cucumber/formatter/steps.rb
cucumber-9.0.1 lib/cucumber/formatter/steps.rb
cucumber-9.0.0 lib/cucumber/formatter/steps.rb
rubypitaya-3.12.5 ./lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/cucumber-8.0.0/lib/cucumber/formatter/steps.rb
rubypitaya-3.12.4 ./lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/cucumber-8.0.0/lib/cucumber/formatter/steps.rb
rubypitaya-3.12.3 ./lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/cucumber-8.0.0/lib/cucumber/formatter/steps.rb
rubypitaya-3.12.2 ./lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/cucumber-8.0.0/lib/cucumber/formatter/steps.rb
cucumber-8.0.0 lib/cucumber/formatter/steps.rb
cucumber-8.0.0.rc.1 lib/cucumber/formatter/steps.rb
phillipug-foodie-0.1.0 .vendor/ruby/3.0.0/gems/cucumber-7.1.0/lib/cucumber/formatter/steps.rb
cucumber-7.1.0 lib/cucumber/formatter/steps.rb
cucumber-7.0.0 lib/cucumber/formatter/steps.rb