metric_fu 2.0.0 → 2.0.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 +13 -5
  2. data/README +2 -2
  3. data/Rakefile +1 -1
  4. data/TODO +3 -1
  5. data/lib/base/base_template.rb +16 -16
  6. data/lib/base/churn_analyzer.rb +3 -3
  7. data/lib/base/code_issue.rb +8 -8
  8. data/lib/base/configuration.rb +24 -22
  9. data/lib/base/flay_analyzer.rb +2 -2
  10. data/lib/base/flog_analyzer.rb +4 -4
  11. data/lib/base/generator.rb +21 -21
  12. data/lib/base/graph.rb +15 -10
  13. data/lib/base/line_numbers.rb +56 -55
  14. data/lib/base/location.rb +68 -66
  15. data/lib/base/metric_analyzer.rb +21 -21
  16. data/lib/base/ranking.rb +23 -22
  17. data/lib/base/rcov_analyzer.rb +3 -3
  18. data/lib/base/reek_analyzer.rb +12 -10
  19. data/lib/base/report.rb +9 -9
  20. data/lib/base/roodi_analyzer.rb +2 -2
  21. data/lib/base/saikuro_analyzer.rb +4 -4
  22. data/lib/base/scoring_strategies.rb +5 -5
  23. data/lib/base/stats_analyzer.rb +2 -2
  24. data/lib/base/table.rb +4 -4
  25. data/lib/generators/churn.rb +1 -1
  26. data/lib/generators/flay.rb +1 -1
  27. data/lib/generators/hotspots.rb +4 -4
  28. data/lib/generators/rails_best_practices.rb +1 -1
  29. data/lib/generators/rcov.rb +17 -17
  30. data/lib/generators/reek.rb +2 -2
  31. data/lib/generators/saikuro.rb +42 -42
  32. data/lib/generators/stats.rb +6 -6
  33. data/lib/graphs/engines/bluff.rb +1 -1
  34. data/lib/graphs/engines/gchart.rb +7 -7
  35. data/lib/graphs/flog_grapher.rb +3 -3
  36. data/lib/graphs/grapher.rb +1 -1
  37. data/lib/metric_fu.rb +2 -2
  38. data/lib/templates/awesome/churn.html.erb +1 -1
  39. data/lib/templates/awesome/css/integrity.css +0 -1
  40. data/lib/templates/awesome/flay.html.erb +2 -2
  41. data/lib/templates/awesome/flog.html.erb +2 -2
  42. data/lib/templates/awesome/hotspots.html.erb +4 -4
  43. data/lib/templates/awesome/index.html.erb +2 -2
  44. data/lib/templates/awesome/rails_best_practices.html.erb +1 -1
  45. data/lib/templates/awesome/rcov.html.erb +1 -1
  46. data/lib/templates/awesome/roodi.html.erb +1 -1
  47. data/lib/templates/awesome/saikuro.html.erb +3 -3
  48. data/lib/templates/awesome/stats.html.erb +1 -1
  49. data/lib/templates/standard/churn.html.erb +2 -2
  50. data/lib/templates/standard/default.css +4 -4
  51. data/lib/templates/standard/flay.html.erb +4 -4
  52. data/lib/templates/standard/flog.html.erb +1 -1
  53. data/lib/templates/standard/hotspots.html.erb +4 -4
  54. data/lib/templates/standard/index.html.erb +2 -2
  55. data/lib/templates/standard/rails_best_practices.html.erb +2 -2
  56. data/lib/templates/standard/rcov.html.erb +2 -2
  57. data/lib/templates/standard/reek.html.erb +1 -1
  58. data/lib/templates/standard/roodi.html.erb +2 -2
  59. data/lib/templates/standard/saikuro.html.erb +4 -4
  60. data/lib/templates/standard/stats.html.erb +2 -2
  61. data/spec/base/base_template_spec.rb +1 -1
  62. data/spec/base/configuration_spec.rb +36 -36
  63. data/spec/base/generator_spec.rb +10 -10
  64. data/spec/base/graph_spec.rb +41 -4
  65. data/spec/base/line_numbers_spec.rb +22 -22
  66. data/spec/base/report_spec.rb +9 -9
  67. data/spec/generators/churn_spec.rb +4 -4
  68. data/spec/generators/flay_spec.rb +31 -31
  69. data/spec/generators/flog_spec.rb +18 -18
  70. data/spec/generators/rails_best_practices_spec.rb +6 -6
  71. data/spec/generators/rcov_spec.rb +18 -18
  72. data/spec/generators/reek_spec.rb +10 -10
  73. data/spec/generators/roodi_spec.rb +2 -2
  74. data/spec/generators/saikuro_spec.rb +7 -7
  75. data/spec/generators/stats_spec.rb +6 -6
  76. data/spec/graphs/engines/gchart_spec.rb +8 -8
  77. data/spec/graphs/flog_grapher_spec.rb +8 -8
  78. data/spec/resources/line_numbers/foo.rb +7 -7
  79. data/spec/resources/line_numbers/module.rb +2 -2
  80. data/spec/resources/line_numbers/module_surrounds_class.rb +6 -6
  81. data/spec/resources/saikuro/index_cyclo.html +2 -2
  82. data/spec/resources/yml/20090630.yml +349 -349
  83. data/spec/resources/yml/metric_missing.yml +1 -1
  84. data/tasks/metric_fu.rake +4 -4
  85. metadata +4 -4
