Class: TestCenter::Helper::ReportNameHelper

Inherits:
Object
  • Object
show all
Defined in:
lib/fastlane/plugin/retry_tests/helper/reportname_helper.rb

Instance Method Summary collapse

Constructor Details

#initialize(output_types = nil, output_files = nil, custom_report_file_name = nil) ⇒ ReportNameHelper

Returns a new instance of ReportNameHelper.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/fastlane/plugin/retry_tests/helper/reportname_helper.rb', line 6

def initialize(output_types = nil, output_files = nil, custom_report_file_name = nil)
  @output_types = output_types || 'junit'
  @output_files = output_files || custom_report_file_name
  @report_count = 0

  if @output_types && @output_files.nil?
    @output_files = @output_types.split(',').map { |type| "report.#{type}" }.join(',')
  end
  unless @output_types.include?('junit')
    FastlaneCore::UI.important('Scan output types missing \'junit\', adding it')
    @output_types = @output_types.split(',').push('junit').join(',')
    if @output_types.split(',').size == @output_files.split(',').size + 1
      @output_files = @output_files.split(',').push('report.xml').join(',')
      FastlaneCore::UI.message('As output files has one less than the new number of output types, assumming the filename for the junit was missing and added it')
    end
  end

  types = @output_types.split(',').each(&:chomp)
  files = @output_files.split(',').each(&:chomp)
  unless files.size == types.size
    raise ArgumentError, "Error: count of :output_types, #{types}, does not match the output filename(s) #{files}"
  end
end

Instance Method Details

#incrementObject



65
66
67
# File 'lib/fastlane/plugin/retry_tests/helper/reportname_helper.rb', line 65

def increment
  @report_count += 1
end

#junit_filextensionObject



61
62
63
# File 'lib/fastlane/plugin/retry_tests/helper/reportname_helper.rb', line 61

def junit_filextension
  File.extname(junit_reportname)
end

#junit_last_reportnameObject



51
52
53
54
# File 'lib/fastlane/plugin/retry_tests/helper/reportname_helper.rb', line 51

def junit_last_reportname
  junit_index = @output_types.split(',').find_index('junit')
  numbered_filename(@output_files.to_s.split(',')[junit_index])
end

#junit_reportnameObject



56
57
58
59
# File 'lib/fastlane/plugin/retry_tests/helper/reportname_helper.rb', line 56

def junit_reportname
  junit_index = @output_types.split(',').find_index('junit')
  @output_files.to_s.split(',')[junit_index]
end

#numbered_filename(filename) ⇒ Object



30
31
32
33
34
35
36
37
# File 'lib/fastlane/plugin/retry_tests/helper/reportname_helper.rb', line 30

def numbered_filename(filename)
  if @report_count > 0
    basename = File.basename(filename, '.*')
    extension = File.extname(filename)
    filename = "#{basename}-#{@report_count + 1}#{extension}"
  end
  filename
end

#scan_optionsObject



39
40
41
42
43
44
45
46
47
48
49
# File 'lib/fastlane/plugin/retry_tests/helper/reportname_helper.rb', line 39

def scan_options
  files = @output_files.split(',').each(&:chomp)
  files.map! do |filename|
    filename.chomp
    numbered_filename(filename)
  end
  {
    output_types: @output_types,
    output_files: files.join(',')
  }
end