Sha256: c7d4334acca33b8b6768b7171de05cc07a253c28570dc639d34525f6bea46fb8

Contents?: true

Size: 1.5 KB

Versions: 14

Compression:

Stored size: 1.5 KB

Contents

module Lucid
  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, "steps")
        @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

14 entries across 14 versions & 1 rubygems

Version Path
lucid-0.5.1 lib/lucid/formatter/steps.rb
lucid-0.4.1 lib/lucid/formatter/steps.rb
lucid-0.4.0 lib/lucid/formatter/steps.rb
lucid-0.3.3 lib/lucid/formatter/steps.rb
lucid-0.3.0 lib/lucid/formatter/steps.rb
lucid-0.2.1 lib/lucid/formatter/steps.rb
lucid-0.2.0 lib/lucid/formatter/steps.rb
lucid-0.1.1 lib/lucid/formatter/steps.rb
lucid-0.1.0 lib/lucid/formatter/steps.rb
lucid-0.0.9 lib/lucid/formatter/steps.rb
lucid-0.0.8 lib/lucid/formatter/steps.rb
lucid-0.0.7 lib/lucid/formatter/steps.rb
lucid-0.0.6 lib/lucid/formatter/steps.rb
lucid-0.0.5 lib/lucid/formatter/steps.rb