Class: ParallelCalabash::ResultFormatter
- Inherits:
-
Object
- Object
- ParallelCalabash::ResultFormatter
- Defined in:
- lib/parallel_calabash/result_formatter.rb
Class Method Summary collapse
- .find_results(test_output) ⇒ Object
- .line_is_result?(line) ⇒ Boolean
- .report_results(test_results) ⇒ Object
- .sum_up_results(results) ⇒ Object
- .summarize_results(results) ⇒ Object
- .summary(results) ⇒ Object
Class Method Details
.find_results(test_output) ⇒ Object
12 13 14 15 16 17 18 |
# File 'lib/parallel_calabash/result_formatter.rb', line 12 def find_results(test_output) test_output.split("\n").map { |line| line.gsub!(/\e\[\d+m/, '') next unless line_is_result?(line) line }.compact end |
.line_is_result?(line) ⇒ Boolean
20 21 22 |
# File 'lib/parallel_calabash/result_formatter.rb', line 20 def line_is_result?(line) line =~scenario_or_step_result_regex or line =~ failing_scenario_regex end |
.report_results(test_results) ⇒ Object
6 7 8 9 10 |
# File 'lib/parallel_calabash/result_formatter.rb', line 6 def report_results(test_results) results = find_results(test_results.map { |result| result[:stdout] }.join('')) puts '' puts summarize_results(results) end |
.sum_up_results(results) ⇒ Object
56 57 58 59 60 61 62 63 |
# File 'lib/parallel_calabash/result_formatter.rb', line 56 def sum_up_results(results) results = results.join(' ').gsub(/s\b/, '') # combine and singularize results counts = results.scan(/(\d+) (\w+)/) counts.inject(Hash.new(0)) do |sum, (number, word)| sum[word] += number.to_i sum end end |
.summarize_results(results) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/parallel_calabash/result_formatter.rb', line 24 def summarize_results(results) output = ["\n\n************ FINAL SUMMARY ************"] failing_scenarios = results.grep(failing_scenario_regex) if failing_scenarios.any? failing_scenarios.unshift("Failing Scenarios:") output << failing_scenarios.join("\n") end output << summary(results) output.join("\n\n") end |
.summary(results) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/parallel_calabash/result_formatter.rb', line 39 def summary(results) sort_order = %w[scenario step failed undefined skipped pending passed] %w[scenario step].map do |group| group_results = results.grep(/^\d+ #{group}/) next if group_results.empty? sums = sum_up_results(group_results) sums = sums.sort_by { |word, _| sort_order.index(word) || 999 } sums.map! do |word, number| plural = "s" if word == group and number != 1 "#{number} #{word}#{plural}" end "#{sums[0]} (#{sums[1..-1].join(", ")})" end.compact.join("\n") end |