@@ -9,15 +9,15 @@ describe RailsBestPractices do
9
9
  practices.emit
10
10
  end
11
11
  end
12
-
12
+
13
13
  describe "analyze method" do
14
14
  before :each do
15
15
  output = <<-HERE.gsub(/^[^\S\n]*/, "")
16
16
  ./app/views/admin/testimonials/_form.html.erb:17 - replace instance variable with local variable
17
17
  ./app/controllers/admin/campaigns_controller.rb:24,45,68,85 - use before_filter for show,edit,update,destroy
18
-
18
+
19
19
  go to http://wiki.github.com/flyerhzm/rails_best_practices to see how to solve these errors.
20
-
20
+
21
21
  Found 2 errors.
22
22
  HERE
23
23
  MetricFu::Configuration.run {}
@@ -25,11 +25,11 @@ describe RailsBestPractices do
25
25
  practices.instance_variable_set(:@output, output)
26
26
  @results = practices.analyze
27
27
  end
28
-
28
+
29
29
  it "should get the total" do
30
30
  @results[:total].should == ["Found 2 errors."]
31
31
  end
32
-
32
+
33
33
  it "should get the problems" do
34
34
  @results[:problems].size.should == 2
35
35
  @results[:problems].first.should == { :line => "17",
@@ -40,7 +40,7 @@ describe RailsBestPractices do
40
40
  :file => "./app/controllers/admin/campaigns_controller.rb" }
41
41
  end
42
42
  end
43
-
43
+
44
44
  describe "to_h method" do
45
45
  it "should put things into a hash" do
46
46
  MetricFu::Configuration.run {}
@@ -1,13 +1,13 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
2
2
 
3
3
  describe MetricFu::Rcov do
4
-
4
+
5
5
  before :each do
6
6
  MetricFu::Configuration.run {}
7
7
  File.stub!(:directory?).and_return(true)
8
8
  @rcov = MetricFu::Rcov.new('base_dir')
9
9
  end
10
-
10
+
11
11
  describe "emit" do
12
12
  before :each do
13
13
  @rcov.stub!(:puts)
@@ -20,7 +20,7 @@ describe MetricFu::Rcov do
20
20
  Dir.should_receive(:mkdir).with(MetricFu::Rcov.metric_directory)
21
21
  @rcov.emit
22
22
  end
23
-
23
+
24
24
  it "should set the RAILS_ENV" do
