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,152 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
describe Churn do
|
4
|
+
describe "initialize" do
|
5
|
+
before :each do
|
6
|
+
MetricFu::Configuration.run {}
|
7
|
+
File.stub!(:directory?).and_return(true)
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should setup git if .git exits" do
|
11
|
+
File.should_receive(:exist?).with(".git").and_return(true)
|
12
|
+
Churn::Git.should_receive(:new)
|
13
|
+
MetricFu::Churn.new
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should setup git if .svn exits" do
|
17
|
+
File.should_receive(:exist?).with(".git").and_return(false)
|
18
|
+
File.should_receive(:exist?).with(".svn").and_return(true)
|
19
|
+
Churn::Svn.should_receive(:new)
|
20
|
+
MetricFu::Churn.new()
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should raise an error if not .svn or .git" do
|
24
|
+
File.stub!(:exist?).and_return(false)
|
25
|
+
lambda{MetricFu::Churn.new()}.should raise_error(Exception)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe "emit method with git" do
|
30
|
+
before :each do
|
31
|
+
MetricFu::Configuration.run {|config| config.churn = {:minimum_churn_count => 2} }
|
32
|
+
File.stub!(:directory?).and_return(true)
|
33
|
+
File.should_receive(:exist?).with(".git").and_return(true)
|
34
|
+
@git = Churn::Git.new
|
35
|
+
Churn::Git.should_receive(:new).and_return(@git)
|
36
|
+
@lines = <<-HERE.gsub(/^\s*/, "")
|
37
|
+
|
38
|
+
lib/generators/flog.rb
|
39
|
+
spec/generators/flog_spec.rb
|
40
|
+
|
41
|
+
|
42
|
+
lib/generators/flog.rb
|
43
|
+
spec/generators/flay_spec.rb
|
44
|
+
|
45
|
+
|
46
|
+
lib/metric_fu.rb
|
47
|
+
|
48
|
+
|
49
|
+
lib/generators/saikuro.rb
|
50
|
+
lib/metric_fu.rb
|
51
|
+
tasks/metric_fu.rake
|
52
|
+
|
53
|
+
|
54
|
+
spec/churn_spec.rb
|
55
|
+
spec/config_spec.rb
|
56
|
+
spec/flay_spec.rb
|
57
|
+
spec/flog_spec.rb
|
58
|
+
lib/metric_fu.rb
|
59
|
+
spec/reek_spec.rb
|
60
|
+
HERE
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should read the logs" do
|
64
|
+
churn = MetricFu::Churn.new
|
65
|
+
@git.should_receive(:`).with("git log --name-only --pretty=format:").and_return(@lines)
|
66
|
+
changes = churn.emit
|
67
|
+
changes["lib/generators/flog.rb"].should == 2
|
68
|
+
changes["lib/metric_fu.rb"].should == 3
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
describe "emit method with svn" do
|
73
|
+
before :each do
|
74
|
+
MetricFu::Configuration.run{|config| config.churn = {:minimum_churn_count => 2} }
|
75
|
+
File.stub!(:directory?).and_return(true)
|
76
|
+
File.should_receive(:exist?).with(".git").and_return(false)
|
77
|
+
File.should_receive(:exist?).with(".svn").and_return(true)
|
78
|
+
@svn = Churn::Svn.new
|
79
|
+
Churn::Svn.should_receive(:new).and_return(@svn)
|
80
|
+
@lines = <<-HERE.gsub(/^\s*/, "")
|
81
|
+
------------------------------------------------------------------------
|
82
|
+
r3183 | dave | 2009-04-28 07:23:37 -0500 (Tue, 28 Apr 2009) | 1 line
|
83
|
+
Changed paths:
|
84
|
+
M /trunk/app/views/promotions/index.erb
|
85
|
+
M /trunk/app/models/email_personalizer.rb
|
86
|
+
|
87
|
+
making custom macros case-insensitive
|
88
|
+
------------------------------------------------------------------------
|
89
|
+
r3182 | marc | 2009-04-28 03:59:32 -0500 (Tue, 28 Apr 2009) | 1 line
|
90
|
+
Changed paths:
|
91
|
+
M /trunk/app/models/file_extraction.rb
|
92
|
+
M /trunk/app/views/promotions/index.erb
|
93
|
+
M /trunk/config/environment.rb
|
94
|
+
|
95
|
+
Demo of the drop out effect for uploading promotions.
|
96
|
+
------------------------------------------------------------------------
|
97
|
+
r3181 | dave | 2009-04-27 21:40:04 -0500 (Mon, 27 Apr 2009) | 1 line
|
98
|
+
Changed paths:
|
99
|
+
M /trunk/app/views/promotions/index.erb
|
100
|
+
A /trunk/app/models/file_extraction.rb
|
101
|
+
A /trunk/app/models/url_file_extraction.rb
|
102
|
+
M /trunk/app/models/zip_file_extraction.rb
|
103
|
+
M /trunk/test/data/zip_test.zip
|
104
|
+
M /trunk/test/unit/zip_file_extraction_test.rb
|
105
|
+
|
106
|
+
URL imports
|
107
|
+
HERE
|
108
|
+
end
|
109
|
+
|
110
|
+
it "should read the logs" do
|
111
|
+
churn = MetricFu::Churn.new
|
112
|
+
@svn.should_receive(:`).with("svn log --verbose").and_return(@lines)
|
113
|
+
changes = churn.emit
|
114
|
+
changes["/trunk/app/views/promotions/index.erb"].should == 3
|
115
|
+
changes["/trunk/app/models/file_extraction.rb"].should == 2
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
describe "analyze method" do
|
120
|
+
before :each do
|
121
|
+
MetricFu::Configuration.run {}
|
122
|
+
File.stub!(:directory?).and_return(true)
|
123
|
+
File.should_receive(:exist?).with(".git").and_return(true)
|
124
|
+
@changes = {"lib/generators/flog.rb"=>2, "lib/metric_fu.rb"=>3}
|
125
|
+
end
|
126
|
+
|
127
|
+
it "should organize and format" do
|
128
|
+
churn = MetricFu::Churn.new
|
129
|
+
churn.instance_variable_set(:@changes, @changes)
|
130
|
+
changes = churn.analyze
|
131
|
+
changes.first[:file_path].should == "lib/metric_fu.rb"
|
132
|
+
changes.first[:times_changed].should == 3
|
133
|
+
changes[1][:file_path].should == "lib/generators/flog.rb"
|
134
|
+
changes[1][:times_changed].should == 2
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
describe "to_h method" do
|
139
|
+
before :each do
|
140
|
+
MetricFu::Configuration.run {}
|
141
|
+
File.stub!(:directory?).and_return(true)
|
142
|
+
File.should_receive(:exist?).with(".git").and_return(true)
|
143
|
+
end
|
144
|
+
|
145
|
+
it "should put the changes into a hash" do
|
146
|
+
churn = MetricFu::Churn.new
|
147
|
+
churn.instance_variable_set(:@changes, "churn_info")
|
148
|
+
churn.to_h[:churn][:changes].should == "churn_info"
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
@@ -0,0 +1,101 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper.rb'
|
2
|
+
|
3
|
+
describe Flay do
|
4
|
+
describe "emit method" do
|
5
|
+
before :each do
|
6
|
+
MetricFu::Configuration.run {|config| config.flay = { :dirs_to_flay => ['app', 'lib'] } }
|
7
|
+
File.stub!(:directory?).and_return(true)
|
8
|
+
@flay = MetricFu::Flay.new('base_dir')
|
9
|
+
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should look at the dirs" do
|
13
|
+
Dir.should_receive(:[]).with(File.join("app", "**/*.rb")).and_return("path/to/app")
|
14
|
+
Dir.should_receive(:[]).with(File.join("lib", "**/*.rb")).and_return("path/to/lib")
|
15
|
+
@flay.should_receive(:`).with("flay path/to/app path/to/lib")
|
16
|
+
output = @flay.emit
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe "analyze method" do
|
21
|
+
before :each do
|
22
|
+
lines = <<-HERE
|
23
|
+
Total score (lower is better) = 246
|
24
|
+
|
25
|
+
|
26
|
+
1) IDENTICAL code found in :or (mass*2 = 68)
|
27
|
+
app/controllers/link_targets_controller.rb:57
|
28
|
+
app/controllers/primary_sites_controller.rb:138
|
29
|
+
|
30
|
+
2) Similar code found in :if (mass = 64)
|
31
|
+
app/controllers/primary_sites_controller.rb:75
|
32
|
+
app/controllers/primary_sites_controller.rb:76
|
33
|
+
app/controllers/primary_sites_controller.rb:88
|
34
|
+
app/controllers/primary_sites_controller.rb:89
|
35
|
+
HERE
|
36
|
+
MetricFu::Configuration.run {}
|
37
|
+
File.stub!(:directory?).and_return(true)
|
38
|
+
@flay = MetricFu::Flay.new('base_dir')
|
39
|
+
@flay.instance_variable_set(:@output, lines)
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should analyze and return matches" do
|
43
|
+
@flay.analyze.should == [ ["Total score (lower is better) = 246"],
|
44
|
+
["\n1) IDENTICAL code found in :or (mass*2 = 68)",
|
45
|
+
"app/controllers/link_targets_controller.rb:57",
|
46
|
+
"app/controllers/primary_sites_controller.rb:138"],
|
47
|
+
["2) Similar code found in :if (mass = 64)",
|
48
|
+
"app/controllers/primary_sites_controller.rb:75",
|
49
|
+
"app/controllers/primary_sites_controller.rb:76",
|
50
|
+
"app/controllers/primary_sites_controller.rb:88",
|
51
|
+
"app/controllers/primary_sites_controller.rb:89"] ]
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
describe "to_h method" do
|
56
|
+
|
57
|
+
before :each do
|
58
|
+
lines = [ ["Total score (lower is better) = 284"],
|
59
|
+
["\n1) IDENTICAL code found in :or (mass*2 = 68)",
|
60
|
+
"app/controllers/link_targets_controller.rb:57",
|
61
|
+
"app/controllers/primary_sites_controller.rb:138"],
|
62
|
+
["2) Similar code found in :if (mass = 64)",
|
63
|
+
"app/controllers/primary_sites_controller.rb:75",
|
64
|
+
"app/controllers/primary_sites_controller.rb:76",
|
65
|
+
"app/controllers/primary_sites_controller.rb:88",
|
66
|
+
"app/controllers/primary_sites_controller.rb:89"],
|
67
|
+
["3) Similar code found in :defn (mass = 40)",
|
68
|
+
"app/controllers/link_targets_controller.rb:40",
|
69
|
+
"app/controllers/primary_sites_controller.rb:98"],
|
70
|
+
["4) Similar code found in :defn (mass = 38)",
|
71
|
+
"app/controllers/link_targets_controller.rb:13",
|
72
|
+
"app/controllers/primary_sites_controller.rb:50"],
|
73
|
+
["5) Similar code found in :defn (mass = 38)",
|
74
|
+
"app/models/primary_site.rb:104",
|
75
|
+
"app/models/primary_site.rb:109"],
|
76
|
+
["6) Similar code found in :call (mass = 36)",
|
77
|
+
"app/controllers/bookmarklet_integration_controller.rb:6",
|
78
|
+
"app/controllers/bookmarklet_integration_controller.rb:17"]]
|
79
|
+
|
80
|
+
MetricFu::Configuration.run {}
|
81
|
+
File.stub!(:directory?).and_return(true)
|
82
|
+
flay = MetricFu::Flay.new('base_dir')
|
83
|
+
flay.instance_variable_set(:@matches, lines)
|
84
|
+
@results = flay.to_h
|
85
|
+
end
|
86
|
+
|
87
|
+
it "should find the total_score" do
|
88
|
+
@results[:flay][:total_score].should == '284'
|
89
|
+
end
|
90
|
+
|
91
|
+
it "should have 6 matches" do
|
92
|
+
@results[:flay][:matches].size.should == 6
|
93
|
+
end
|
94
|
+
|
95
|
+
it "should capture info for match" do
|
96
|
+
@results[:flay][:matches].first[:reason].should =~ /IDENTICAL/
|
97
|
+
@results[:flay][:matches].first[:matches].first[:name].should =~ /link_targets_controller/
|
98
|
+
@results[:flay][:matches].first[:matches].first[:line].should == "57"
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
@@ -0,0 +1,189 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
describe Flog do
|
4
|
+
before :each do
|
5
|
+
@text = <<-HERE
|
6
|
+
157.9: flog total
|
7
|
+
11.3: flog/method average
|
8
|
+
|
9
|
+
34.8: UsersController#create
|
10
|
+
9.2: branch
|
11
|
+
6.8: current_user
|
12
|
+
5.2: assignment
|
13
|
+
3.4: role
|
14
|
+
3.0: render
|
15
|
+
3.0: ==
|
16
|
+
2.8: flash
|
17
|
+
1.6: after_create_page
|
18
|
+
1.6: params
|
19
|
+
1.5: activate!
|
20
|
+
1.5: errors
|
21
|
+
1.4: login
|
22
|
+
1.4: redirect_to
|
23
|
+
1.4: []
|
24
|
+
1.3: empty?
|
25
|
+
1.3: save
|
26
|
+
1.2: new
|
27
|
+
24.2: UsersController#authorize_user
|
28
|
+
4.8: branch
|
29
|
+
4.7: current_user
|
30
|
+
3.6: params
|
31
|
+
3.2: []
|
32
|
+
2.6: ==
|
33
|
+
1.5: role
|
34
|
+
1.5: to_i
|
35
|
+
1.5: id
|
36
|
+
1.4: new_session_path
|
37
|
+
1.3: include?
|
38
|
+
1.2: assignment
|
39
|
+
1.2: flash
|
40
|
+
1.2: redirect_to
|
41
|
+
16.4: UsersController#thank_you
|
42
|
+
4.0: assignment
|
43
|
+
3.3: params
|
44
|
+
2.9: []
|
45
|
+
2.7: redirect_to
|
46
|
+
2.4: branch
|
47
|
+
1.5: new_session_path
|
48
|
+
1.4: flash
|
49
|
+
1.4: activate!
|
50
|
+
1.3: can_activate?
|
51
|
+
1.2: find_by_id
|
52
|
+
14.2: UsersController#update
|
53
|
+
3.2: params
|
54
|
+
2.8: []
|
55
|
+
2.6: assignment
|
56
|
+
1.4: login
|
57
|
+
1.4: flash
|
58
|
+
1.4: redirect_to
|
59
|
+
1.3: render
|
60
|
+
1.2: branch
|
61
|
+
1.2: update_attributes
|
62
|
+
1.2: find_by_id
|
63
|
+
12.5: UsersController#sanitize_params
|
64
|
+
3.9: assignment
|
65
|
+
3.6: branch
|
66
|
+
3.0: current_user
|
67
|
+
1.6: params
|
68
|
+
1.5: role
|
69
|
+
1.4: []
|
70
|
+
1.3: include?
|
71
|
+
1.3: ==
|
72
|
+
1.2: reject!
|
73
|
+
10.6: UsersController#users_have_changed
|
74
|
+
3.9: assignment
|
75
|
+
2.6: branch
|
76
|
+
1.6: params
|
77
|
+
1.5: refresh_from_external
|
78
|
+
1.4: find_by_id
|
79
|
+
1.4: []
|
80
|
+
1.2: split
|
81
|
+
1.2: each
|
82
|
+
1.2: head
|
83
|
+
10.0: UsersController#after_create_page
|
84
|
+
3.0: current_user
|
85
|
+
2.6: id
|
86
|
+
2.4: branch
|
87
|
+
1.5: role
|
88
|
+
1.3: login
|
89
|
+
1.3: ==
|
90
|
+
8.4: UsersController#add_primary_site
|
91
|
+
2.4: assignment
|
92
|
+
1.6: params
|
93
|
+
1.4: []
|
94
|
+
1.4: new
|
95
|
+
1.2: find_by_id
|
96
|
+
1.2: all
|
97
|
+
1.2: render
|
98
|
+
7.7: UsersController#none
|
99
|
+
3.3: before_filter
|
100
|
+
1.1: private
|
101
|
+
1.1: caches_page
|
102
|
+
1.1: after_filter
|
103
|
+
1.1: skip_before_filter
|
104
|
+
7.2: UsersController#destroy
|
105
|
+
1.8: params
|
106
|
+
1.6: []
|
107
|
+
1.4: find_by_id
|
108
|
+
1.2: destroy
|
109
|
+
1.2: redirect_to
|
110
|
+
5.9: UsersController#edit
|
111
|
+
2.4: assignment
|
112
|
+
1.6: params
|
113
|
+
1.4: []
|
114
|
+
1.2: all
|
115
|
+
1.2: find_by_id
|
116
|
+
2.7: UsersController#signup
|
117
|
+
1.2: render
|
118
|
+
1.2: assignment
|
119
|
+
1.2: new
|
120
|
+
1.7: UsersController#new
|
121
|
+
1.2: assignment
|
122
|
+
1.2: new
|
123
|
+
1.7: UsersController#index
|
124
|
+
1.2: assignment
|
125
|
+
1.2: all
|
126
|
+
HERE
|
127
|
+
end
|
128
|
+
|
129
|
+
describe "parse method" do
|
130
|
+
before :each do
|
131
|
+
MetricFu::Configuration.run {}
|
132
|
+
File.stub!(:directory?).and_return(true)
|
133
|
+
flog = MetricFu::Flog.new('base_dir')
|
134
|
+
@flog_page = flog.parse(@text)
|
135
|
+
end
|
136
|
+
|
137
|
+
it "should find the total score" do
|
138
|
+
@flog_page.score.should == 157.9
|
139
|
+
end
|
140
|
+
|
141
|
+
it "should find the average score" do
|
142
|
+
@flog_page.average_score.should == 11.3
|
143
|
+
end
|
144
|
+
|
145
|
+
it "should find the scanned method score" do
|
146
|
+
@flog_page.scanned_methods.first.score.should == 34.8
|
147
|
+
end
|
148
|
+
|
149
|
+
it "should find the scanned method name" do
|
150
|
+
@flog_page.scanned_methods.first.name.should == "UsersController#create"
|
151
|
+
end
|
152
|
+
|
153
|
+
it "should find the scanned method opperators names" do
|
154
|
+
@flog_page.scanned_methods.first.operators.first.operator.should == "branch"
|
155
|
+
end
|
156
|
+
|
157
|
+
it "should find the scanned method opperators scores" do
|
158
|
+
@flog_page.scanned_methods.first.operators.first.score.should == 9.2
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
describe "to_h function" do
|
163
|
+
before :each do
|
164
|
+
MetricFu::Configuration.run {}
|
165
|
+
File.stub!(:directory?).and_return(true)
|
166
|
+
flog = MetricFu::Flog.new('base_dir')
|
167
|
+
flog.should_receive(:open).and_return(@text)
|
168
|
+
Dir.should_receive(:glob).and_return(["tmp/metric_fu/scratch/flog/app/controllers/user_controller.txt"])
|
169
|
+
flog.analyze
|
170
|
+
@flog_hash = flog.to_h
|
171
|
+
end
|
172
|
+
|
173
|
+
it "should put the total in the hash" do
|
174
|
+
@flog_hash[:flog][:total].should == 157.9
|
175
|
+
end
|
176
|
+
|
177
|
+
it "should put the average in the hash" do
|
178
|
+
@flog_hash[:flog][:average].should == 11.3
|
179
|
+
end
|
180
|
+
|
181
|
+
it "should put pages into the hash" do
|
182
|
+
@flog_hash[:flog][:pages].first[:scanned_methods].first[:score].should == 34.8
|
183
|
+
end
|
184
|
+
|
185
|
+
it "should put the filename into the hash" do
|
186
|
+
@flog_hash[:flog][:pages].first[:path].should == "/app/controllers/user_controller.rb"
|
187
|
+
end
|
188
|
+
end
|
189
|
+
end
|
@@ -0,0 +1,47 @@
|
|
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
|
+
HERE
|
19
|
+
MetricFu::Configuration.run {}
|
20
|
+
File.stub!(:directory?).and_return(true)
|
21
|
+
reek = MetricFu::Reek.new
|
22
|
+
reek.instance_variable_set(:@output, @lines)
|
23
|
+
@matches = reek.analyze
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should find the code smell's method name" do
|
27
|
+
first_smell = @matches.first[:code_smells].first
|
28
|
+
first_smell[:method].should == "ActivityReportsController#authorize_user"
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should find the code smell's type" do
|
32
|
+
first_smell = @matches[1][:code_smells].first
|
33
|
+
first_smell[:type].should == "Nested Iterators"
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should find the code smell's message" do
|
37
|
+
first_smell = @matches[1][:code_smells].first
|
38
|
+
first_smell[:message].should == "is nested"
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should find the code smell's type" do
|
42
|
+
first_smell = @matches.first
|
43
|
+
first_smell[:file_path].should == "app/controllers/activity_reports_controller.rb"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
describe Saikuro do
|
4
|
+
|
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
|
@@ -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
CHANGED
@@ -2,10 +2,27 @@ require 'rubygems'
|
|
2
2
|
require 'spec'
|
3
3
|
require 'date'
|
4
4
|
|
5
|
-
require File.join(File.dirname(__FILE__), '/../lib/metric_fu
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
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,14 @@
|
|
1
|
+
require 'rake'
|
2
|
+
namespace :metrics do
|
3
|
+
desc "Generate all metrics reports"
|
4
|
+
task :all do
|
5
|
+
MetricFu.metrics.each {|metric| MetricFu.report.add(metric) }
|
6
|
+
MetricFu.report.save_output(MetricFu.report.to_yaml,
|
7
|
+
MetricFu.base_directory,
|
8
|
+
'report.yml')
|
9
|
+
MetricFu.report.save_templatized_report
|
10
|
+
if MetricFu.report.open_in_browser?
|
11
|
+
MetricFu.report.show_in_browser(MetricFu.output_directory)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
File without changes
|
File without changes
|