Module: TestRunHelper

Included in:
ProjectNotification
Defined in:
app/helpers/test_run_helper.rb

Instance Method Summary collapse

Instance Method Details

#commit_test_status(test_run, test_result) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'app/helpers/test_run_helper.rb', line 36

def commit_test_status(test_run, test_result)
  status = test_result.status if test_result
  status = "untested" if test_run.nil?
  status = "pending" if test_run && test_run.pending?
  status = "aborted" if test_run && test_run.aborted?
  status ||= "unknown"

  css = "project-test-status project-test-status-#{status}"

  if test_run
    link_to status, test_run_url(slug: test_run.project.slug, commit: test_run.sha), class: css
  else
    "<span class=\"#{css}\">#{status}</span>".html_safe
  end
end

#test_results_count(test) ⇒ Object



60
61
62
# File 'app/helpers/test_run_helper.rb', line 60

def test_results_count(test)
  test[:results].count { |result| !result.nil? }
end

#test_results_fail_count(test) ⇒ Object



56
57
58
# File 'app/helpers/test_run_helper.rb', line 56

def test_results_fail_count(test)
  test[:results].count { |result| result == "fail" }
end

#test_results_graph(test) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
# File 'app/helpers/test_run_helper.rb', line 64

def test_results_graph(test)
  html = "<svg class=\"dot-graph\">"
  percent = 100 / test[:results].length.to_f
  left = 0
  test[:results].reverse_each do |result|
    html << "<rect x=\"#{left}%\" y=\"0\" rx=\"2\" ry=\"2\" width=\"#{percent}%\" height=\"100%\" class=\"dot-graph-rect #{result}\" data-index=\"0\"></rect>" if result
    left += percent
  end
  html << "</svg>"
  html.html_safe
end

#test_results_pass_count(test) ⇒ Object



52
53
54
# File 'app/helpers/test_run_helper.rb', line 52

def test_results_pass_count(test)
  test[:results].count { |result| result == "pass" }
end

#test_run_fail_summary(test_run) ⇒ Object



28
29
30
31
32
33
34
# File 'app/helpers/test_run_helper.rb', line 28

def test_run_fail_summary(test_run)
  if test_run.real_fail_count.zero?
    "the build exited unsuccessfully after running #{test_run.total_count} #{test_run.total_count == 1 ? "test" : "tests"}"
  else
    "#{test_run.real_fail_count} #{test_run.real_fail_count == 1 ? "test" : "tests"} failed"
  end
end

#test_run_summary(test_run) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/helpers/test_run_helper.rb', line 13

def test_run_summary(test_run)
  subject = {
    "pass" => "#{test_run.total_count} tests passed!",
    "fail" => test_run_fail_summary(test_run),
    "error" => "tests are broken",
    "aborted" => "aborted"
  }.fetch(
    test_run.result.to_s,
    (test_run.created_at ? "started #{distance_of_time_in_words(test_run.created_at, Time.now)} ago" : ""))

  subject << " [#{test_run.branch}]" if test_run.branch

  subject
end

#test_status(test) ⇒ Object



3
4
5
6
7
8
9
10
11
# File 'app/helpers/test_run_helper.rb', line 3

def test_status(test)
  case test[:status].to_s
  when "pass"; "pass"
  when "skip"; "skip"
  when "fail", "regression"; "fail"
  else
    raise NotImplementedError.new "TestRunHelper#test_status doesn't know about the status #{test[:status].inspect}"
  end
end