25
25
  FileUtils.stub!(:rm_rf)
26
26
  Dir.stub!(:mkdir)
@@ -29,7 +29,7 @@ describe MetricFu::Rcov do
29
29
  @rcov.emit
30
30
  end
31
31
  end
32
-
32
+
33
33
  describe "with RCOV_OUTPUT fed into" do
34
34
  before :each do
35
35
  MetricFu.rcov[:external] = nil
@@ -38,7 +38,7 @@ describe MetricFu::Rcov do
38
38
  and_return(mock("io", :read => RCOV_OUTPUT))
39
39
  @files = @rcov.analyze
40
40
  end
41
-
41
+
42
42
  describe "analyze" do
43
43
  it "should compute percent of lines run" do
44
44
  @files["lib/templates/awesome/awesome_template.rb"][:percent_run].should == 13
@@ -72,14 +72,14 @@ describe MetricFu::Rcov do
72
72
  FileUtils.should_not_receive(:rm_rf)
73
73
  @rcov.emit
74
74
  end
75
-
75
+
76
76
  it "should open the external rcov analysis file" do
77
77
  File.should_receive(:open).
78
78
  with(MetricFu.rcov[:external]).
79
79
  and_return(mock("io", :read => RCOV_OUTPUT))
80
80
  @files = @rcov.analyze
81
81
  end
82
-
82
+
83
83
  end
84
84
 
85
85
 
@@ -107,18 +107,18 @@ Finished in 2.517686 seconds
107
107
  lib/templates/awesome/awesome_template.rb
108
108
  ================================================================================
109
109
  require 'fileutils'
110
-
110
+
111
111
  class AwesomeTemplate < MetricFu::Template
112
-
112
+
113
113
  def write
114
114
  !! # Getting rid of the crap before and after the project name from integrity
115
115
  !! @name = File.basename(Dir.pwd).gsub(/^\w+-|-\w+$/, "")
116
- !!
116
+ !!
117
117
  !! # Copy Bluff javascripts to output directory
118
118
  !! Dir[File.join(this_directory, '..', 'javascripts', '*')].each do |f|
119
119
  !! FileUtils.copy(f, File.join(MetricFu.output_directory, File.basename(f)))
120
120
  !! end
121
- !!
121
+ !!
122
122
  !! report.each_pair do |section, contents|
123
123
  !! if template_exists?(section)
124
124
  !! create_instance_var(section, contents)
@@ -128,7 +128,7 @@ lib/templates/awesome/awesome_template.rb
128
128
  !! MetricFu.report.save_output(html, MetricFu.output_directory, fn)
129
129
  !! end
130
130
  !! end
131
- !!
131
+ !!
132
132
  !! # Instance variables we need should already be created from above
133
133
  !! if template_exists?('index')
134
134
  !! @html = erbify('index')
@@ -137,18 +137,18 @@ lib/templates/awesome/awesome_template.rb
137
137
  !! MetricFu.report.save_output(html, MetricFu.output_directory, fn)
138
138
  !! end
139
139
  !! end
140
-
140
+
141
141
  def this_directory
142
142
  !! File.dirname(__FILE__)
143
143
  !! end
144
144
  !! end
145
-
145
+
146
146
  ================================================================================
147
147
  lib/templates/standard/standard_template.rb
148
148
  ================================================================================
149
149
  class StandardTemplate < MetricFu::Template
150
-
151
-
150
+
151
+
152
152
  def write
153
153
  !! report.each_pair do |section, contents|
154
154
  !! if template_exists?(section)
@@ -158,7 +158,7 @@ lib/templates/standard/standard_template.rb
158
158
  !! MetricFu.report.save_output(html, MetricFu.output_directory, fn)
159
159
  !! end
160
160
  !! end
161
- !!
161
+ !!
162
162
  !! # Instance variables we need should already be created from above
163
163
  !! if template_exists?('index')
164
164
  !! html = erbify('index')
