Class: ParallelCucumber::ResultFormatter

Inherits:
Object
  • Object
show all
Defined in:
lib/parallel_cucumber/result_formatter.rb

Class Method Summary collapse

Class Method Details

.find_results(test_output) ⇒ Object



10
11
12
13
14
15
16
# File 'lib/parallel_cucumber/result_formatter.rb', line 10

def find_results(test_output)
  test_output.split("\n").map do |line|
    line.gsub!(/\e\[\d+m/, '')
    next unless line_is_result?(line)
    line
  end.compact
end

.line_is_result?(line) ⇒ Boolean



18
19
20
# File 'lib/parallel_cucumber/result_formatter.rb', line 18

def line_is_result?(line)
  line =~ scenario_or_step_result_regex || line =~ failing_scenario_regex
end

.report_results(test_results) ⇒ Object



4
5
6
7
8
# File 'lib/parallel_cucumber/result_formatter.rb', line 4

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



53
54
55
56
57
58
59
# File 'lib/parallel_cucumber/result_formatter.rb', line 53

def sum_up_results(results)
  results = results.join(' ').gsub(/s\b/, '') # combine and singularize results
  counts = results.scan(/(\d+) (\w+)/)
  counts.each_with_object(Hash.new(0)) do |(number, word), sum|
    sum[word] += number.to_i
  end
end

.summarize_results(results) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/parallel_cucumber/result_formatter.rb', line 22

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



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/parallel_cucumber/result_formatter.rb', line 36

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 && number != 1
      "#{number} #{word}#{plural}"
    end
    "#{sums[0]} (#{sums[1..-1].join(', ')})"
  end.compact.join("\n")
end