Class: ReportBuilder::Builder

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

Overview

ReportBuilder Main class

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#optionsObject

Returns the value of attribute options.



15
16
17
# File 'lib/report_builder/builder.rb', line 15

def options
  @options
end

Instance Method Details

#build_report(opts = nil) ⇒ Object

ReportBuilder Main method



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

def build_report(opts = nil)
  options = self.options || default_options.marshal_dump
  options.merge! opts if opts.is_a? Hash

  fail 'Error:: Invalid report_types. Use: [:json, :html]' unless options[:report_types].is_a? Array
  options[:report_types].map!(&:to_s).map!(&:upcase)

  options[:input_path] ||= options[:json_path] || Dir.pwd
  groups = get_groups options[:input_path]

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

  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]
  File.open(html_report_path + '.html', 'w') do |file|
    file.write get(groups.size > 1 ? 'group_report' : 'report').result(binding).gsub('  ', '').gsub("\n\n", '')
  end if options[:report_types].include? 'HTML'

  retry_report_path = options[:retry_report_path] || options[:report_path]
  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 {|scenario| file.puts "#{feature['uri']}:#{scenario['line']}" if scenario['status'] == 'failed'}
        end
      end
    end
  end if options[:report_types].include? 'RETRY'
  [json_report_path, html_report_path, retry_report_path]
end

#default_optionsObject

ReportBuilder default configuration



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/report_builder/builder.rb', line 64

def default_options
  OpenStruct.new(json_path: nil,
                 input_path: nil,
                 report_types: [:html],
                 report_title: 'Test Results',
                 include_images: true,
                 additional_info: {},
                 report_path: 'test_report',
                 json_report_path: nil,
                 html_report_path: nil,
                 retry_report_path: nil,
                 additional_css: nil,
                 additional_js: nil
  )
end