Sha256: 5be0a76686e07a6aa8e3ebe7d02e1655885ad78081b6fb264c1b49eb12b9d627

Contents?: true

Size: 1.52 KB

Versions: 24

Compression:

Stored size: 1.52 KB

Contents

module Cucumber
  module Formatter
    # The formatter used for <tt>--format steps</tt>
    class Steps

      def initialize(step_mother, path_or_io, options)
        @io = ensure_io(path_or_io, "steps")
        @options = options
        @step_definition_files = collect_steps(step_mother)
      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.jlength)
            @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(step_mother)
        step_mother.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

24 entries across 24 versions & 3 rubygems

Version Path
cucumber-0.7.2 lib/cucumber/formatter/steps.rb
cucumber-0.7.1 lib/cucumber/formatter/steps.rb
cucumber-0.7.0 lib/cucumber/formatter/steps.rb
cucumber-0.7.0.beta.8 lib/cucumber/formatter/steps.rb
cucumber-0.7.0.beta.7 lib/cucumber/formatter/steps.rb
cucumber-0.7.0.beta.6 lib/cucumber/formatter/steps.rb
cucumber-0.7.0.beta.5 lib/cucumber/formatter/steps.rb
cucumber-0.7.0.beta.4 lib/cucumber/formatter/steps.rb
cucumber-0.7.0.beta.3 lib/cucumber/formatter/steps.rb
cucumber-0.7.0.beta.2 lib/cucumber/formatter/steps.rb
cucumber-0.7.0.beta.1 lib/cucumber/formatter/steps.rb
cucumber-0.6.4 lib/cucumber/formatter/steps.rb
cucumber-0.6.3 lib/cucumber/formatter/steps.rb
davidtrogers-cucumber-0.6.2 lib/cucumber/formatter/steps.rb
cucumber-0.6.2 lib/cucumber/formatter/steps.rb
cucumber-0.6.1 lib/cucumber/formatter/steps.rb
cucumber-0.6.0 lib/cucumber/formatter/steps.rb
cucumber-0.5.3 lib/cucumber/formatter/steps.rb
cucumber-0.5.2 lib/cucumber/formatter/steps.rb
cucumber-0.5.1 lib/cucumber/formatter/steps.rb