You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

steps.rb 1.6 kB

2 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. # frozen_string_literal: true
  2. require 'cucumber/formatter/console'
  3. module Cucumber
  4. module Formatter
  5. # The formatter used for <tt>--format steps</tt>
  6. class Steps
  7. include Console
  8. def initialize(runtime, path_or_io, options)
  9. @io = ensure_io(path_or_io, nil)
  10. @options = options
  11. @step_definition_files = collect_steps(runtime)
  12. end
  13. def after_features(_features)
  14. print_summary
  15. end
  16. private
  17. def print_summary
  18. count = 0
  19. @step_definition_files.keys.sort.each do |step_definition_file|
  20. @io.puts step_definition_file
  21. sources = @step_definition_files[step_definition_file]
  22. source_indent = source_indent(sources)
  23. sources.sort.each do |file_colon_line, regexp_source|
  24. @io.print indent(regexp_source, 2)
  25. @io.print indent(" # #{file_colon_line}", source_indent - regexp_source.unpack('U*').length)
  26. @io.puts
  27. end
  28. @io.puts
  29. count += sources.size
  30. end
  31. @io.puts "#{count} step definition(s) in #{@step_definition_files.size} source file(s)."
  32. end
  33. def collect_steps(runtime)
  34. runtime.step_definitions.each_with_object({}) do |step_definition, step_definitions|
  35. step_definitions[step_definition.file] ||= []
  36. step_definitions[step_definition.file] << [step_definition.file_colon_line, step_definition.regexp_source]
  37. end
  38. end
  39. def source_indent(sources)
  40. sources.map { |_file_colon_line, regexp| regexp.size }.max + 1
  41. end
  42. end
  43. end
  44. end

No Description

Contributors (1)