Class: HtmlGenerator

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

Instance Method Summary collapse

Constructor Details

#initialize(data, externalDetails) ⇒ HtmlGenerator

Returns a new instance of HtmlGenerator.



6
7
8
9
10
# File 'lib/html_generator.rb', line 6

def initialize data, externalDetails
  @baseData = JSON.parse(data)
  external = JSON.parse(externalDetails)
  @externalDetails = external['userDetails']
end

Instance Method Details

#createHtmlObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/html_generator.rb', line 12

def createHtml
  summary = @baseData['summary']
  currentTime = Time.now.strftime("%A, %b %d %Y %r %z")
  suits = @baseData['suits']
  groupNames = @baseData['groupNames']

  footer = @externalDetails['footerMessage']
  outPath = @externalDetails['outPath']
  documentation = @externalDetails['documentation']

  path = 'reports'

  if(outPath != '')
    path = outPath
  end

  Dir.mkdir(path) unless File.exists?(path)
  Dir.mkdir(path + '/refs') unless File.exists?(path + '/refs')

  cssFile = File.expand_path(File.dirname(__FILE__)) + "/refs/main.min.css"
  jsFile = File.expand_path(File.dirname(__FILE__)) + "/refs/main.min.js"

  File.open path + "/refs/main.min.css", "w" do |c|
    c << IO.read(cssFile)
  end

  File.open path + "/refs/main.min.js", "w" do |c|
    c << IO.read(jsFile)
  end

  templateFile = File.expand_path(File.dirname(__FILE__)) + "/index.erb"
  File.open path + "/index.html", "w" do |f|
    f << ERB.new(IO.read(templateFile), nil, '>', 'output').result(binding)
  end

  File.open path + "/summary.json", "w" do |f|
    f.write summary.to_json
  end

  puts "\n"
  puts "---------------------------------------------------------"
  puts "Total Suits      : #{summary['groupCount']}"
  puts "Total Tests      : #{summary['testCount']}"
  puts "Total Passed     : #{summary['passCount']}"
  puts "Total Failed     : #{summary['failureCount']}"
  puts "Total Pending    : #{summary['pendingCount']}"
  puts "Total Time Taken : #{summary['duration']}"
  puts "---------------------------------------------------------"

  if(documentation)
    puts "=====================Exceptions=========================="
    cnt = 0
    @baseData['failed'].each do |failedTest|
      exMessage = failedTest['exception']['message'].gsub("\n","")
      exType = failedTest['exception']['type']
      puts "\n#{cnt + 1}. #{failedTest['fullName']}"
      puts "Exception : #{exType}"
      puts "Message   : #{exMessage}"
      cnt = cnt + 1
      puts "\n"
    end
    puts "========================================================="
  end
end