Class: ReportBuilder::Builder

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

Overview

ReportBuilder Main class

Instance Method Summary collapse

Instance Method Details

#build_reportObject

ReportBuilder Main method



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
# File 'lib/report_builder/builder.rb', line 19

def build_report
  options = ReportBuilder.options

  groups = get_groups options[:input_path]

  json_report_path = options[:json_report_path] || options[:report_path]
  if options[:report_types].include? 'JSON'
    File.open(json_report_path + '.json', 'w') do |file|
      file.write JSON.pretty_generate(groups.size > 1 ? groups : groups.first['features'])
    end
  end

  if options[:additional_css] and Pathname.new(options[:additional_css]).file?
    options[:additional_css] = File.read(options[:additional_css])
  end

  if options[:additional_js] and Pathname.new(options[:additional_js]).file?
    options[:additional_js] = File.read(options[:additional_js])
  end

  html_report_path = options[:html_report_path] || options[:report_path]
  if options[:report_types].include? 'HTML'
    File.open(html_report_path + '.html', 'w') do |file|
      file.write get(groups.size > 1 ? 'group_report' : 'report').result(binding)
    end
  end

  retry_report_path = options[:retry_report_path] || options[:report_path]
  if options[:report_types].include? 'RETRY'
    File.open(retry_report_path + '.retry', 'w') do |file|
      groups.each do |group|
        group['features'].each do |feature|
          if feature['status'] == 'broken'
            feature['elements'].each do |scenario|
              file.puts "#{feature['uri']}:#{scenario['line']}" if scenario['status'] == 'failed'
            end
          end
        end
      end
    end
  end
  [json_report_path, html_report_path, retry_report_path]
end