Module: AppThwack::Reports

Defined in:
lib/ruby_appthwack/reports.rb

Class Method Summary collapse

Class Method Details

.convert_reports(reports, platform = 'android') ⇒ Object

Converts Android reports into results readable by Cucumber plugin



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
# File 'lib/ruby_appthwack/reports.rb', line 13

def convert_reports(reports, platform='android')
	# default to android folder
	intermediate_folders = 'calabash_tests_from_features.zip'

	dst = 'cucumber-html-reports'

	# unless platform is explicitly ios
	if platform.eql? 'ios'
		 intermediate_folders = 'calabash'
	end

	reports = extract_reports(reports)
	folders = Dir.entries(reports).select {|f| not f.eql? '.' and not f.eql? '..' }

	# extract for each of the devices
	folders.each do |f|

		# capitalize every word
		device = f.gsub('_', ' ').split.map(&:capitalize).join(' ')

		# original folder name
		folder_name = f

		puts device

		f = File.join(reports, f, intermediate_folders, 'raw_calabash_json_output.instrtxt')

		features = []

		# now we just add the device prefix to each feature name to make it unique
		File.open(f, 'r') do |io|

			features = JSON.load(io)

			if not features.nil?
				
				features.each_index do |i|
					# append the device name to the feature name
					features[i]['name'] = "#{features[i]['name']} on #{device}"
				end
			end

			Dir.mkdir dst if not Dir.exists? dst

			# now write out the new file
			File.open(File.join(dst, "#{Time.now.to_i}_#{folder_name}.json"), 'w') do |io|
				JSON.dump(features, io) unless features.nil?
			end
		end
	end

	dst
end

.extract_reports(reports) ⇒ Object



7
8
9
10
# File 'lib/ruby_appthwack/reports.rb', line 7

def extract_reports(reports)
	
	'unzipped_reports' if system "rm -rf unzipped_reports && unzip -qq #{reports} -d unzipped_reports"
end