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.

progress.rb 3.8 kB

2 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. # frozen_string_literal: true
  2. require 'cucumber/formatter/backtrace_filter'
  3. require 'cucumber/formatter/console'
  4. require 'cucumber/formatter/console_counts'
  5. require 'cucumber/formatter/console_issues'
  6. require 'cucumber/formatter/io'
  7. require 'cucumber/formatter/duration_extractor'
  8. require 'cucumber/formatter/ast_lookup'
  9. module Cucumber
  10. module Formatter
  11. # The formatter used for <tt>--format progress</tt>
  12. class Progress
  13. include Console
  14. include Io
  15. attr_reader :config, :current_feature_uri
  16. private :config, :current_feature_uri
  17. def initialize(config)
  18. @config = config
  19. @io = ensure_io(config.out_stream, config.error_stream)
  20. @snippets_input = []
  21. @undefined_parameter_types = []
  22. @total_duration = 0
  23. @matches = {}
  24. @pending_step_matches = []
  25. @failed_results = []
  26. @passed_test_cases = []
  27. @current_feature_uri = ''
  28. @gherkin_documents = {}
  29. @ast_lookup = AstLookup.new(config)
  30. @counts = ConsoleCounts.new(config)
  31. @issues = ConsoleIssues.new(config, @ast_lookup)
  32. config.on_event :step_activated, &method(:on_step_activated)
  33. config.on_event :test_case_started, &method(:on_test_case_started)
  34. config.on_event :test_step_finished, &method(:on_test_step_finished)
  35. config.on_event :test_case_finished, &method(:on_test_case_finished)
  36. config.on_event :test_run_finished, &method(:on_test_run_finished)
  37. config.on_event :undefined_parameter_type, &method(:collect_undefined_parameter_type_names)
  38. end
  39. def on_step_activated(event)
  40. @matches[event.test_step.to_s] = event.step_match
  41. end
  42. def on_test_case_started(event)
  43. unless @profile_information_printed
  44. do_print_profile_information(config.profiles) unless config.skip_profile_information? || config.profiles.nil? || config.profiles.empty?
  45. @profile_information_printed = true
  46. end
  47. @current_feature_uri = event.test_case.location.file
  48. end
  49. def on_test_step_finished(event)
  50. test_step = event.test_step
  51. result = event.result.with_filtered_backtrace(Cucumber::Formatter::BacktraceFilter)
  52. progress(result.to_sym) if !test_step.hook? || result.failed?
  53. return if test_step.hook?
  54. collect_snippet_data(test_step, @ast_lookup) if result.undefined?
  55. @pending_step_matches << @matches[test_step.to_s] if result.pending?
  56. @failed_results << result if result.failed?
  57. end
  58. def on_test_case_finished(event)
  59. test_case = event.test_case
  60. result = event.result.with_filtered_backtrace(Cucumber::Formatter::BacktraceFilter)
  61. @passed_test_cases << test_case if result.passed?
  62. @total_duration += DurationExtractor.new(result).result_duration
  63. end
  64. def on_test_run_finished(_event)
  65. @io.puts
  66. @io.puts
  67. print_summary
  68. end
  69. private
  70. def gherkin_document
  71. @ast_lookup.gherkin_document(current_feature_uri)
  72. end
  73. def print_summary
  74. print_elements(@pending_step_matches, :pending, 'steps')
  75. print_elements(@failed_results, :failed, 'steps')
  76. print_statistics(@total_duration, @config, @counts, @issues)
  77. print_snippets(config.to_hash)
  78. print_passing_wip(config, @passed_test_cases, @ast_lookup)
  79. end
  80. CHARS = {
  81. passed: '.',
  82. failed: 'F',
  83. undefined: 'U',
  84. pending: 'P',
  85. skipped: '-'
  86. }.freeze
  87. def progress(status)
  88. char = CHARS[status]
  89. @io.print(format_string(char, status))
  90. @io.flush
  91. end
  92. def table_header_cell?(status)
  93. status == :skipped_param
  94. end
  95. TestCaseData = Struct.new(:name, :location)
  96. end
  97. end
  98. end

No Description

Contributors (1)