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.

rerun.rb 1.6 kB

2 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. # frozen_string_literal: true
  2. require 'cucumber/formatter/io'
  3. module Cucumber
  4. module Formatter
  5. class Rerun
  6. include Formatter::Io
  7. def initialize(config)
  8. @io = ensure_io(config.out_stream, config.error_stream)
  9. @config = config
  10. @failures = {}
  11. config.on_event :test_case_finished do |event|
  12. test_case, result = *event.attributes
  13. if @config.strict.strict?(:flaky)
  14. next if result.ok?(@config.strict)
  15. add_to_failures(test_case)
  16. else
  17. unless @latest_failed_test_case.nil?
  18. if @latest_failed_test_case != test_case
  19. add_to_failures(@latest_failed_test_case)
  20. @latest_failed_test_case = nil
  21. elsif result.ok?(@config.strict)
  22. @latest_failed_test_case = nil
  23. end
  24. end
  25. @latest_failed_test_case = test_case unless result.ok?(@config.strict)
  26. end
  27. end
  28. config.on_event :test_run_finished do
  29. add_to_failures(@latest_failed_test_case) unless @latest_failed_test_case.nil?
  30. next if @failures.empty?
  31. @io.print file_failures.join("\n")
  32. end
  33. end
  34. private
  35. def file_failures
  36. @failures.map { |file, lines| [file, lines].join(':') }
  37. end
  38. def add_to_failures(test_case)
  39. location = test_case.location
  40. @failures[location.file] ||= []
  41. @failures[location.file] << location.lines.max unless @failures[location.file].include?(location.lines.max)
  42. end
  43. end
  44. end
  45. end

No Description

Contributors (1)