@@ -166,7 +166,7 @@ lib/templates/standard/standard_template.rb
166
166
  !! MetricFu.report.save_output(html, MetricFu.output_directory, fn)
167
167
  !! end
168
168
  !! end
169
-
169
+
170
170
  def this_directory
171
171
  !! File.dirname(__FILE__)
172
172
  !! end
@@ -11,7 +11,7 @@ describe Reek do
11
11
  reek.emit
12
12
  end
13
13
  end
14
-
14
+
15
15
  describe "analyze method" do
16
16
  before :each do
17
17
  @lines = <<-HERE
@@ -36,37 +36,37 @@ NewlineController#some_method calls current_user.<< "new line\n" multiple times
36
36
  reek.instance_variable_set(:@output, @lines)
37
37
  @matches = reek.analyze
38
38
  end
39
-
39
+
40
40
  it "should find the code smell's method name" do
41
41
  smell = @matches.first[:code_smells].first
42
42
  smell[:method].should == "ActivityReportsController#authorize_user"
43
43
  end
44
-
44
+
45
45
  it "should find the code smell's type" do
46
46
  smell = @matches[1][:code_smells].first
47
47
  smell[:type].should == "Nested Iterators"
48
48
  end
49
-
49
+
50
50
  it "should find the code smell's message" do
51
51
  smell = @matches[1][:code_smells].first
52
52
  smell[:message].should == "is nested"
53
53
  end
54
-
54
+
55
55
  it "should find the code smell's type" do
56
56
  smell = @matches.first
57
57
  smell[:file_path].should == "app/controllers/activity_reports_controller.rb"
58
58
  end
59
-
59
+
60
60
  it "should NOT insert nil smells into the array when there's a newline in the method call" do
61
61
  @matches.last[:code_smells].should == @matches.last[:code_smells].compact
