khall-metric_fu 1.0.2.1
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 +119 -0
- data/MIT-LICENSE +22 -0
- data/Manifest.txt +25 -0
- data/README +1 -0
- data/Rakefile +46 -0
- data/TODO +14 -0
- data/lib/base/base_template.rb +134 -0
- data/lib/base/configuration.rb +187 -0
- data/lib/base/generator.rb +147 -0
- data/lib/base/md5_tracker.rb +52 -0
- data/lib/base/report.rb +100 -0
- data/lib/generators/churn.rb +86 -0
- data/lib/generators/flay.rb +29 -0
- data/lib/generators/flog.rb +127 -0
- data/lib/generators/rcov.rb +77 -0
- data/lib/generators/reek.rb +32 -0
- data/lib/generators/roodi.rb +24 -0
- data/lib/generators/saikuro.rb +212 -0
- data/lib/generators/stats.rb +43 -0
- data/lib/metric_fu.rb +20 -0
- data/lib/templates/standard/churn.html.erb +30 -0
- data/lib/templates/standard/default.css +64 -0
- data/lib/templates/standard/flay.html.erb +33 -0
- 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/standard/roodi.html.erb +28 -0
- 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/base/md5_tracker_spec.rb +57 -0
- 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 +200 -0
- data/spec/generators/reek_spec.rb +59 -0
- data/spec/generators/saikuro_spec.rb +53 -0
- data/spec/generators/stats_spec.rb +74 -0
- data/spec/spec_helper.rb +28 -0
- data/tasks/metric_fu.rake +15 -0
- data/tasks/railroad.rake +39 -0
- data/vendor/saikuro/saikuro.rb +1214 -0
- metadata +163 -0
@@ -0,0 +1,59 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
describe Reek do
|
4
|
+
describe "analyze method" do
|
5
|
+
before :each do
|
6
|
+
@lines = <<-HERE
|
7
|
+
"app/controllers/activity_reports_controller.rb" -- 4 warnings:
|
8
|
+
ActivityReportsController#authorize_user calls current_user.primary_site_ids multiple times (Duplication)
|
9
|
+
ActivityReportsController#authorize_user calls params[id] multiple times (Duplication)
|
10
|
+
ActivityReportsController#authorize_user calls params[primary_site_id] multiple times (Duplication)
|
11
|
+
ActivityReportsController#authorize_user has approx 6 statements (Long Method)
|
12
|
+
|
13
|
+
"app/controllers/application.rb" -- 1 warnings:
|
14
|
+
ApplicationController#start_background_task/block/block is nested (Nested Iterators)
|
15
|
+
|
16
|
+
"app/controllers/link_targets_controller.rb" -- 1 warnings:
|
17
|
+
LinkTargetsController#authorize_user calls current_user.role multiple times (Duplication)
|
18
|
+
|
19
|
+
"app/controllers/newline_controller.rb" -- 1 warnings:
|
20
|
+
NewlineController#some_method calls current_user.<< "new line\n" multiple times (Duplication)
|
21
|
+
HERE
|
22
|
+
MetricFu::Configuration.run {}
|
23
|
+
File.stub!(:directory?).and_return(true)
|
24
|
+
reek = MetricFu::Reek.new
|
25
|
+
reek.instance_variable_set(:@output, @lines)
|
26
|
+
@matches = reek.analyze
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should find the code smell's method name" do
|
30
|
+
smell = @matches.first[:code_smells].first
|
31
|
+
smell[:method].should == "ActivityReportsController#authorize_user"
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should find the code smell's type" do
|
35
|
+
smell = @matches[1][:code_smells].first
|
36
|
+
smell[:type].should == "Nested Iterators"
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should find the code smell's message" do
|
40
|
+
smell = @matches[1][:code_smells].first
|
41
|
+
smell[:message].should == "is nested"
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should find the code smell's type" do
|
45
|
+
smell = @matches.first
|
46
|
+
smell[:file_path].should == "app/controllers/activity_reports_controller.rb"
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should NOT insert nil smells into the array when there's a newline in the method call" do
|
50
|
+
@matches.last[:code_smells].should == @matches.last[:code_smells].compact
|
51
|
+
@matches.last.should == {:file_path=>"app/controllers/newline_controller.rb",
|
52
|
+
:code_smells=>[{:type=>"Duplication",
|
53
|
+
:method=>"\"",
|
54
|
+
:message=>"multiple times"}]}
|
55
|
+
# Note: hopefully a temporary solution until I figure out how to deal with newlines in the method call more effectively -Jake 5/11/2009
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
describe Saikuro do
|
4
|
+
describe "to_h method" do
|
5
|
+
before :all do
|
6
|
+
MetricFu::Configuration.run {}
|
7
|
+
File.stub!(:directory?).and_return(true)
|
8
|
+
saikuro = MetricFu::Saikuro.new
|
9
|
+
saikuro.stub!(:metric_directory).and_return(File.join(File.dirname(__FILE__), "..", "resources", "saikuro"))
|
10
|
+
saikuro.analyze
|
11
|
+
@output = saikuro.to_h
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should find the filename of a file" do
|
15
|
+
@output[:saikuro][:files].first[:filename].should == 'users_controller.rb'
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should find the name of the classes" do
|
19
|
+
@output[:saikuro][:classes].first[:name].should == "UsersController"
|
20
|
+
@output[:saikuro][:classes][1][:name].should == "SessionsController"
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should put the most complex method first" do
|
24
|
+
@output[:saikuro][:methods].first[:name].should == "UsersController#create"
|
25
|
+
@output[:saikuro][:methods].first[:complexity].should == 4
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should find the complexity of a method" do
|
29
|
+
@output[:saikuro][:methods].first[:complexity].should == 4
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should find the lines of a method" do
|
33
|
+
@output[:saikuro][:methods].first[:lines].should == 15
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
describe "emit method" do
|
38
|
+
it "should format the directories" do
|
39
|
+
MetricFu::Configuration.run {}
|
40
|
+
File.stub!(:directory?).and_return(true)
|
41
|
+
saikuro = MetricFu::Saikuro.new
|
42
|
+
|
43
|
+
MetricFu.saikuro[:input_directory] = ["app", "lib"]
|
44
|
+
|
45
|
+
File.stub!(:dirname).and_return('..')
|
46
|
+
File.stub!(:expand_path)
|
47
|
+
|
48
|
+
saikuro.should_receive(:sh).with(/"app \| lib"/)
|
49
|
+
|
50
|
+
saikuro.emit
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
describe Stats do
|
4
|
+
describe "emit method" do
|
5
|
+
it "should gather the raw data" do
|
6
|
+
MetricFu::Configuration.run {}
|
7
|
+
File.stub!(:directory?).and_return(true)
|
8
|
+
stats = MetricFu::Stats.new
|
9
|
+
stats.should_receive(:`).with("rake stats > tmp/metric_fu/scratch/stats/stats.txt")
|
10
|
+
stats.emit
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "analyze method" do
|
15
|
+
before :each do
|
16
|
+
@lines = <<-HERE.gsub(/^\s*/, "")
|
17
|
+
+----------------------+-------+-------+---------+---------+-----+-------+
|
18
|
+
| Name | Lines | LOC | Classes | Methods | M/C | LOC/M |
|
19
|
+
+----------------------+-------+-------+---------+---------+-----+-------+
|
20
|
+
| Controllers | 470 | 382 | 7 | 53 | 7 | 5 |
|
21
|
+
| Helpers | 128 | 65 | 0 | 6 | 0 | 8 |
|
22
|
+
| Models | 351 | 285 | 9 | 31 | 3 | 7 |
|
23
|
+
| Libraries | 305 | 183 | 2 | 30 | 15 | 4 |
|
24
|
+
| Model specs | 860 | 719 | 0 | 2 | 0 | 357 |
|
25
|
+
| View specs | 0 | 0 | 0 | 0 | 0 | 0 |
|
26
|
+
| Controller specs | 1570 | 1308 | 1 | 10 | 10 | 128 |
|
27
|
+
| Helper specs | 191 | 172 | 0 | 0 | 0 | 0 |
|
28
|
+
| Library specs | 31 | 27 | 0 | 0 | 0 | 0 |
|
29
|
+
+----------------------+-------+-------+---------+---------+-----+-------+
|
30
|
+
| Total | 3906 | 3141 | 19 | 132 | 6 | 21 |
|
31
|
+
+----------------------+-------+-------+---------+---------+-----+-------+
|
32
|
+
Code LOC: 915 Test LOC: 2226 Code to Test Ratio: 1:2.4
|
33
|
+
|
34
|
+
HERE
|
35
|
+
MetricFu::Configuration.run {}
|
36
|
+
File.stub!(:directory?).and_return(true)
|
37
|
+
stats = MetricFu::Stats.new
|
38
|
+
File.should_receive(:open).and_return(mock("file", :read => @lines))
|
39
|
+
@results = stats.analyze
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should get code Lines Of Code" do
|
43
|
+
@results[:codeLOC].should == 915
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should get test Lines Of Code" do
|
47
|
+
@results[:testLOC].should == 2226
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should get code to test ratio" do
|
51
|
+
@results[:code_to_test_ratio].should == 2.4
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should get data on models" do
|
55
|
+
model_data = @results[:lines].find {|line| line[:name] == "Models"}
|
56
|
+
model_data[:classes].should == 9
|
57
|
+
model_data[:methods].should == 31
|
58
|
+
model_data[:loc].should == 285
|
59
|
+
model_data[:lines].should == 351
|
60
|
+
model_data[:methods_per_class].should == 3
|
61
|
+
model_data[:loc_per_method].should == 7
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
describe "to_h method" do
|
66
|
+
it "should put things into a hash" do
|
67
|
+
MetricFu::Configuration.run {}
|
68
|
+
File.stub!(:directory?).and_return(true)
|
69
|
+
stats = MetricFu::Stats.new
|
70
|
+
stats.instance_variable_set(:@stats, "the_stats")
|
71
|
+
stats.to_h[:stats].should == "the_stats"
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'spec'
|
3
|
+
require 'date'
|
4
|
+
|
5
|
+
require File.join(File.dirname(__FILE__), '/../lib/metric_fu.rb')
|
6
|
+
include MetricFu
|
7
|
+
|
8
|
+
Mystat = <<-EOF
|
9
|
+
(in /Users/gmcinnes/Documents/projects/NeerBeer/src/Web)
|
10
|
+
+----------------------+-------+-------+---------+---------+-----+-------+
|
11
|
+
| Name | Lines | LOC | Classes | Methods | M/C | LOC/M |
|
12
|
+
+----------------------+-------+-------+---------+---------+-----+-------+
|
13
|
+
| Controllers | 893 | 405 | 16 | 41 | 2 | 7 |
|
14
|
+
| Helpers | 569 | 352 | 0 | 52 | 0 | 4 |
|
15
|
+
| Models | 1758 | 453 | 26 | 48 | 1 | 7 |
|
16
|
+
| Libraries | 2507 | 1320 | 19 | 175 | 9 | 5 |
|
17
|
+
| Model specs | 2285 | 965 | 0 | 1 | 0 | 963 |
|
18
|
+
| View specs | 821 | 654 | 0 | 2 | 0 | 325 |
|
19
|
+
| Controller specs | 1144 | 871 | 0 | 9 | 0 | 94 |
|
20
|
+
| Helper specs | 652 | 465 | 0 | 1 | 0 | 463 |
|
21
|
+
| Library specs | 1456 | 1141 | 8 | 14 | 1 | 79 |
|
22
|
+
+----------------------+-------+-------+---------+---------+-----+-------+
|
23
|
+
| Total | 12085 | 6626 | 69 | 343 | 4 | 17 |
|
24
|
+
+----------------------+-------+-------+---------+---------+-----+-------+
|
25
|
+
Code LOC: 2530 Test LOC: 4096 Code to Test Ratio: 1:1.6
|
26
|
+
|
27
|
+
EOF
|
28
|
+
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'rake'
|
2
|
+
namespace :metrics do
|
3
|
+
desc "Generate all metrics reports"
|
4
|
+
task :all do
|
5
|
+
MetricFu::Configuration.run {}
|
6
|
+
MetricFu.metrics.each {|metric| MetricFu.report.add(metric) }
|
7
|
+
MetricFu.report.save_output(MetricFu.report.to_yaml,
|
8
|
+
MetricFu.base_directory,
|
9
|
+
'report.yml')
|
10
|
+
MetricFu.report.save_templatized_report
|
11
|
+
if MetricFu.report.open_in_browser?
|
12
|
+
MetricFu.report.show_in_browser(MetricFu.output_directory)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/tasks/railroad.rake
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
namespace :metrics do
|
2
|
+
|
3
|
+
RAILROAD_DIR = File.join(MetricFu::BASE_DIRECTORY, 'railroad')
|
4
|
+
RAILROAD_FILE = File.join(RAILROAD_DIR, 'index.html')
|
5
|
+
|
6
|
+
task :railroad => ['railroad:all'] do
|
7
|
+
end
|
8
|
+
|
9
|
+
namespace :railroad do
|
10
|
+
|
11
|
+
desc "Create all railroad reports"
|
12
|
+
task :all => [:models, :controllers, :aasm] do
|
13
|
+
#system("open #{RAILROAD_INDEX}") if PLATFORM['darwin']
|
14
|
+
end
|
15
|
+
|
16
|
+
desc "Create a railroad models report"
|
17
|
+
task :models do
|
18
|
+
#mkdir_p(RAILROAD_DIR) unless File.directory?(RAILROAD_DIR)
|
19
|
+
`railroad -M -a -m -l -v | neato -Tpng > #{File.join(MetricFu::BASE_DIRECTORY,'model-diagram.png')}`
|
20
|
+
#`echo "<a href=\"railroad/models.png\">Model diagram</a><br />" >> #{RAILROAD_FILE}`
|
21
|
+
end
|
22
|
+
|
23
|
+
desc "Create a railroad controllers report"
|
24
|
+
task :controllers do
|
25
|
+
#mkdir_p(RAILROAD_DIR) unless File.directory?(RAILROAD_DIR)
|
26
|
+
`railroad -C -l -v | neato -Tpng > #{File.join(MetricFu::BASE_DIRECTORY,'controller-diagram.png')}`
|
27
|
+
#`echo "<a href=\"railroad/controllers.png\">Controller diagram</a><br />" >> #{RAILROAD_FILE}`
|
28
|
+
end
|
29
|
+
|
30
|
+
desc "Create a railroad acts_as_state_machine report"
|
31
|
+
task :aasm do
|
32
|
+
#mkdir_p(RAILROAD_DIR) unless File.directory?(RAILROAD_DIR)
|
33
|
+
`railroad -A -l -v | neato -Tpng > #{File.join(MetricFu::BASE_DIRECTORY,'aasm-diagram.png')}`
|
34
|
+
#`echo "<a href=\"railroad/aasm.png\">State machine diagram</a><br />" >> #{RAILROAD_FILE}`
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|