Module: Omnitest::Command::Generate::Dashboard::Helpers

Includes:
Omnitest::Core::Util::String, Padrino::Helpers::AssetTagHelpers, Padrino::Helpers::OutputHelpers, Padrino::Helpers::TagHelpers
Included in:
Omnitest::Command::Generate::Dashboard
Defined in:
lib/omnitest/command/generators/dashboard.rb

Instance Method Summary collapse

Instance Method Details

#as_json(data) ⇒ Object



43
44
45
46
47
# File 'lib/omnitest/command/generators/dashboard.rb', line 43

def as_json(data)
  JSON.dump(data)
rescue => e
  JSON.dump(to_utf(data))
end

#bootstrap_color(color) ⇒ Object



67
68
69
70
71
72
73
74
75
# File 'lib/omnitest/command/generators/dashboard.rb', line 67

def bootstrap_color(color)
  bootstrap_classes = {
    green: 'success',
    cyan: 'primary',
    red: 'danger',
    yellow: 'warning'
  }
  bootstrap_classes.key?(color) ? bootstrap_classes[color] : color
end

#projectsObject



19
20
21
22
23
# File 'lib/omnitest/command/generators/dashboard.rb', line 19

def projects
  Omnitest.projects.map do |project|
    slugify(project.name)
  end
end

#resultsObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/omnitest/command/generators/dashboard.rb', line 25

def results
  rows = []
  grouped_scenarios = Omnitest.scenarios.group_by { |scenario| [scenario.suite, scenario.name] }
  grouped_scenarios.each do |(suite, name), scenarios|
    row = {
      slug_prefix: slugify(suite, name),
      suite: suite,
      scenario: name
    }
    Omnitest.projects.each do |project|
      scenario = scenarios.find { |s| s.psychic.name == project.name }
      row[slugify(project.name)] = scenario.status_description
    end
    rows << row
  end
  rows
end

#status(status, msg = nil, _color = :cyan) ⇒ Object



63
64
65
# File 'lib/omnitest/command/generators/dashboard.rb', line 63

def status(status, msg = nil, _color = :cyan)
  "<strong>#{status}</strong> <em>#{msg}</em>"
end

#to_utf(data) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/omnitest/command/generators/dashboard.rb', line 49

def to_utf(data)
  Hash[
    data.collect do |k, v|
      if v.respond_to?(:collect)
        [k, to_utf(v)]
      elsif v.respond_to?(:encoding)
        [k, v.dup.encode('UTF-8')]
      else
        [k, v]
      end
    end
  ]
end