mtdewboy-metric_fu 1.1.5.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (85) hide show
  1. data/HISTORY +159 -0
  2. data/MIT-LICENSE +22 -0
  3. data/Manifest.txt +25 -0
  4. data/README +1 -0
  5. data/Rakefile +18 -0
  6. data/TODO +9 -0
  7. data/lib/base/base_template.rb +146 -0
  8. data/lib/base/configuration.rb +189 -0
  9. data/lib/base/generator.rb +160 -0
  10. data/lib/base/graph.rb +38 -0
  11. data/lib/base/md5_tracker.rb +52 -0
  12. data/lib/base/report.rb +100 -0
  13. data/lib/generators/churn.rb +90 -0
  14. data/lib/generators/dcov.rb +105 -0
  15. data/lib/generators/flay.rb +33 -0
  16. data/lib/generators/flog.rb +140 -0
  17. data/lib/generators/rcov.rb +87 -0
  18. data/lib/generators/reek.rb +37 -0
  19. data/lib/generators/roodi.rb +31 -0
  20. data/lib/generators/saikuro.rb +208 -0
  21. data/lib/generators/stats.rb +43 -0
  22. data/lib/graphs/flay_grapher.rb +35 -0
  23. data/lib/graphs/flog_grapher.rb +51 -0
  24. data/lib/graphs/grapher.rb +19 -0
  25. data/lib/graphs/rcov_grapher.rb +34 -0
  26. data/lib/graphs/reek_grapher.rb +44 -0
  27. data/lib/graphs/roodi_grapher.rb +34 -0
  28. data/lib/metric_fu.rb +30 -0
  29. data/lib/templates/awesome/awesome_template.rb +30 -0
  30. data/lib/templates/awesome/churn.html.erb +19 -0
  31. data/lib/templates/awesome/css/buttons.css +82 -0
  32. data/lib/templates/awesome/css/default.css +75 -0
  33. data/lib/templates/awesome/css/integrity.css +335 -0
  34. data/lib/templates/awesome/css/reset.css +7 -0
  35. data/lib/templates/awesome/dcov.html.erb +27 -0
  36. data/lib/templates/awesome/flay.html.erb +27 -0
  37. data/lib/templates/awesome/flog.html.erb +47 -0
  38. data/lib/templates/awesome/index.html.erb +31 -0
  39. data/lib/templates/awesome/layout.html.erb +27 -0
  40. data/lib/templates/awesome/rcov.html.erb +36 -0
  41. data/lib/templates/awesome/reek.html.erb +34 -0
  42. data/lib/templates/awesome/roodi.html.erb +21 -0
  43. data/lib/templates/awesome/saikuro.html.erb +71 -0
  44. data/lib/templates/awesome/stats.html.erb +41 -0
  45. data/lib/templates/standard/churn.html.erb +31 -0
  46. data/lib/templates/standard/dcov.html.erb +38 -0
  47. data/lib/templates/standard/default.css +64 -0
  48. data/lib/templates/standard/flay.html.erb +34 -0
  49. data/lib/templates/standard/flog.html.erb +53 -0
  50. data/lib/templates/standard/index.html.erb +41 -0
  51. data/lib/templates/standard/rcov.html.erb +43 -0
  52. data/lib/templates/standard/reek.html.erb +42 -0
  53. data/lib/templates/standard/roodi.html.erb +29 -0
  54. data/lib/templates/standard/saikuro.html.erb +84 -0
  55. data/lib/templates/standard/standard_template.rb +26 -0
  56. data/lib/templates/standard/stats.html.erb +55 -0
  57. data/spec/base/base_template_spec.rb +161 -0
  58. data/spec/base/configuration_spec.rb +300 -0
  59. data/spec/base/generator_spec.rb +181 -0
  60. data/spec/base/graph_spec.rb +24 -0
  61. data/spec/base/md5_tracker_spec.rb +57 -0
  62. data/spec/base/report_spec.rb +139 -0
  63. data/spec/generators/churn_spec.rb +152 -0
  64. data/spec/generators/flay_spec.rb +104 -0
  65. data/spec/generators/flog_spec.rb +219 -0
  66. data/spec/generators/reek_spec.rb +60 -0
  67. data/spec/generators/saikuro_spec.rb +58 -0
  68. data/spec/generators/stats_spec.rb +74 -0
  69. data/spec/graphs/flay_grapher_spec.rb +44 -0
  70. data/spec/graphs/flog_grapher_spec.rb +61 -0
  71. data/spec/graphs/grapher_spec.rb +9 -0
  72. data/spec/graphs/rcov_grapher_spec.rb +44 -0
  73. data/spec/graphs/reek_grapher_spec.rb +53 -0
  74. data/spec/graphs/roodi_grapher_spec.rb +44 -0
  75. data/spec/resources/saikuro/app/controllers/sessions_controller.rb_cyclo.html +10 -0
  76. data/spec/resources/saikuro/app/controllers/users_controller.rb_cyclo.html +16 -0
  77. data/spec/resources/saikuro/index_cyclo.html +155 -0
  78. data/spec/resources/saikuro_sfiles/thing.rb_cyclo.html +11 -0
  79. data/spec/resources/yml/20090630.yml +7844 -0
  80. data/spec/spec.opts +8 -0
  81. data/spec/spec_helper.rb +6 -0
  82. data/tasks/metric_fu.rake +22 -0
  83. data/vendor/_fonts/monaco.ttf +0 -0
  84. data/vendor/saikuro/saikuro.rb +1219 -0
  85. metadata +184 -0
