jscruggs-metric_fu 0.9.0 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/HISTORY +10 -0
- data/README +1 -154
- data/Rakefile +37 -2
- data/TODO +2 -1
- data/lib/base/base_template.rb +134 -0
- data/lib/base/configuration.rb +187 -0
- data/lib/base/generator.rb +144 -0
- data/lib/{metric_fu → base}/md5_tracker.rb +0 -0
- data/lib/base/report.rb +100 -0
- data/lib/{metric_fu → generators}/churn.rb +20 -22
- data/lib/generators/flay.rb +29 -0
- data/lib/generators/flog.rb +130 -0
- data/lib/generators/rcov.rb +74 -0
- data/lib/generators/reek.rb +31 -0
- data/lib/generators/roodi.rb +28 -0
- data/lib/generators/saikuro.rb +201 -0
- data/lib/generators/stats.rb +43 -0
- data/lib/metric_fu.rb +20 -3
- data/lib/templates/{churn.html.erb → standard/churn.html.erb} +12 -4
- data/lib/templates/{default.css → standard/default.css} +20 -1
- data/lib/templates/{flay.html.erb → standard/flay.html.erb} +12 -9
- data/lib/templates/standard/flog.html.erb +52 -0
- data/lib/templates/standard/index.html.erb +38 -0
- data/lib/templates/standard/rcov.html.erb +42 -0
- data/lib/templates/standard/reek.html.erb +41 -0
- data/lib/templates/{roodi.html.erb → standard/roodi.html.erb} +10 -8
- data/lib/templates/standard/saikuro.html.erb +83 -0
- data/lib/templates/standard/standard_template.rb +26 -0
- data/lib/templates/standard/stats.html.erb +54 -0
- data/spec/base/base_template_spec.rb +140 -0
- data/spec/base/configuration_spec.rb +303 -0
- data/spec/base/generator_spec.rb +159 -0
- data/spec/{md5_tracker_spec.rb → base/md5_tracker_spec.rb} +1 -1
- data/spec/base/report_spec.rb +139 -0
- data/spec/generators/churn_spec.rb +152 -0
- data/spec/generators/flay_spec.rb +101 -0
- data/spec/generators/flog_spec.rb +189 -0
- data/spec/generators/reek_spec.rb +47 -0
- data/spec/generators/saikuro_spec.rb +35 -0
- data/spec/generators/stats_spec.rb +74 -0
- data/spec/spec_helper.rb +24 -7
- data/tasks/metric_fu.rake +14 -0
- data/{lib/tasks → tasks}/railroad.rake +0 -0
- data/{lib/metric_fu → vendor}/saikuro/saikuro.rb +0 -0
- metadata +58 -47
- data/lib/metric_fu/base.rb +0 -160
- data/lib/metric_fu/flay.rb +0 -17
- data/lib/metric_fu/flog.rb +0 -129
- data/lib/metric_fu/reek.rb +0 -17
- data/lib/metric_fu/roodi.rb +0 -17
- data/lib/tasks/churn.rake +0 -9
- data/lib/tasks/coverage.rake +0 -54
- data/lib/tasks/flay.rake +0 -6
- data/lib/tasks/flog.rake +0 -69
- data/lib/tasks/metric_fu.rake +0 -24
- data/lib/tasks/metric_fu.rb +0 -6
- data/lib/tasks/reek.rake +0 -6
- data/lib/tasks/roodi.rake +0 -7
- data/lib/tasks/saikuro.rake +0 -35
- data/lib/tasks/stats.rake +0 -14
- data/lib/templates/flog.html.erb +0 -38
- data/lib/templates/flog_page.html.erb +0 -25
- data/lib/templates/reek.html.erb +0 -30
- data/spec/base_spec.rb +0 -57
- data/spec/churn_spec.rb +0 -117
- data/spec/config_spec.rb +0 -110
- data/spec/flay_spec.rb +0 -19
- data/spec/flog_spec.rb +0 -208
- data/spec/reek_spec.rb +0 -26
@@ -0,0 +1,43 @@
|
|
1
|
+
module MetricFu
|
2
|
+
|
3
|
+
class Stats < Generator
|
4
|
+
|
5
|
+
def emit
|
6
|
+
`rake stats > #{metric_directory + '/stats.txt'}`
|
7
|
+
end
|
8
|
+
|
9
|
+
def analyze
|
10
|
+
output = File.open(metric_directory + '/stats.txt').read
|
11
|
+
output = output.split("\n")
|
12
|
+
output = output.find_all {|line| line[0].chr != "+" }
|
13
|
+
output = output.find_all {|line| line[0].chr != "(" }
|
14
|
+
output.shift
|
15
|
+
totals = output.pop
|
16
|
+
totals = totals.split(" ").find_all {|el| ! el.empty? }
|
17
|
+
@stats = {}
|
18
|
+
@stats[:codeLOC] = totals[0].match(/\d.*/)[0].to_i
|
19
|
+
@stats[:testLOC] = totals[1].match(/\d.*/)[0].to_i
|
20
|
+
@stats[:code_to_test_ratio] = totals[2].match(/1\:(\d.*)/)[1].to_f
|
21
|
+
|
22
|
+
@stats[:lines] = output.map do |line|
|
23
|
+
elements = line.split("|")
|
24
|
+
elements.map! {|el| el.strip }
|
25
|
+
elements = elements.find_all {|el| ! el.empty? }
|
26
|
+
info_line = {}
|
27
|
+
info_line[:name] = elements.shift
|
28
|
+
elements.map! {|el| el.to_i }
|
29
|
+
[:lines, :loc, :classes, :methods,
|
30
|
+
:methods_per_class, :loc_per_method].each do |sym|
|
31
|
+
info_line[sym] = elements.shift
|
32
|
+
end
|
33
|
+
info_line
|
34
|
+
end
|
35
|
+
@stats
|
36
|
+
end
|
37
|
+
|
38
|
+
def to_h
|
39
|
+
{:stats => @stats}
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
end
|
data/lib/metric_fu.rb
CHANGED
@@ -1,3 +1,20 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
# Load a few things to make our lives easier elsewhere.
|
2
|
+
module MetricFu
|
3
|
+
LIB_ROOT = File.dirname(__FILE__)
|
4
|
+
end
|
5
|
+
base_dir = File.join(MetricFu::LIB_ROOT, 'base')
|
6
|
+
generator_dir = File.join(MetricFu::LIB_ROOT, 'generators')
|
7
|
+
template_dir = File.join(MetricFu::LIB_ROOT, 'templates')
|
8
|
+
|
9
|
+
# We need to require these two things first because our other classes
|
10
|
+
# depend on them.
|
11
|
+
require File.join(base_dir, 'report')
|
12
|
+
require File.join(base_dir, 'generator')
|
13
|
+
|
14
|
+
# Load the rakefile so users of the gem get the default metric_fu task
|
15
|
+
load File.join(MetricFu::LIB_ROOT, '..', 'tasks', 'metric_fu.rake')
|
16
|
+
|
17
|
+
# Now load everything else that's in the directory
|
18
|
+
Dir[File.join(base_dir, '*.rb')].each{|l| require l }
|
19
|
+
Dir[File.join(generator_dir, '*.rb')].each {|l| require l }
|
20
|
+
Dir[File.join(template_dir, 'standard/*.rb')].each {|l| require l}
|
@@ -12,11 +12,19 @@
|
|
12
12
|
This task uses your source control log to identify those files.
|
13
13
|
</p>
|
14
14
|
<table>
|
15
|
-
|
16
|
-
|
17
|
-
|
15
|
+
<tr>
|
16
|
+
<th>File Path</th>
|
17
|
+
<th>Times Changed</th>
|
18
|
+
</tr>
|
19
|
+
<% count = 0 %>
|
20
|
+
<% @churn[:changes].each do |change| %>
|
21
|
+
<tr>
|
22
|
+
<td><%= change[:file_path] %></td>
|
23
|
+
<td><%= change[:times_changed] %></td>
|
24
|
+
</tr>
|
25
|
+
<% count += 1 %>
|
18
26
|
<% end %>
|
19
27
|
</table>
|
20
28
|
<p>Generated on <%= Time.now.localtime %></p>
|
21
29
|
</body>
|
22
|
-
</html>
|
30
|
+
</html>
|
@@ -42,4 +42,23 @@ table {
|
|
42
42
|
|
43
43
|
.warning {
|
44
44
|
background: yellow;
|
45
|
-
}
|
45
|
+
}
|
46
|
+
.rcov_code td {
|
47
|
+
border-bottom: 1px solid #ddd ;
|
48
|
+
padding: 0;
|
49
|
+
margin: 0;
|
50
|
+
}
|
51
|
+
.rcov_code tr {
|
52
|
+
border: 0px;
|
53
|
+
padding:0px;
|
54
|
+
margin: 0px;
|
55
|
+
}
|
56
|
+
.rcov_code pre {
|
57
|
+
border: 0px;
|
58
|
+
padding: 0px;
|
59
|
+
margin: 0px;
|
60
|
+
}
|
61
|
+
.rcov_run {}
|
62
|
+
.rcov_not_run {
|
63
|
+
background-color: #d88;
|
64
|
+
}
|
@@ -8,21 +8,24 @@
|
|
8
8
|
|
9
9
|
<body>
|
10
10
|
<h1>Flay Results</h1>
|
11
|
+
<h2>Total Score (lower is better): <%= @flay[:total_score] %></h2>
|
11
12
|
<p><a href='http://ruby.sadi.st/Flay.html'>Flay</a> analyzes ruby code for structural similarities.</p>
|
12
13
|
<table>
|
13
|
-
|
14
|
+
<tr>
|
14
15
|
<th>Files</th>
|
15
16
|
<th>Matches</th>
|
16
|
-
|
17
|
-
|
17
|
+
</tr>
|
18
|
+
<% count = 0 %>
|
19
|
+
<% @flay[:matches].each do |match| %>
|
18
20
|
<tr class='<%= cycle("light", "dark", count) %>'>
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
21
|
+
<td>
|
22
|
+
<% match[:matches].each do |file| %>
|
23
|
+
<%= file[:name] %>:<%= file[:line] %><br />
|
24
|
+
<% end %>
|
23
25
|
</td>
|
24
|
-
<td><%= match
|
25
|
-
|
26
|
+
<td><%= match[:reason] %></td>
|
27
|
+
</tr>
|
28
|
+
<% count += 1 %>
|
26
29
|
<% end %>
|
27
30
|
</table>
|
28
31
|
<p>Generated on <%= Time.now.localtime %></p>
|
@@ -0,0 +1,52 @@
|
|
1
|
+
<html>
|
2
|
+
<head>
|
3
|
+
<title>Flog Reporter</title>
|
4
|
+
<style>
|
5
|
+
<%= inline_css("default.css") %>
|
6
|
+
</style>
|
7
|
+
</head>
|
8
|
+
<body>
|
9
|
+
<h1>Flog Results</h1>
|
10
|
+
<p><a href='http://ruby.sadi.st/Flog.html'>Flog</a> measures code complexity.</p>
|
11
|
+
<h2>Total Flog score for all methods: <%= @flog[:total]%></h2>
|
12
|
+
<h2>Average Flog score for all methods: <%= @flog[:average]%></h2>
|
13
|
+
<table>
|
14
|
+
<tr>
|
15
|
+
<th>File</th>
|
16
|
+
<th>Total score</th>
|
17
|
+
<th>Methods</th>
|
18
|
+
<th>Average score</th>
|
19
|
+
<th>Highest score</th>
|
20
|
+
</tr>
|
21
|
+
<% @flog[:pages].each do |page| %>
|
22
|
+
<tr>
|
23
|
+
<td><%= page[:path] %></td>
|
24
|
+
<td><%= page[:score].round %></td>
|
25
|
+
<td><%= page[:scanned_methods].length %></td>
|
26
|
+
<td><%= page[:average_score].round %></td>
|
27
|
+
<td><%= page[:highest_score].round %></td>
|
28
|
+
</tr>
|
29
|
+
<% end %>
|
30
|
+
</table>
|
31
|
+
|
32
|
+
<% @flog[:pages].each do |page| %>
|
33
|
+
<h2><%= page[:path] %></h2>
|
34
|
+
<% page[:scanned_methods].each do |sm| %>
|
35
|
+
<p><%= sm[:name] %></p>
|
36
|
+
<table>
|
37
|
+
<tr>
|
38
|
+
<th>Score</th>
|
39
|
+
<th>Operator</th>
|
40
|
+
</tr>
|
41
|
+
<% sm[:operators].each do |operator| %>
|
42
|
+
<tr>
|
43
|
+
<td><%= operator[:score] %></td>
|
44
|
+
<td><%= operator[:operator] %></td>
|
45
|
+
</tr>
|
46
|
+
<% end %>
|
47
|
+
</table>
|
48
|
+
<% end %>
|
49
|
+
<% end %>
|
50
|
+
<p>Generated on <%= Time.now.localtime %></p>
|
51
|
+
</body>
|
52
|
+
</html>
|
@@ -0,0 +1,38 @@
|
|
1
|
+
<html>
|
2
|
+
<head>
|
3
|
+
<title>Metric Fu Results</title>
|
4
|
+
<style>
|
5
|
+
<%= inline_css("default.css") %>
|
6
|
+
</style>
|
7
|
+
</head>
|
8
|
+
|
9
|
+
<body>
|
10
|
+
<h1>Metric Fu Results</h1>
|
11
|
+
<% if @churn %>
|
12
|
+
<p><a href="churn.html">Churn report</a></p>
|
13
|
+
<% end %>
|
14
|
+
<% if @flay %>
|
15
|
+
<p><a href="flay.html">Flay report</a></p>
|
16
|
+
<% end %>
|
17
|
+
<% if @flog %>
|
18
|
+
<p><a href="flog.html">Flog report</a></p>
|
19
|
+
<% end %>
|
20
|
+
<% if @rcov %>
|
21
|
+
<p><a href="rcov.html">Rcov report</a></p>
|
22
|
+
<% end %>
|
23
|
+
<% if @reek %>
|
24
|
+
<p><a href="reek.html">Reek report</a></p>
|
25
|
+
<% end %>
|
26
|
+
<% if @roodi %>
|
27
|
+
<p><a href="roodi.html">Roodi report</a></p>
|
28
|
+
<% end %>
|
29
|
+
<% if @saikuro %>
|
30
|
+
<p><a href="saikuro.html">Saikuro report</a></p>
|
31
|
+
<% end %>
|
32
|
+
<% if @stats %>
|
33
|
+
<p><a href="stats.html">Stats report</a></p>
|
34
|
+
<% end %>
|
35
|
+
<p>Generated on <%= Time.now.localtime %></p>
|
36
|
+
</body>
|
37
|
+
</html>
|
38
|
+
|
@@ -0,0 +1,42 @@
|
|
1
|
+
<html>
|
2
|
+
<head>
|
3
|
+
<title>Rcov Code Coverage Results</title>
|
4
|
+
<style>
|
5
|
+
<%= inline_css("default.css") %>
|
6
|
+
</style>
|
7
|
+
</head>
|
8
|
+
|
9
|
+
<body>
|
10
|
+
<h1>Rcov Code Coverage Results</h1>
|
11
|
+
<p>C0 code coverage information.</p>
|
12
|
+
|
13
|
+
<table>
|
14
|
+
<tr>
|
15
|
+
<th>File Path</th>
|
16
|
+
<th>Percent run</th>
|
17
|
+
</tr>
|
18
|
+
<% count = 0 %>
|
19
|
+
<% @rcov.each_pair do |fname, file| %>
|
20
|
+
<tr>
|
21
|
+
<td><%= fname %></td>
|
22
|
+
<td><%= file[:percent_run] %></td>
|
23
|
+
</tr>
|
24
|
+
<% count += 1 %>
|
25
|
+
<% end %>
|
26
|
+
</table>
|
27
|
+
|
28
|
+
<% @rcov.each_pair do |fname, file| %>
|
29
|
+
<h2> <%= fname %></h2>
|
30
|
+
<table class="rcov_code">
|
31
|
+
<% file[:lines].each do |line| %>
|
32
|
+
<tr>
|
33
|
+
<% css_class = line[:was_run] ? "rcov_run" : "rcov_not_run" %>
|
34
|
+
<td class="<%= css_class %>"><pre><%= line[:content] %></pre></td>
|
35
|
+
</tr>
|
36
|
+
<% end %>
|
37
|
+
</table>
|
38
|
+
<% end %>
|
39
|
+
<p>Generated on <%= Time.now.localtime %></p>
|
40
|
+
</body>
|
41
|
+
</html>
|
42
|
+
|
@@ -0,0 +1,41 @@
|
|
1
|
+
<html>
|
2
|
+
<head>
|
3
|
+
<title>Reek Results</title>
|
4
|
+
<style>
|
5
|
+
<%= inline_css("default.css") %>
|
6
|
+
</style>
|
7
|
+
</head>
|
8
|
+
|
9
|
+
<body>
|
10
|
+
<h1>Reek Results</h1>
|
11
|
+
<p><a href="http://reek.rubyforge.org/">Reek</a> detects common code smells in ruby code.</p>
|
12
|
+
<table>
|
13
|
+
<tr>
|
14
|
+
<th>File Path</th>
|
15
|
+
<th>Method</th>
|
16
|
+
<th>Description</th>
|
17
|
+
<th>Type</th>
|
18
|
+
</tr>
|
19
|
+
<% count = 0 %>
|
20
|
+
<% @reek[:matches].each do |match| %>
|
21
|
+
<% match[:code_smells].each do |smell| %>
|
22
|
+
<tr class='<%= cycle("light", "dark", count) %>'>
|
23
|
+
<td><%= match[:file_path] %></td>
|
24
|
+
<td>
|
25
|
+
<%= smell[:method] %>
|
26
|
+
</td>
|
27
|
+
<td>
|
28
|
+
<%= smell[:message] %>
|
29
|
+
</td>
|
30
|
+
<td>
|
31
|
+
<%= smell[:type] %>
|
32
|
+
</td>
|
33
|
+
</tr>
|
34
|
+
<% count += 1 %>
|
35
|
+
<% end %>
|
36
|
+
<% end %>
|
37
|
+
|
38
|
+
</table>
|
39
|
+
<p>Generated on <%= Time.now.localtime %></p>
|
40
|
+
</body>
|
41
|
+
</html>
|
@@ -13,14 +13,16 @@
|
|
13
13
|
<tr>
|
14
14
|
<th>File Path</th>
|
15
15
|
<th>Warning</th>
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
16
|
+
</tr>
|
17
|
+
<% count = 0 %>
|
18
|
+
<% @roodi[:problems].each do |problem| %>
|
19
|
+
<tr class='<%= cycle("light", "dark", count) %>'>
|
20
|
+
<td><%= problem[:file] %>:<%= problem[:line] %></td>
|
21
|
+
<td><%= problem[:problem] %></td>
|
22
|
+
</tr>
|
23
|
+
<% count += 1 %>
|
24
|
+
<% end %>
|
23
25
|
</table>
|
24
26
|
<p>Generated on <%= Time.now.localtime %></p>
|
25
27
|
</body>
|
26
|
-
</html>
|
28
|
+
</html>
|
@@ -0,0 +1,83 @@
|
|
1
|
+
<html>
|
2
|
+
<head>
|
3
|
+
<title>Saikuro Results</title>
|
4
|
+
<style>
|
5
|
+
<%= inline_css("default.css") %>
|
6
|
+
</style>
|
7
|
+
</head>
|
8
|
+
|
9
|
+
<body>
|
10
|
+
<h1>Saikuro Results</h1>
|
11
|
+
<p><a href='http://saikuro.rubyforge.org/'>Saikuro</a> analyzes ruby code for cyclomatic complexity.</p>
|
12
|
+
|
13
|
+
<h2>Analyzed Methods</h2>
|
14
|
+
<table>
|
15
|
+
<tr>
|
16
|
+
<th>Method Name</th>
|
17
|
+
<th>Complexity</th>
|
18
|
+
<th># Lines</th>
|
19
|
+
</tr>
|
20
|
+
<% @saikuro[:methods].each do |method| %>
|
21
|
+
<tr>
|
22
|
+
<td><%= method[:name] %></td>
|
23
|
+
<td><%= method[:complexity] %></td>
|
24
|
+
<td><%= method[:lines] %></td>
|
25
|
+
</tr>
|
26
|
+
<% end %>
|
27
|
+
</table>
|
28
|
+
|
29
|
+
|
30
|
+
|
31
|
+
<h2>Analyzed Classes</h2>
|
32
|
+
<table>
|
33
|
+
<tr>
|
34
|
+
<th>Class Name</th>
|
35
|
+
<th>Complexity</th>
|
36
|
+
<th># Lines</th>
|
37
|
+
</tr>
|
38
|
+
<% @saikuro[:classes].each do |klass| %>
|
39
|
+
<tr>
|
40
|
+
<td><%= klass[:name] %></td>
|
41
|
+
<td><%= klass[:complexity] %></td>
|
42
|
+
<td><%= klass[:lines] %></td>
|
43
|
+
</tr>
|
44
|
+
<% end %>
|
45
|
+
</table>
|
46
|
+
|
47
|
+
|
48
|
+
<h2>Analyzed Files</h2>
|
49
|
+
<% @saikuro[:files].each do |file| %>
|
50
|
+
<% file[:classes].each do |klass| %>
|
51
|
+
<% if !klass[:methods].empty? %>
|
52
|
+
<h3><%= file[:filename] %></h3>
|
53
|
+
<h4>Class : <%= klass[:class_name] %></h4>
|
54
|
+
<h5>Total complexity : <%= klass[:complexity] %></h5>
|
55
|
+
<h5>Total lines : <%= klass[:lines] %></h5>
|
56
|
+
<table>
|
57
|
+
<tr>
|
58
|
+
<th>Method</th>
|
59
|
+
<th>Complexity</th>
|
60
|
+
<th># Lines</th>
|
61
|
+
</tr>
|
62
|
+
<% klass[:methods].each do |method| %>
|
63
|
+
<tr>
|
64
|
+
<td>
|
65
|
+
<%= method[:name] %>
|
66
|
+
</td>
|
67
|
+
<td>
|
68
|
+
<%= method[:complexity] %>
|
69
|
+
</td>
|
70
|
+
<td>
|
71
|
+
<%= method[:lines] %>
|
72
|
+
</td>
|
73
|
+
</tr>
|
74
|
+
<% end %>
|
75
|
+
</table>
|
76
|
+
<% end %>
|
77
|
+
<% end %>
|
78
|
+
<% end %>
|
79
|
+
|
80
|
+
<p>Generated on <%= Time.now.localtime %></p>
|
81
|
+
</body>
|
82
|
+
</html>
|
83
|
+
|
@@ -0,0 +1,26 @@
|
|
1
|
+
class StandardTemplate < MetricFu::Template
|
2
|
+
|
3
|
+
|
4
|
+
def write
|
5
|
+
report.each_pair do |section, contents|
|
6
|
+
if template_exists?(section)
|
7
|
+
create_instance_var(section, contents)
|
8
|
+
html = erbify(section)
|
9
|
+
fn = output_filename(section)
|
10
|
+
MetricFu.report.save_output(html, MetricFu.output_directory, fn)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
# Instance variables we need should already be created from above
|
15
|
+
if template_exists?('index')
|
16
|
+
html = erbify('index')
|
17
|
+
fn = output_filename('index')
|
18
|
+
MetricFu.report.save_output(html, MetricFu.output_directory, fn)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def this_directory
|
23
|
+
File.dirname(__FILE__)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
@@ -0,0 +1,54 @@
|
|
1
|
+
<html>
|
2
|
+
<head>
|
3
|
+
<title>Rake Stats Results</title>
|
4
|
+
<style>
|
5
|
+
<%= inline_css("default.css") %>
|
6
|
+
</style>
|
7
|
+
</head>
|
8
|
+
|
9
|
+
<body>
|
10
|
+
<h1>Rake Stats Results</h1>
|
11
|
+
<p>Rails rake stats results.</p>
|
12
|
+
<table>
|
13
|
+
<tr>
|
14
|
+
<th>Lines of Code</th>
|
15
|
+
<th>Lines of Test</th>
|
16
|
+
<th>Code to test ratio</th>
|
17
|
+
</tr>
|
18
|
+
<tr>
|
19
|
+
<td><%= @stats[:codeLOC] %></td>
|
20
|
+
<td><%= @stats[:testLOC] %></td>
|
21
|
+
<td>1:<%= @stats[:code_to_test_ratio] %></td>
|
22
|
+
</tr>
|
23
|
+
</table>
|
24
|
+
|
25
|
+
<table>
|
26
|
+
<tr>
|
27
|
+
<th>Name</th>
|
28
|
+
<th>Lines</th>
|
29
|
+
<th>LOC</th>
|
30
|
+
<th>Classes</th>
|
31
|
+
<th>Methods</th>
|
32
|
+
<th>Methods per class</th>
|
33
|
+
<th>LOC per method</th>
|
34
|
+
</tr>
|
35
|
+
<% count = 0 %>
|
36
|
+
<% @stats[:lines].each do |line| %>
|
37
|
+
<tr>
|
38
|
+
<td><%= line[:name] %></td>
|
39
|
+
<td><%= line[:lines] %></td>
|
40
|
+
<td><%= line[:loc] %></td>
|
41
|
+
<td><%= line[:classes] %></td>
|
42
|
+
<td><%= line[:methods] %></td>
|
43
|
+
<td><%= line[:methods_per_class] %></td>
|
44
|
+
<td><%= line[:loc_per_method] %></td>
|
45
|
+
</tr>
|
46
|
+
<% count += 1 %>
|
47
|
+
<% end %>
|
48
|
+
</table>
|
49
|
+
|
50
|
+
<p>Generated on <%= Time.now.localtime %></p>
|
51
|
+
</body>
|
52
|
+
</html>
|
53
|
+
|
54
|
+
|
@@ -0,0 +1,140 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/../spec_helper.rb"
|
2
|
+
require 'erb'
|
3
|
+
|
4
|
+
describe MetricFu::Template do
|
5
|
+
|
6
|
+
before(:each) do
|
7
|
+
@template = Template.new
|
8
|
+
end
|
9
|
+
|
10
|
+
describe "#erbify" do
|
11
|
+
it 'should evaluate a erb doc' do
|
12
|
+
section = 'section'
|
13
|
+
File.stub!(:read).and_return('foo')
|
14
|
+
erb = mock('erb')
|
15
|
+
erb.should_receive(:result)
|
16
|
+
ERB.should_receive(:new).with('foo').and_return(erb)
|
17
|
+
@template.should_receive(:template).and_return('foo')
|
18
|
+
@template.send(:erbify, section)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "#template_exists? " do
|
23
|
+
|
24
|
+
before(:each) do
|
25
|
+
@section = mock('section')
|
26
|
+
@template.should_receive(:template).
|
27
|
+
with(@section).and_return(@section)
|
28
|
+
end
|
29
|
+
|
30
|
+
describe 'if the template exists' do
|
31
|
+
it 'should return true' do
|
32
|
+
File.should_receive(:exist?).with(@section).and_return(true)
|
33
|
+
result = @template.send(:template_exists?, @section)
|
34
|
+
result.should be_true
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe 'if the template does not exist' do
|
39
|
+
it 'should return false' do
|
40
|
+
File.should_receive(:exist?).with(@section).and_return(false)
|
41
|
+
result = @template.send(:template_exists?, @section)
|
42
|
+
result.should be_false
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe "#create_instance_var" do
|
48
|
+
it 'should set an instance variable with the passed contents' do
|
49
|
+
section = 'section'
|
50
|
+
contents = 'contents'
|
51
|
+
@template.send(:create_instance_var, section, contents)
|
52
|
+
@template.instance_variable_get(:@section).should == contents
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
describe "#template" do
|
57
|
+
it 'should generate the filename of the template file' do
|
58
|
+
section = mock('section')
|
59
|
+
section.should_receive(:to_s).and_return('section')
|
60
|
+
@template.should_receive(:this_directory).and_return('dir')
|
61
|
+
result = @template.send(:template, section)
|
62
|
+
result.should == "dir/section.html.erb"
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
describe "#output_filename" do
|
67
|
+
it 'should generate the filename of the output file' do
|
68
|
+
section = mock('section')
|
69
|
+
section.should_receive(:to_s).and_return('section')
|
70
|
+
result = @template.send(:output_filename, section)
|
71
|
+
result.should == "section.html"
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
describe "#inline_css" do
|
76
|
+
it 'should return the contents of a css file' do
|
77
|
+
css = 'mycss.css'
|
78
|
+
@template.should_receive(:this_directory).and_return('dir')
|
79
|
+
io = mock('io', :read => "css contents")
|
80
|
+
@template.should_receive(:open).and_yield(io)
|
81
|
+
result = @template.send(:inline_css, css)
|
82
|
+
result.should == 'css contents'
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
describe "#link_to_filename " do
|
87
|
+
describe "when on OS X" do
|
88
|
+
before(:each) do
|
89
|
+
config = mock("configuration")
|
90
|
+
config.should_receive(:platform).and_return('universal-darwin-9.0')
|
91
|
+
MetricFu.stub!(:configuration).and_return(config)
|
92
|
+
File.should_receive(:expand_path).and_return('filename')
|
93
|
+
end
|
94
|
+
|
95
|
+
it 'should return a textmate protocol link' do
|
96
|
+
name = "filename"
|
97
|
+
result = @template.send(:link_to_filename, name)
|
98
|
+
result.should eql("<a href='txmt://open/?url=file://" \
|
99
|
+
+ "filename&line='>filename:</a>")
|
100
|
+
end
|
101
|
+
|
102
|
+
end
|
103
|
+
|
104
|
+
describe "when on other platforms" do
|
105
|
+
before(:each) do
|
106
|
+
config = mock("configuration")
|
107
|
+
config.should_receive(:platform).and_return('other')
|
108
|
+
MetricFu.stub!(:configuration).and_return(config)
|
109
|
+
File.should_receive(:expand_path).and_return('filename')
|
110
|
+
end
|
111
|
+
|
112
|
+
it 'should return a file protocol link' do
|
113
|
+
name = "filename"
|
114
|
+
result = @template.send(:link_to_filename, name)
|
115
|
+
result.should == "<a href='file://filename'>filename:</a>"
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
describe "#cycle" do
|
121
|
+
it 'should return the first_value passed if iteration passed is even' do
|
122
|
+
first_val = "first"
|
123
|
+
second_val = "second"
|
124
|
+
iter = 2
|
125
|
+
result = @template.send(:cycle, first_val, second_val, iter)
|
126
|
+
result.should == first_val
|
127
|
+
end
|
128
|
+
|
129
|
+
it 'should return the second_value passed if iteration passed is odd' do
|
130
|
+
first_val = "first"
|
131
|
+
second_val = "second"
|
132
|
+
iter = 1
|
133
|
+
result = @template.send(:cycle, first_val, second_val, iter)
|
134
|
+
result.should == second_val
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
end
|
139
|
+
|
140
|
+
|