Class: TestCenter::Helper::ReportNameHelper

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

Instance Attribute Summary collapse

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.



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

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 Attribute Details

#report_countObject (readonly)

Returns the value of attribute report_count.



6
7
8
# File 'lib/fastlane/plugin/test_center/helper/reportname_helper.rb', line 6

def report_count
  @report_count
end

Instance Method Details

#html_fileglobObject



102
103
104
# File 'lib/fastlane/plugin/test_center/helper/reportname_helper.rb', line 102

def html_fileglob
  "#{File.basename(html_reportname, '.*')}*#{html_filextension}"
end

#html_filextensionObject



98
99
100
# File 'lib/fastlane/plugin/test_center/helper/reportname_helper.rb', line 98

def html_filextension
  File.extname(html_reportname)
end

#html_last_reportnameObject



88
89
90
91
# File 'lib/fastlane/plugin/test_center/helper/reportname_helper.rb', line 88

def html_last_reportname
  html_index = @output_types.split(',').find_index('html')
  numbered_filename(@output_files.to_s.split(',')[html_index])
end

#html_numbered_fileglobObject



106
107
108
# File 'lib/fastlane/plugin/test_center/helper/reportname_helper.rb', line 106

def html_numbered_fileglob
  "#{File.basename(html_reportname, '.*')}-[1-9]*#{html_filextension}"
end

#html_reportnameObject



93
94
95
96
# File 'lib/fastlane/plugin/test_center/helper/reportname_helper.rb', line 93

def html_reportname
  html_index = @output_types.split(',').find_index('html')
  @output_files.to_s.split(',')[html_index]
end

#includes_html?Boolean

Returns:

  • (Boolean)


84
85
86
# File 'lib/fastlane/plugin/test_center/helper/reportname_helper.rb', line 84

def includes_html?
  @output_types.split(',').find_index('html') != nil
end

#includes_json?Boolean

Returns:

  • (Boolean)


110
111
112
# File 'lib/fastlane/plugin/test_center/helper/reportname_helper.rb', line 110

def includes_json?
  @output_types.split(',').find_index('json') != nil
end

#incrementObject



136
137
138
# File 'lib/fastlane/plugin/test_center/helper/reportname_helper.rb', line 136

def increment
  @report_count += 1
end

#json_fileglobObject



128
129
130
# File 'lib/fastlane/plugin/test_center/helper/reportname_helper.rb', line 128

def json_fileglob
  "#{File.basename(json_reportname, '.*')}*#{json_filextension}"
end

#json_filextensionObject



124
125
126
# File 'lib/fastlane/plugin/test_center/helper/reportname_helper.rb', line 124

def json_filextension
  File.extname(json_reportname)
end

#json_last_reportnameObject



114
115
116
117
# File 'lib/fastlane/plugin/test_center/helper/reportname_helper.rb', line 114

def json_last_reportname
  json_index = @output_types.split(',').find_index('json')
  numbered_filename(@output_files.to_s.split(',')[json_index])
end

#json_numbered_fileglobObject



132
133
134
# File 'lib/fastlane/plugin/test_center/helper/reportname_helper.rb', line 132

def json_numbered_fileglob
  "#{File.basename(json_reportname, '.*')}-[1-9]*#{json_filextension}"
end

#json_reportnameObject



119
120
121
122
# File 'lib/fastlane/plugin/test_center/helper/reportname_helper.rb', line 119

def json_reportname
  json_index = @output_types.split(',').find_index('json')
  @output_files.to_s.split(',')[json_index]
end

#junit_fileglobObject



76
77
78
# File 'lib/fastlane/plugin/test_center/helper/reportname_helper.rb', line 76

def junit_fileglob
  "#{File.basename(junit_reportname, '.*')}*#{junit_filextension}"
end

#junit_filextensionObject



72
73
74
# File 'lib/fastlane/plugin/test_center/helper/reportname_helper.rb', line 72

def junit_filextension
  File.extname(junit_reportname)
end

#junit_last_reportnameObject



62
63
64
65
# File 'lib/fastlane/plugin/test_center/helper/reportname_helper.rb', line 62

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

#junit_numbered_fileglobObject



80
81
82
# File 'lib/fastlane/plugin/test_center/helper/reportname_helper.rb', line 80

def junit_numbered_fileglob
  "#{File.basename(junit_reportname, '.*')}-[1-9]*#{junit_filextension}"
end

#junit_reportnameObject



67
68
69
70
# File 'lib/fastlane/plugin/test_center/helper/reportname_helper.rb', line 67

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

#numbered_filename(filename) ⇒ Object



32
33
34
35
36
37
38
39
# File 'lib/fastlane/plugin/test_center/helper/reportname_helper.rb', line 32

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



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/fastlane/plugin/test_center/helper/reportname_helper.rb', line 41

def scan_options
  options = {}

  types = @output_types.split(',').each(&:chomp)
  files = @output_files.split(',').each(&:chomp)
  if (json_index = types.find_index('json'))
    options[:formatter] = 'xcpretty-json-formatter'
    files.delete_at(json_index)
    types.delete_at(json_index)
  end
  files.map! do |filename|
    filename.chomp
    numbered_filename(filename)
  end

  options.merge(
    output_types: types.join(','),
    output_files: files.join(',')
  )
end