@@ -0,0 +1,53 @@
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
+ <a href="index.html">back to menu</a>
11
+ <p><a href='http://ruby.sadi.st/Flog.html'>Flog</a> measures code complexity.</p>
12
+ <h2>Total Flog score for all methods: <%= @flog[:total]%></h2>
13
+ <h2>Average Flog score for all methods: <%= @flog[:average]%></h2>
14
+ <table>
15
+ <tr>
16
+ <th>File</th>
17
+ <th>Total score</th>
18
+ <th>Methods</th>
19
+ <th>Average score</th>
20
+ <th>Highest score</th>
21
+ </tr>
22
+ <% @flog[:pages].each do |page| %>
23
+ <tr>
24
+ <td><a href="#<%= page[:path].gsub(/[^a-z]+/, '_') %>"><%= page[:path] %></a></td>
25
+ <td><%= page[:score].round %></td>
26
+ <td><%= page[:scanned_methods].length %></td>
27
+ <td><%= page[:average_score].round %></td>
28
+ <td><%= page[:highest_score].round %></td>
29
+ </tr>
30
+ <% end %>
31
+ </table>
32
+
33
+ <% @flog[:pages].each do |page| %>
34
+ <h2 id="<%= page[:path].gsub(/[^a-z]+/, '_') %>"><%= page[:path] %></h2>
35
+ <% page[:scanned_methods].each do |sm| %>
36
+ <p><%= sm[:name] %></p>
37
+ <table>
38
+ <tr>
39
+ <th>Score</th>
40
+ <th>Operator</th>
41
+ </tr>
42
+ <% sm[:operators].each do |operator| %>
43
+ <tr>
44
+ <td><%= operator[:score] %></td>
45
+ <td><%= operator[:operator] %></td>
46
+ </tr>
47
+ <% end %>
48
+ </table>
49
+ <% end %>
50
+ <% end %>
51
+ <p>Generated on <%= Time.now.localtime %></p>
52
+ </body>
53
+ </html>
@@ -0,0 +1,41 @@
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 @dcov %>
15
+ <p><a href="dcov.html">Dcov report</a></p>
16
+ <% end %>
17
+ <% if @flay %>
18
+ <p><a href="flay.html">Flay report</a></p>
19
+ <% end %>
20
+ <% if @flog %>
21
+ <p><a href="flog.html">Flog report</a></p>
22
+ <% end %>
23
+ <% if @rcov %>
24
+ <p><a href="rcov.html">Rcov report</a></p>
25
+ <% end %>
26
+ <% if @reek %>
27
+ <p><a href="reek.html">Reek report</a></p>
28
+ <% end %>
29
+ <% if @roodi %>
30
+ <p><a href="roodi.html">Roodi report</a></p>
31
+ <% end %>
32
+ <% if @saikuro %>
33
+ <p><a href="saikuro.html">Saikuro report</a></p>
34
+ <% end %>
35
+ <% if @stats %>
36
+ <p><a href="stats.html">Stats report</a></p>
37
+ <% end %>
38
+ <p>Generated on <%= Time.now.localtime %></p>
39
+ </body>
40
+ </html>
41
+
@@ -0,0 +1,43 @@
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
+ <a href="index.html">back to menu</a>
12
+ <p>C0 code coverage information.</p>
13
+ <p>Total Coverage: <%= @rcov.delete(:global_percent_run) %>% </p>
14
+ <table>
15
+ <tr>
16
+ <th>File Path</th>
17
+ <th>Percent run</th>
18
+ </tr>
19
+ <% count = 0 %>
20
+ <% @rcov.sort_by{|k,v| v[:percent_run]}.each do |e| %>
21
+ <tr>
22
+ <td><a href="#<%= e[0].gsub(/[^a-z]+/, '_') %>"><%= e[0] %></a></td>
23
+ <td><%= e[1][:percent_run] %></td>
24
+ </tr>
25
+ <% count += 1 %>
26
+ <% end %>
27
+ </table>
28
+
29
+ <% @rcov.each_pair do |fname, file| %>
30
+ <h2 id="<%= fname.gsub(/[^a-z]+/, '_') %>"> <%= fname %></h2>
31
+ <table class="rcov_code">
32
+ <% file[:lines].each do |line| %>
33
+ <tr>
34
+ <% css_class = line[:was_run] ? "rcov_run" : "rcov_not_run" %>
35
+ <td class="<%= css_class %>"><pre><%= line[:content] %></pre></td>
36
+ </tr>
37
+ <% end %>
38
+ </table>
39
+ <% end %>
40
+ <p>Generated on <%= Time.now.localtime %></p>
41
+ </body>
42
+ </html>
43
+
@@ -0,0 +1,42 @@
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
+ <a href="index.html">back to menu</a>
12
+ <p><a href="http://reek.rubyforge.org/">Reek</a> detects common code smells in ruby code.</p>
13
+ <table>
14
+ <tr>
15
+ <th>File Path</th>
16
+ <th>Method</th>
17
+ <th>Description</th>
18
+ <th>Type</th>
19
+ </tr>
20
+ <% count = 0 %>
21
+ <% @reek[:matches].each do |match| %>
22
+ <% match[:code_smells].each do |smell| %>
23
+ <tr class='<%= cycle("light", "dark", count) %>'>
24
+ <td><%= match[:file_path] %></td>
25
+ <td>
26
+ <%= smell[:method] %>
27
+ </td>
28
+ <td>
29
+ <%= smell[:message] %>
30
+ </td>
31
+ <td>
32
+ <%= smell[:type] %>
33
+ </td>
34
+ </tr>
35
+ <% count += 1 %>
36
+ <% end %>
37
+ <% end %>
38
+
39
+ </table>
40
+ <p>Generated on <%= Time.now.localtime %></p>
41
+ </body>
42
+ </html>
@@ -0,0 +1,29 @@
1
+ <html>
2
+ <head>
3
+ <title>Roodi Results</title>
4
+ <style>
5
+ <%= inline_css("default.css") %>
6
+ </style>
7
+ </head>
8
+
9
+ <body>
10
+ <h1>Roodi Results</h1>
11
+ <a href="index.html">back to menu</a>
12
+ <p><a href="http://roodi.rubyforge.org/">Roodi</a> parses your Ruby code and warns you about design issues you have based on the checks that is has configured.</p>
13
+ <table>
14
+ <tr>
15
+ <th>File Path</th>
16
+ <th>Warning</th>
17
+ </tr>
18
+ <% count = 0 %>
19
+ <% @roodi[:problems].each do |problem| %>
20
+ <tr class='<%= cycle("light", "dark", count) %>'>
21
+ <td><%= problem[:file] %>:<%= problem[:line] %></td>
22
+ <td><%= problem[:problem] %></td>
23
+ </tr>
24
+ <% count += 1 %>
25
+ <% end %>
26
+ </table>
27
+ <p>Generated on <%= Time.now.localtime %></p>
28
+ </body>
29
+ </html>
@@ -0,0 +1,84 @@
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
+ <a href="index.html">back to menu</a>
12
+ <p><a href='http://saikuro.rubyforge.org/'>Saikuro</a> analyzes ruby code for cyclomatic complexity.</p>
13
+
14
+ <h2>Analyzed Methods</h2>
15
+ <table>
16
+ <tr>
17
+ <th>Method Name</th>
18
+ <th>Complexity</th>
19
+ <th># Lines</th>
20
+ </tr>
21
+ <% @saikuro[:methods].each do |method| %>
22
+ <tr>
23
+ <td><%= method[:name] %></td>
24
+ <td><%= method[:complexity] %></td>
25
+ <td><%= method[:lines] %></td>
26
+ </tr>
27
+ <% end %>
28
+ </table>
29
+
30
+
31
+
32
+ <h2>Analyzed Classes</h2>
33
+ <table>
34
+ <tr>
35
+ <th>Class Name</th>
36
+ <th>Complexity</th>
37
+ <th># Lines</th>
38
+ </tr>
39
+ <% @saikuro[:classes].each do |klass| %>
40
+ <tr>
41
+ <td><%= klass[:name] %></td>
42
+ <td><%= klass[:complexity] %></td>
43
+ <td><%= klass[:lines] %></td>
44
+ </tr>
45
+ <% end %>
46
+ </table>
47
+
48
+
49
+ <h2>Analyzed Files</h2>
50
+ <% @saikuro[:files].each do |file| %>
51
+ <% file[:classes].each do |klass| %>
52
+ <% if !klass[:methods].empty? %>
53
+ <h3><%= file[:filename] %></h3>
54
+ <h4>Class : <%= klass[:class_name] %></h4>
55
+ <h5>Total complexity : <%= klass[:complexity] %></h5>
56
+ <h5>Total lines : <%= klass[:lines] %></h5>
57
+ <table>
58
+ <tr>
59
+ <th>Method</th>
60
+ <th>Complexity</th>
61
+ <th># Lines</th>
62
+ </tr>
63
+ <% klass[:methods].each do |method| %>
64
+ <tr>
65
+ <td>
66
+ <%= method[:name] %>
67
+ </td>
68
+ <td>
69
+ <%= method[:complexity] %>
70
+ </td>
71
+ <td>
72
+ <%= method[:lines] %>
73
+ </td>
74
+ </tr>
75
+ <% end %>
76
+ </table>
77
+ <% end %>
78
+ <% end %>
79
+ <% end %>
80
+
81
+ <p>Generated on <%= Time.now.localtime %></p>
82
+ </body>
83
+ </html>
84
+
@@ -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,55 @@
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
+ <a href="index.html">back to menu</a>
12
+ <p>Rails rake stats results.</p>
13
+ <table>
14
+ <tr>
15
+ <th>Lines of Code</th>
16
+ <th>Lines of Test</th>
17
+ <th>Code to test ratio</th>
18
+ </tr>
19
+ <tr>
20
+ <td><%= @stats[:codeLOC] %></td>
21
+ <td><%= @stats[:testLOC] %></td>
22
+ <td>1:<%= @stats[:code_to_test_ratio] %></td>
23
+ </tr>
24
+ </table>
25
+
26
+ <table>
27
+ <tr>
28
+ <th>Name</th>
29
+ <th>Lines</th>
30
+ <th>LOC</th>
31
+ <th>Classes</th>
32
+ <th>Methods</th>
33
+ <th>Methods per class</th>
34
+ <th>LOC per method</th>
35
+ </tr>
36
+ <% count = 0 %>
37
+ <% @stats[:lines].each do |line| %>
38
+ <tr>
39
+ <td><%= line[:name] %></td>
40
+ <td><%= line[:lines] %></td>
41
+ <td><%= line[:loc] %></td>
42
+ <td><%= line[:classes] %></td>
43
+ <td><%= line[:methods] %></td>
44
+ <td><%= line[:methods_per_class] %></td>
45
+ <td><%= line[:loc_per_method] %></td>
46
+ </tr>
47
+ <% count += 1 %>
48
+ <% end %>
49
+ </table>
50
+
51
+ <p>Generated on <%= Time.now.localtime %></p>
52
+ </body>
53
+ </html>
54
+
55
+
@@ -0,0 +1,161 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
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.stub!(:platform).and_return('universal-darwin-9.0')
91
+ MetricFu.stub!(:configuration).and_return(config)
92
+ end
93
+
94
+ it 'should return a textmate protocol link' do
95
+ File.stub!(:expand_path).with('filename').and_return('/expanded/filename')
96
+ result = @template.send(:link_to_filename, 'filename')
97
+ result.should eql("<a href='txmt://open/?url=file://" \
98
+ + "/expanded/filename'>filename</a>")
99
+ end
100
+
101
+ it "should do the right thing with a filename that starts with a slash" do
102
+ File.stub!(:expand_path).with('filename').and_return('/expanded/filename')
103
+ result = @template.send(:link_to_filename, '/filename')
104
+ result.should eql("<a href='txmt://open/?url=file://" \
105
+ + "/expanded/filename'>/filename</a>")
106
+ end
107
+
108
+ it "should include a line number" do
109
+ File.stub!(:expand_path).with('filename').and_return('/expanded/filename')
110
+ result = @template.send(:link_to_filename, 'filename', 6)
111
+ result.should eql("<a href='txmt://open/?url=file://" \
112
+ + "/expanded/filename&line=6'>filename:6</a>")
113
+ end
114
+
115
+ describe "and given link text" do
116
+ it "should use the submitted link text" do
117
+ File.stub!(:expand_path).with('filename').and_return('/expanded/filename')
118
+ result = @template.send(:link_to_filename, 'filename', 6, 'link content')
119
+ result.should eql("<a href='txmt://open/?url=file://" \
120
+ + "/expanded/filename&line=6'>link content</a>")
121
+ end
122
+ end
123
+ end
124
+
125
+ describe "when on other platforms" do
126
+ before(:each) do
127
+ config = mock("configuration")
128
+ config.should_receive(:platform).and_return('other')
129
+ MetricFu.stub!(:configuration).and_return(config)
130
+ File.should_receive(:expand_path).and_return('filename')
131
+ end
132
+
133
+ it 'should return a file protocol link' do
134
+ name = "filename"
135
+ result = @template.send(:link_to_filename, name)
136
+ result.should == "<a href='file://filename'>filename</a>"
137
+ end
138
+ end
139
+ end
140
+
141
+ describe "#cycle" do
142
+ it 'should return the first_value passed if iteration passed is even' do
143
+ first_val = "first"
144
+ second_val = "second"
145
+ iter = 2
146
+ result = @template.send(:cycle, first_val, second_val, iter)
147
+ result.should == first_val
148
+ end
149
+
150
+ it 'should return the second_value passed if iteration passed is odd' do
151
+ first_val = "first"
152
+ second_val = "second"
153
+ iter = 1
154
+ result = @template.send(:cycle, first_val, second_val, iter)
155
+ result.should == second_val
156
+ end
157
+ end
158
+
159
+ end
160
+
161
+