62
- @matches.last.should == {:file_path=>"app/controllers/newline_controller.rb",
63
- :code_smells=>[{:type=>"Duplication",
64
- :method=>"\"",
62
+ @matches.last.should == {:file_path=>"app/controllers/newline_controller.rb",
63
+ :code_smells=>[{:type=>"Duplication",
64
+ :method=>"\"",
65
65
  :message=>"multiple times"}]}
66
66
  # Note: hopefully a temporary solution until I figure out how to deal with newlines in the method call more effectively -Jake 5/11/2009
67
67
  end
68
68
  end
69
-
69
+
70
70
  end
71
71
 
72
72
  describe Reek do
@@ -1,6 +1,6 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
2
2
 
3
- describe Roodi do
3
+ describe Roodi do
4
4
  describe "emit" do
5
5
  it "should add config options when present" do
6
6
  MetricFu::Configuration.run do |config|
@@ -10,7 +10,7 @@ describe Roodi do
10
10
  roodi.should_receive(:`).with(/-config=lib\/config\/roodi_config\.yml/).and_return("")
11
11
  roodi.emit
12
12
  end
13
-
13
+
14
14
  it "should NOT add config options when NOT present" do
15
15
  MetricFu::Configuration.run do |config|
16
16
  config.roodi = {:dirs_to_roodi => []}
@@ -1,5 +1,5 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
2
-
2
+
3
3
  describe Saikuro do
4
4
  describe "to_h method" do
5
5
  before :all do
@@ -14,7 +14,7 @@ describe Saikuro do
14
14
  it "should find the filename of a file" do
15
15
  @output[:saikuro][:files].first[:filename].should == 'users_controller.rb'
16
16
  end
17
-
17
+
18
18
  it "should find the name of the classes" do
19
19
  @output[:saikuro][:classes].first[:name].should == "UsersController"
20
20
  @output[:saikuro][:classes][1][:name].should == "SessionsController"
@@ -24,11 +24,11 @@ describe Saikuro do
24
24
  @output[:saikuro][:methods].first[:name].should == "UsersController#create"
25
25
  @output[:saikuro][:methods].first[:complexity].should == 4
26
26
  end
27
-
27
+
28
28
  it "should find the complexity of a method" do
29
29
  @output[:saikuro][:methods].first[:complexity].should == 4
30
30
  end
31
-
31
+
32
32
  it "should find the lines of a method" do
33
33
  @output[:saikuro][:methods].first[:lines].should == 15
34
34
  end
@@ -39,13 +39,13 @@ describe Saikuro do
39
39
  MetricFu::Configuration.run {}
40
40
  File.stub!(:directory?).and_return(true)
41
41
  saikuro = MetricFu::Saikuro.new
42
-
42
+
43
43
  MetricFu.saikuro[:input_directory] = ["app", "lib"]
44
-
44
+
45
45
  saikuro.format_directories.should == "\"app | lib\""
46
46
  end
47
47
  end
48
-
48
+
49
49
  describe Saikuro::SFile do
50
50
  describe "getting elements from a Saikuro result file" do
51
51
  it "should parse nested START/END sections" do
@@ -10,7 +10,7 @@ describe Stats do
10
10
  stats.emit
11
11
  end
12
12
  end
13
-
13
+
14
14
  describe "analyze method" do
15
15
  before :each do
16
16
  @lines = <<-HERE.gsub(/^\s*/, "")
@@ -38,19 +38,19 @@ describe Stats do
38
38
  File.should_receive(:open).and_return(mock("file", :read => @lines))
39
39
  @results = stats.analyze
40
40
  end
41
-
41
+
42
42
  it "should get code Lines Of Code" do
43
43
  @results[:codeLOC].should == 915
44
44
  end
45
-
45
+
46
46
  it "should get test Lines Of Code" do
47
47
  @results[:testLOC].should == 2226
48
48
  end
49
-
49
+
50
50
  it "should get code to test ratio" do
51
51
  @results[:code_to_test_ratio].should == 2.4
52
52
  end
53
-
53
+
54
54
  it "should get data on models" do
55
55
  model_data = @results[:lines].find {|line| line[:name] == "Models"}
56
56
  model_data[:classes].should == 9
@@ -61,7 +61,7 @@ describe Stats do
61
61
  model_data[:loc_per_method].should == 7
62
62
  end
63
63
  end
64
-
64
+
65
65
  describe "to_h method" do
66
66
  it "should put things into a hash" do
67
67
  MetricFu::Configuration.run {}
@@ -18,12 +18,12 @@ describe MetricFu::GchartGrapher do
18
18
  grapher.instance_variable_get(:@max_value).should == 10
19
19
  grapher.instance_variable_get(:@yaxis).should == [0, 2, 4, 6, 8, 10]
20
20
  end
21
-
21
+
22
22
  it "should set max value of the graph above largest value" do
23
23
  grapher = Object.new.extend(MetricFu::GchartGrapher)
24
24
  grapher.determine_y_axis_scale([19])
25
25
  grapher.instance_variable_get(:@max_value).should == 20
26
-
26
+
27
27
  grapher.determine_y_axis_scale([20])
28
28
  grapher.instance_variable_get(:@max_value).should == 25
29
29
  end
@@ -34,7 +34,7 @@ describe "Gchart graphers" do
34
34
  before :each do
35
35
  MetricFu::Configuration.run {|config| config.graph_engine = :gchart}
36
36
  end
37
-
37
+
38
38
  describe "FlayGchartGrapher graph! method" do
39
39
  it "should set static values for graph" do
40
40
  grapher = FlayGchartGrapher.new
@@ -49,7 +49,7 @@ describe "Gchart graphers" do
49
49
  grapher.graph!
50
50
  end
51
51
  end
52
-
52
+
53
53
  describe "FlogGchartGrapher graph! method" do
54
54
  it "should set static values for graph" do
55
55
  grapher = FlogGchartGrapher.new
@@ -68,7 +68,7 @@ describe "Gchart graphers" do
68
68
  grapher.graph!
69
69
  end
70
70
  end
71
-
71
+
72
72
  describe "RcovGchartGrapher graph! method" do
73
73
  it "should set static values for graph" do
74
74
  grapher = RcovGchartGrapher.new
@@ -85,7 +85,7 @@ describe "Gchart graphers" do
85
85
  grapher.graph!
86
86
  end
87
87
  end
88
-
88
+
89
89
  describe "ReekGchartGrapher graph! method" do
90
90
  it "should set static values for graph" do
91
91
  grapher = ReekGchartGrapher.new
@@ -102,7 +102,7 @@ describe "Gchart graphers" do
102
102
  grapher.graph!
103
103
  end
104
104
  end
105
-
105
+
106
106
  describe "RoodiGchartGrapher graph! method" do
107
107
  it "should set static values for graph" do
108
108
  grapher = RoodiGchartGrapher.new
@@ -117,7 +117,7 @@ describe "Gchart graphers" do
117
117
  grapher.graph!
118
118
  end
119
119
  end
120
-
120
+
121
121
  describe "StatsGchartGrapher graph! method" do
122
122
  it "should set static values for graph" do
123
123
  grapher = StatsGchartGrapher.new
@@ -4,7 +4,7 @@ describe MetricFu::FlogGrapher do
4
4
  before :each do
5
5
  MetricFu.configuration
6
6
  @flog_grapher = MetricFu::FlogGrapher.new
7
-
7
+
8
8
  end
9
9
 
10
10
  it "should respond to flog_total, flog_average and labels" do
@@ -27,24 +27,24 @@ describe MetricFu::FlogGrapher do
27
27
  100.times do |i|
28
28
  methods["method_name_#{i}"] = {:score => i.to_f}
29
29
  end
30
-
30
+
31
31
  @metrics = {:flog => {:total => 111.1,
32
32
  :average => 7.7,
33
33
  :method_containers => [ {:methods => methods } ] } }
34
34
  @date = "1/2"
35
35
  end
36
-
36
+
37
37
  it "should push to top_five_percent_average" do
38
38
  average = (99.0 + 98.0 + 97.0 + 96.0 + 95.0) / 5.0
39
- @flog_grapher.top_five_percent_average.should_receive(:push).with(average)
39
+ @flog_grapher.top_five_percent_average.should_receive(:push).with(average)
40
40
  @flog_grapher.get_metrics(@metrics, @date)
41
41
  end
42
-
42
+
43
43
  it "should push 9.9 to flog_average" do
44
44
  @flog_grapher.flog_average.should_receive(:push).with(7.7)
45
45
  @flog_grapher.get_metrics(@metrics, @date)
46
46
  end
47
-
47
+
48
48
  context "when metrics were not generated" do
49
49
  before(:each) do
50
50
  @metrics = YAML::load(File.open(File.join(File.dirname(__FILE__), "..", "resources", "yml", "metric_missing.yml")))
@@ -90,7 +90,7 @@ describe MetricFu::FlogGrapher do
90
90
  end
91
91
  end
92
92
  end
93
-
93
+
94
94
  describe "responding to #get_metrics with legacy data" do
95
95
  before(:each) do
96
96
  @metrics = YAML::load(File.open(File.join(File.dirname(__FILE__), "..", "resources", "yml", "20090630.yml")))
@@ -100,7 +100,7 @@ describe MetricFu::FlogGrapher do
100
100
 
101
101
  it "should push to top_five_percent_average" do
102
102
  average = (73.6 + 68.5 + 66.1 + 46.6 + 44.8 + 44.1 + 41.2 + 36.0) / 8.0
103
- @flog_grapher.top_five_percent_average.should_receive(:push).with(average)
103
+ @flog_grapher.top_five_percent_average.should_receive(:push).with(average)
104
104
  @flog_grapher.get_metrics(@metrics, @date)
105
105
  end
106
106
  end