jscruggs-metric_fu 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/HISTORY +6 -0
- data/lib/generators/flog.rb +1 -1
- data/lib/generators/reek.rb +2 -1
- data/lib/generators/roodi.rb +0 -4
- data/lib/generators/saikuro.rb +13 -3
- data/spec/generators/flog_spec.rb +12 -1
- data/spec/generators/reek_spec.rb +20 -8
- data/spec/generators/saikuro_spec.rb +43 -25
- metadata +1 -1
data/HISTORY
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
=== MetricFu 1.0.2 / 2009-5-11
|
2
|
+
|
3
|
+
* Fixing problems with Reek new line character (thanks to all who pointed this out)
|
4
|
+
* Flog now recognizes namespaces in method names thanks to Daniel Guettler
|
5
|
+
* Saikuro now looks at multiple directories, again.
|
6
|
+
|
1
7
|
=== MetricFu 1.0.1 / 2009-5-3
|
2
8
|
|
3
9
|
* metrics:all task no longer requires a MetricFu::Configuration.run {} if you want to accept the defaults
|
data/lib/generators/flog.rb
CHANGED
data/lib/generators/reek.rb
CHANGED
@@ -15,10 +15,11 @@ module MetricFu
|
|
15
15
|
file_path = file_path.gsub('"', ' ').strip
|
16
16
|
code_smells = match.map do |smell|
|
17
17
|
match_object = smell.match(REEK_REGEX)
|
18
|
+
next unless match_object
|
18
19
|
{:method => match_object[1].strip,
|
19
20
|
:message => match_object[2].strip,
|
20
21
|
:type => match_object[3].strip}
|
21
|
-
end
|
22
|
+
end.compact
|
22
23
|
{:file_path => file_path, :code_smells => code_smells}
|
23
24
|
end
|
24
25
|
end
|
data/lib/generators/roodi.rb
CHANGED
data/lib/generators/saikuro.rb
CHANGED
@@ -7,9 +7,13 @@ class Saikuro < Generator
|
|
7
7
|
relative_path = [File.dirname(__FILE__), '..', '..',
|
8
8
|
'vendor', 'saikuro', 'saikuro.rb']
|
9
9
|
saikuro = File.expand_path(File.join(relative_path))
|
10
|
-
|
11
|
-
|
12
|
-
|
10
|
+
|
11
|
+
format_directories
|
12
|
+
|
13
|
+
options_string = MetricFu.saikuro.inject("") do |options, option|
|
14
|
+
options + "--#{option.join(' ')} "
|
15
|
+
end
|
16
|
+
|
13
17
|
sh %{ruby "#{saikuro}" #{options_string}} do |ok, response|
|
14
18
|
unless ok
|
15
19
|
puts "Saikuro failed with exit status: #{response.exitstatus}"
|
@@ -17,6 +21,12 @@ class Saikuro < Generator
|
|
17
21
|
end
|
18
22
|
end
|
19
23
|
end
|
24
|
+
|
25
|
+
def format_directories
|
26
|
+
dirs = MetricFu.saikuro[:input_directory].join(" | ")
|
27
|
+
dirs = "\"#{dirs}\""
|
28
|
+
MetricFu.saikuro[:input_directory] = dirs
|
29
|
+
end
|
20
30
|
|
21
31
|
def analyze
|
22
32
|
@files = []
|
@@ -1,5 +1,4 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
-
|
3
2
|
describe Flog do
|
4
3
|
before :each do
|
5
4
|
@text = <<-HERE
|
@@ -157,6 +156,18 @@ describe Flog do
|
|
157
156
|
it "should find the scanned method opperators scores" do
|
158
157
|
@flog_page.scanned_methods.first.operators.first.score.should == 9.2
|
159
158
|
end
|
159
|
+
|
160
|
+
it "should find the name of the method even if namespaced" do
|
161
|
+
text = <<-HERE
|
162
|
+
157.9: flog total
|
163
|
+
11.3: flog/method average
|
164
|
+
|
165
|
+
34.8: SomeNamespace::UsersController#create
|
166
|
+
HERE
|
167
|
+
flog = MetricFu::Flog.new('base_dir')
|
168
|
+
flog_page = flog.parse(text)
|
169
|
+
flog_page.scanned_methods.first.name.should == "SomeNamespace::UsersController#create"
|
170
|
+
end
|
160
171
|
end
|
161
172
|
|
162
173
|
describe "to_h function" do
|
@@ -15,6 +15,9 @@ ApplicationController#start_background_task/block/block is nested (Nested Iterat
|
|
15
15
|
|
16
16
|
"app/controllers/link_targets_controller.rb" -- 1 warnings:
|
17
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)
|
18
21
|
HERE
|
19
22
|
MetricFu::Configuration.run {}
|
20
23
|
File.stub!(:directory?).and_return(true)
|
@@ -24,23 +27,32 @@ LinkTargetsController#authorize_user calls current_user.role multiple times (Dup
|
|
24
27
|
end
|
25
28
|
|
26
29
|
it "should find the code smell's method name" do
|
27
|
-
|
28
|
-
|
30
|
+
smell = @matches.first[:code_smells].first
|
31
|
+
smell[:method].should == "ActivityReportsController#authorize_user"
|
29
32
|
end
|
30
33
|
|
31
34
|
it "should find the code smell's type" do
|
32
|
-
|
33
|
-
|
35
|
+
smell = @matches[1][:code_smells].first
|
36
|
+
smell[:type].should == "Nested Iterators"
|
34
37
|
end
|
35
38
|
|
36
39
|
it "should find the code smell's message" do
|
37
|
-
|
38
|
-
|
40
|
+
smell = @matches[1][:code_smells].first
|
41
|
+
smell[:message].should == "is nested"
|
39
42
|
end
|
40
43
|
|
41
44
|
it "should find the code smell's type" do
|
42
|
-
|
43
|
-
|
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
|
44
56
|
end
|
45
57
|
end
|
46
58
|
|
@@ -1,35 +1,53 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/../spec_helper'
|
2
2
|
|
3
3
|
describe Saikuro do
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
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
13
|
|
14
|
-
|
15
|
-
|
16
|
-
|
14
|
+
it "should find the filename of a file" do
|
15
|
+
@output[:saikuro][:files].first[:filename].should == 'users_controller.rb'
|
16
|
+
end
|
17
17
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
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
22
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
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
|
27
31
|
|
28
|
-
|
29
|
-
|
32
|
+
it "should find the lines of a method" do
|
33
|
+
@output[:saikuro][:methods].first[:lines].should == 15
|
34
|
+
end
|
30
35
|
end
|
31
36
|
|
32
|
-
|
33
|
-
|
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
|
34
52
|
end
|
35
|
-
end
|
53
|
+
end
|