Class: MetricFu::Rcov
Defined Under Namespace
Classes: Line
Constant Summary
collapse
- NEW_FILE_MARKER =
("=" * 80) + "\n"
Instance Attribute Summary
Attributes inherited from Generator
#report, #template
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Generator
class_name, #create_data_dir_if_missing, #create_metric_dir_if_missing, #create_output_dir_if_missing, generate_report, #generate_report, #initialize, #metric_directory, metric_directory, #round_to_tenths, #to_graph
Class Method Details
.verify_dependencies! ⇒ Object
8
9
10
11
12
13
14
15
16
17
|
# File 'lib/generators/rcov.rb', line 8
def self.verify_dependencies!
`rcov --help`
unless $?.success?
if RUBY_PLATFORM =~ /java/
raise 'running in jruby - rcov tasks not available'
else
raise 'sudo gem install rcov # if you want the rcov tasks'
end
end
end
|
Instance Method Details
#analyze ⇒ Object
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
# File 'lib/generators/rcov.rb', line 62
def analyze
output = File.open(MetricFu::Rcov.metric_directory + '/rcov.txt').read
output.gsub!(/^\..*\d{3}s\n/m, '') if MetricFu.rcov[:run_cucumber]
output = output.split(NEW_FILE_MARKER)
output.shift
files = {}
output.each_slice(2) {|out| files[out.first.strip] = out.last}
files.each_pair {|fname, content| files[fname] = content.split("\n") }
files.each_pair do |fname, content|
content.map! do |raw_line|
if raw_line.match(/^!!/)
line = Line.new(raw_line.gsub('!!', ' '), false).to_h
else
line = Line.new(raw_line, true).to_h
end
end
files[fname] = {:lines => content}
end
@global_total_lines = 0
@global_total_lines_run = 0
files.each_pair do |fname, content|
lines = content[:lines]
@global_total_lines_run += lines_run = lines.find_all {|line| line[:was_run] == true }.length
@global_total_lines += total_lines = lines.length
percent_run = ((lines_run.to_f / total_lines.to_f) * 100).round
files[fname][:percent_run] = percent_run
end
@rcov = files
end
|
#emit ⇒ Object
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/generators/rcov.rb', line 32
def emit
begin
FileUtils.rm_rf(MetricFu::Rcov.metric_directory, :verbose => false)
Dir.mkdir(MetricFu::Rcov.metric_directory)
test_files = FileList[*MetricFu.rcov[:test_files]].join(' ')
rcov_opts = MetricFu.rcov[:rcov_opts].join(' ')
output = "> #{MetricFu::Rcov.metric_directory}/rcov.txt"
if MetricFu.rcov[:run_cucumber]
aggregate_file = "#{MetricFu::Rcov.metric_directory}/rcov_aggregate.data"
rcov_opts << " --aggregate #{aggregate_file}"
end
`rcov #{rcov_opts} #{test_files} #{output}`
if MetricFu.rcov[:run_cucumber]
cucumber_opts = MetricFu.rcov[:cucumber_opts].join(' ')
cucumber_executable = MetricFu.rcov[:cucumber_executable]
feature_files = FileList[*MetricFu.rcov[:feature_files]].join(' ')
`rcov #{rcov_opts} #{cucumber_executable} -- #{cucumber_opts} #{feature_files} #{output}`
end
rescue LoadError
if RUBY_PLATFORM =~ /java/
puts 'running in jruby - rcov tasks not available'
else
puts 'sudo gem install rcov # if you want the rcov tasks'
end
end
end
|
#to_h ⇒ Object
95
96
97
98
|
# File 'lib/generators/rcov.rb', line 95
def to_h
global_percent_run = ((@global_total_lines_run.to_f / @global_total_lines.to_f) * 100)
{:rcov => @rcov.merge({:global_percent_run => round_to_tenths(global_percent_run) })}
end
|