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 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
@@ -4,7 +4,7 @@ module MetricFu
4
4
  attr_reader :pages
5
5
 
6
6
  SCORE_FORMAT = "%0.2f"
7
- METHOD_LINE_REGEX = /(\d+\.\d+):\s+([A-Za-z]+#.*)/
7
+ METHOD_LINE_REGEX = /(\d+\.\d+):\s+([A-Za-z:]+#.*)/
8
8
  OPERATOR_LINE_REGEX = /\s*(\d+\.\d+):\s(.*)$/
9
9
 
10
10
  def emit
@@ -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
@@ -1,12 +1,8 @@
1
1
  module MetricFu
2
-
3
-
4
2
  class Roodi < Generator
5
-
6
3
  def emit
7
4
  files_to_analyze = MetricFu.roodi[:dirs_to_roodi].map{|dir| Dir[File.join(dir, "**/*.rb")] }
8
5
  @output = `roodi #{files_to_analyze.join(" ")}`
9
-
10
6
  end
11
7
 
12
8
  def analyze
@@ -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
- options_string = MetricFu.saikuro.inject("") do |o, h|
11
- o + "--#{h.join(' ')} "
12
- end
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
- first_smell = @matches.first[:code_smells].first
28
- first_smell[:method].should == "ActivityReportsController#authorize_user"
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
- first_smell = @matches[1][:code_smells].first
33
- first_smell[:type].should == "Nested Iterators"
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
- first_smell = @matches[1][:code_smells].first
38
- first_smell[:message].should == "is nested"
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
- first_smell = @matches.first
43
- first_smell[:file_path].should == "app/controllers/activity_reports_controller.rb"
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
- 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
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
- it "should find the filename of a file" do
15
- @output[:saikuro][:files].first[:filename].should == 'users_controller.rb'
16
- end
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
- 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
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
- 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
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
- it "should find the complexity of a method" do
29
- @output[:saikuro][:methods].first[:complexity].should == 4
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
- it "should find the lines of a method" do
33
- @output[:saikuro][:methods].first[:lines].should == 15
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jscruggs-metric_fu
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jake Scruggs