Class: Knapsack::Presenter

Inherits:
Object
  • Object
show all
Defined in:
lib/knapsack/presenter.rb

Class Method Summary collapse

Class Method Details

.exceeded_timeObject



33
34
35
36
# File 'lib/knapsack/presenter.rb', line 33

def exceeded_time
  exceeded_time = pretty_seconds(Knapsack.tracker.exceeded_time)
  "Exceeded time: #{exceeded_time}"
end

.global_timeObject



19
20
21
22
# File 'lib/knapsack/presenter.rb', line 19

def global_time
  global_time = pretty_seconds(Knapsack.tracker.global_time)
  "\nKnapsack global time execution for tests: #{global_time}"
end

.max_allowed_node_time_executionObject



28
29
30
31
# File 'lib/knapsack/presenter.rb', line 28

def max_allowed_node_time_execution
  max_node_time_execution = pretty_seconds(Knapsack.tracker.max_node_time_execution)
  "Max allowed node time execution: #{max_node_time_execution}"
end

.pretty_seconds(seconds) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/knapsack/presenter.rb', line 62

def pretty_seconds(seconds)
  sign = ''

  if seconds < 0
    seconds = seconds*-1
    sign = '-'
  end

  return "#{sign}#{seconds}s" if seconds.abs < 1

  time = Time.at(seconds).gmtime.strftime('%Hh %Mm %Ss')
  time_without_zeros = time.gsub(/00(h|m|s)/, '').strip
  sign + time_without_zeros
end

.report_detailsObject



15
16
17
# File 'lib/knapsack/presenter.rb', line 15

def report_details
  "Knapsack report was generated. Preview:\n" + Presenter.report_json
end

.report_jsonObject



11
12
13
# File 'lib/knapsack/presenter.rb', line 11

def report_json
  JSON.pretty_generate(Knapsack.tracker.test_files_with_time)
end

.report_ymlObject



7
8
9
# File 'lib/knapsack/presenter.rb', line 7

def report_yml
  Knapsack.tracker.test_files_with_time.to_yaml
end

.time_offsetObject



24
25
26
# File 'lib/knapsack/presenter.rb', line 24

def time_offset
  "Time offset: #{Knapsack.tracker.config[:time_offset_in_seconds]}s"
end

.time_offset_warningObject



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/knapsack/presenter.rb', line 38

def time_offset_warning
  str = %{\n========= Knapsack Time Offset Warning ==========
#{Presenter.time_offset}
#{Presenter.max_allowed_node_time_execution}
#{Presenter.exceeded_time}
  }
  if Knapsack.tracker.time_exceeded?
    str << %{
Tests on this CI node took more than time offset.
Please regenerate your knapsack report.
If that didn't help then split your heavy test file
or bump time_offset_in_seconds setting.}
  else
    str << %{
Global time execution for this CI node is fine.
Happy testing!}
  end
  str << "\n=================================================\n"
  str << %{Sign up for beta Knapsack Pro here:
http://knapsack.launchrock.com}
  str << "\n=================================================\n"
  str
end