Class: CucumberStatistics::RendererHelper

Inherits:
Object
  • Object
show all
Defined in:
lib/cucumber_statistics/renderer_helper.rb

Instance Method Summary collapse

Instance Method Details

#alert_info_text(overall_statistics) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/cucumber_statistics/renderer_helper.rb', line 31

def alert_info_text(overall_statistics)
  <<-HTML
      <span>
        #{overall_statistics.feature_count} Features,
        #{overall_statistics.scenario_count} Scenarios,
        #{overall_statistics.step_count} Steps completed in #{format(overall_statistics.duration)}.
        <span class='text-muted pull-right small'>
          Finished on #{format_date_time(overall_statistics.end_time)}
        </span>
      </span>
  HTML
end

#count_td(results, metric) ⇒ Object



58
59
60
61
# File 'lib/cucumber_statistics/renderer_helper.rb', line 58

def count_td(results, metric)
  value = results[1][metric]
  %{<td data-value="#{value}">#{value}</td>}
end

#format(ts) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/cucumber_statistics/renderer_helper.rb', line 63

def format (ts)

  return '-' if ts.nil? || ts == 0

  #find the seconds
  seconds = ts % 60

  #find the minutes
  minutes = (ts / 60) % 60

  #find the hours
  hours = (ts/3600)

  formatted_h = hours.to_i
  formatted_m = minutes.to_i
  formatted_s = seconds.to_i
  formatted_ms = Time.at(seconds).utc.strftime("%3N")

  # http://apidock.com/ruby/DateTime/strftime
  if hours >= 1
    #result = Time.at(ts).utc.strftime("%Hh %Mm %S.%3Ns")
    result = "#{formatted_h}h #{formatted_m}m #{formatted_s}.#{formatted_ms}s"
  elsif minutes >= 1
    #result = Time.at(ts).utc.strftime("%Mm %S.%3Ns")
    result = "#{formatted_m}m #{formatted_s}.#{formatted_ms}s"
  elsif formatted_ms.to_i == 0 && formatted_s == 0 && formatted_h == 0
    result = "< #{formatted_s}.#{formatted_ms}s"
  else
    #result = Time.at(ts).utc.strftime("%S.%3Ns")
    result = "#{formatted_s}.#{formatted_ms}s"
  end

  result
end

#format_date_time(time) ⇒ Object



98
99
100
# File 'lib/cucumber_statistics/renderer_helper.rb', line 98

def format_date_time (time)
  time.strftime("%m/%d/%Y at %I:%M%p")
end

#name_td(results) ⇒ Object



5
6
7
# File 'lib/cucumber_statistics/renderer_helper.rb', line 5

def name_td(results)
  %{<td title="#{results[1][:file]}">#{results[0]}</td>}
end

#scenario_file_td(name, scenario_name) ⇒ Object



9
10
11
# File 'lib/cucumber_statistics/renderer_helper.rb', line 9

def scenario_file_td(name, scenario_name)
  %{<td title="#{scenario_name}">#{name}</td>}
end

#scenario_time_td(duration) ⇒ Object



23
24
25
# File 'lib/cucumber_statistics/renderer_helper.rb', line 23

def scenario_time_td(duration)
  %{<td data-value="#{duration}" title="#{duration}">#{format(duration)}</td>}
end

#std_file_td(file_name, name) ⇒ Object



13
14
15
# File 'lib/cucumber_statistics/renderer_helper.rb', line 13

def std_file_td(file_name, name)
  %{<td title="#{name}">#{file_name}</td>}
end

#std_time_td(duration) ⇒ Object



27
28
29
# File 'lib/cucumber_statistics/renderer_helper.rb', line 27

def std_time_td(duration)
  %{<td data-value="#{duration}" title="#{duration}">#{format(duration)}</td>}
end

#time_td(results, metric, *warning_results) ⇒ Object



17
18
19
20
21
# File 'lib/cucumber_statistics/renderer_helper.rb', line 17

def time_td(results, metric, *warning_results)
  duration = results[1][metric]

  %{<td #{warning_class(results, warning_results)} data-value="#{duration}" title="#{duration}">#{format(duration)}</td>}
end

#warning_class(results, warning_results) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/cucumber_statistics/renderer_helper.rb', line 44

def warning_class(results, warning_results)

  if warning_results.nil? || warning_results.empty?
    should_warn = false
  else
    should_warn = (results[0].eql? warning_results[0][0])
  end
  if should_warn
    %{class="danger"}
  else
    ''
  end
end