bf4-metric_fu 2.1.3.1
Sign up to get free protection for your applications and to get access to all the features.
- data/HISTORY +252 -0
- data/MIT-LICENSE +22 -0
- data/README.md +49 -0
- data/Rakefile +22 -0
- data/TODO +6 -0
- data/lib/base/base_template.rb +182 -0
- data/lib/base/churn_analyzer.rb +38 -0
- data/lib/base/code_issue.rb +100 -0
- data/lib/base/configuration.rb +219 -0
- data/lib/base/flay_analyzer.rb +50 -0
- data/lib/base/flog_analyzer.rb +43 -0
- data/lib/base/generator.rb +166 -0
- data/lib/base/graph.rb +44 -0
- data/lib/base/grouping.rb +42 -0
- data/lib/base/line_numbers.rb +79 -0
- data/lib/base/location.rb +87 -0
- data/lib/base/md5_tracker.rb +52 -0
- data/lib/base/metric_analyzer.rb +331 -0
- data/lib/base/ranking.rb +34 -0
- data/lib/base/rcov_analyzer.rb +43 -0
- data/lib/base/record.rb +43 -0
- data/lib/base/reek_analyzer.rb +164 -0
- data/lib/base/report.rb +110 -0
- data/lib/base/roodi_analyzer.rb +37 -0
- data/lib/base/saikuro_analyzer.rb +48 -0
- data/lib/base/scoring_strategies.rb +29 -0
- data/lib/base/stats_analyzer.rb +37 -0
- data/lib/base/table.rb +108 -0
- data/lib/generators/churn.rb +28 -0
- data/lib/generators/flay.rb +31 -0
- data/lib/generators/flog.rb +113 -0
- data/lib/generators/hotspots.rb +52 -0
- data/lib/generators/rails_best_practices.rb +53 -0
- data/lib/generators/rcov.rb +124 -0
- data/lib/generators/reek.rb +81 -0
- data/lib/generators/roodi.rb +35 -0
- data/lib/generators/saikuro.rb +259 -0
- data/lib/generators/stats.rb +58 -0
- data/lib/graphs/engines/bluff.rb +113 -0
- data/lib/graphs/engines/gchart.rb +157 -0
- data/lib/graphs/flay_grapher.rb +18 -0
- data/lib/graphs/flog_grapher.rb +57 -0
- data/lib/graphs/grapher.rb +11 -0
- data/lib/graphs/rails_best_practices_grapher.rb +19 -0
- data/lib/graphs/rcov_grapher.rb +18 -0
- data/lib/graphs/reek_grapher.rb +30 -0
- data/lib/graphs/roodi_grapher.rb +18 -0
- data/lib/graphs/stats_grapher.rb +20 -0
- data/lib/metric_fu.rb +80 -0
- data/lib/tasks/metric_fu.rake +36 -0
- data/lib/templates/awesome/awesome_template.rb +92 -0
- data/lib/templates/awesome/churn.html.erb +58 -0
- data/lib/templates/awesome/css/buttons.css +82 -0
- data/lib/templates/awesome/css/default.css +91 -0
- data/lib/templates/awesome/css/integrity.css +334 -0
- data/lib/templates/awesome/css/reset.css +7 -0
- data/lib/templates/awesome/css/syntax.css +19 -0
- data/lib/templates/awesome/flay.html.erb +34 -0
- data/lib/templates/awesome/flog.html.erb +55 -0
- data/lib/templates/awesome/hotspots.html.erb +62 -0
- data/lib/templates/awesome/index.html.erb +34 -0
- data/lib/templates/awesome/layout.html.erb +30 -0
- data/lib/templates/awesome/rails_best_practices.html.erb +27 -0
- data/lib/templates/awesome/rcov.html.erb +42 -0
- data/lib/templates/awesome/reek.html.erb +40 -0
- data/lib/templates/awesome/roodi.html.erb +27 -0
- data/lib/templates/awesome/saikuro.html.erb +71 -0
- data/lib/templates/awesome/stats.html.erb +51 -0
- data/lib/templates/javascripts/bluff-min.js +1 -0
- data/lib/templates/javascripts/excanvas.js +35 -0
- data/lib/templates/javascripts/js-class.js +1 -0
- data/lib/templates/standard/churn.html.erb +31 -0
- data/lib/templates/standard/default.css +64 -0
- data/lib/templates/standard/flay.html.erb +34 -0
- data/lib/templates/standard/flog.html.erb +57 -0
- data/lib/templates/standard/hotspots.html.erb +54 -0
- data/lib/templates/standard/index.html.erb +41 -0
- data/lib/templates/standard/rails_best_practices.html.erb +29 -0
- data/lib/templates/standard/rcov.html.erb +43 -0
- data/lib/templates/standard/reek.html.erb +42 -0
- data/lib/templates/standard/roodi.html.erb +29 -0
- data/lib/templates/standard/saikuro.html.erb +84 -0
- data/lib/templates/standard/standard_template.rb +27 -0
- data/lib/templates/standard/stats.html.erb +55 -0
- data/spec/base/base_template_spec.rb +194 -0
- data/spec/base/configuration_spec.rb +277 -0
- data/spec/base/generator_spec.rb +223 -0
- data/spec/base/graph_spec.rb +61 -0
- data/spec/base/line_numbers_spec.rb +62 -0
- data/spec/base/location_spec.rb +127 -0
- data/spec/base/md5_tracker_spec.rb +57 -0
- data/spec/base/metric_analyzer_spec.rb +452 -0
- data/spec/base/ranking_spec.rb +42 -0
- data/spec/base/report_spec.rb +146 -0
- data/spec/base/table_spec.rb +36 -0
- data/spec/generators/churn_spec.rb +41 -0
- data/spec/generators/flay_spec.rb +105 -0
- data/spec/generators/flog_spec.rb +70 -0
- data/spec/generators/hotspots_spec.rb +88 -0
- data/spec/generators/rails_best_practices_spec.rb +52 -0
- data/spec/generators/rcov_spec.rb +180 -0
- data/spec/generators/reek_spec.rb +134 -0
- data/spec/generators/roodi_spec.rb +24 -0
- data/spec/generators/saikuro_spec.rb +74 -0
- data/spec/generators/stats_spec.rb +74 -0
- data/spec/graphs/engines/bluff_spec.rb +19 -0
- data/spec/graphs/engines/gchart_spec.rb +156 -0
- data/spec/graphs/flay_grapher_spec.rb +56 -0
- data/spec/graphs/flog_grapher_spec.rb +108 -0
- data/spec/graphs/rails_best_practices_grapher_spec.rb +61 -0
- data/spec/graphs/rcov_grapher_spec.rb +56 -0
- data/spec/graphs/reek_grapher_spec.rb +65 -0
- data/spec/graphs/roodi_grapher_spec.rb +56 -0
- data/spec/graphs/stats_grapher_spec.rb +68 -0
- data/spec/resources/line_numbers/foo.rb +33 -0
- data/spec/resources/line_numbers/module.rb +11 -0
- data/spec/resources/line_numbers/module_surrounds_class.rb +15 -0
- data/spec/resources/line_numbers/two_classes.rb +11 -0
- data/spec/resources/saikuro/app/controllers/sessions_controller.rb_cyclo.html +10 -0
- data/spec/resources/saikuro/app/controllers/users_controller.rb_cyclo.html +16 -0
- data/spec/resources/saikuro/index_cyclo.html +155 -0
- data/spec/resources/saikuro_sfiles/thing.rb_cyclo.html +11 -0
- data/spec/resources/yml/20090630.yml +7922 -0
- data/spec/resources/yml/metric_missing.yml +1 -0
- data/spec/spec.opts +6 -0
- data/spec/spec_helper.rb +7 -0
- metadata +560 -0
@@ -0,0 +1,52 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
|
2
|
+
|
3
|
+
describe RailsBestPractices do
|
4
|
+
describe "emit method" do
|
5
|
+
it "should gather the raw data" do
|
6
|
+
MetricFu::Configuration.run {}
|
7
|
+
practices = MetricFu::RailsBestPractices.new
|
8
|
+
practices.should_receive(:`).with("rails_best_practices --without-color .")
|
9
|
+
practices.emit
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "analyze method" do
|
14
|
+
before :each do
|
15
|
+
output = <<-HERE.gsub(/^[^\S\n]*/, "")
|
16
|
+
./app/views/admin/testimonials/_form.html.erb:17 - replace instance variable with local variable
|
17
|
+
./app/controllers/admin/campaigns_controller.rb:24,45,68,85 - use before_filter for show,edit,update,destroy
|
18
|
+
|
19
|
+
go to http://wiki.github.com/railsbp/rails_best_practices to see how to solve these errors.
|
20
|
+
|
21
|
+
Found 2 errors.
|
22
|
+
HERE
|
23
|
+
MetricFu::Configuration.run {}
|
24
|
+
practices = MetricFu::RailsBestPractices.new
|
25
|
+
practices.instance_variable_set(:@output, output)
|
26
|
+
@results = practices.analyze
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should get the total" do
|
30
|
+
@results[:total].should == ["Found 2 errors."]
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should get the problems" do
|
34
|
+
@results[:problems].size.should == 2
|
35
|
+
@results[:problems].first.should == { :line => "17",
|
36
|
+
:problem => "replace instance variable with local variable",
|
37
|
+
:file => "app/views/admin/testimonials/_form.html.erb" }
|
38
|
+
@results[:problems][1].should == { :line => "24,45,68,85",
|
39
|
+
:problem => "use before_filter for show,edit,update,destroy",
|
40
|
+
:file => "app/controllers/admin/campaigns_controller.rb" }
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe "to_h method" do
|
45
|
+
it "should put things into a hash" do
|
46
|
+
MetricFu::Configuration.run {}
|
47
|
+
practices = MetricFu::RailsBestPractices.new
|
48
|
+
practices.instance_variable_set(:@rails_best_practices_results, "the_practices")
|
49
|
+
practices.to_h[:rails_best_practices].should == "the_practices"
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,180 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
|
2
|
+
|
3
|
+
describe MetricFu::Rcov do
|
4
|
+
|
5
|
+
before :each do
|
6
|
+
MetricFu::Configuration.run {}
|
7
|
+
File.stub!(:directory?).and_return(true)
|
8
|
+
@rcov = MetricFu::Rcov.new('base_dir')
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "emit" do
|
12
|
+
before :each do
|
13
|
+
@rcov.stub!(:puts)
|
14
|
+
MetricFu.rcov[:external] = nil
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should clear out previous output and make output folder" do
|
18
|
+
@rcov.stub!(:`)
|
19
|
+
FileUtils.should_receive(:rm_rf).with(MetricFu::Rcov.metric_directory, :verbose => false)
|
20
|
+
Dir.should_receive(:mkdir).with(MetricFu::Rcov.metric_directory)
|
21
|
+
@rcov.emit
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should set the RAILS_ENV" do
|
25
|
+
FileUtils.stub!(:rm_rf)
|
26
|
+
Dir.stub!(:mkdir)
|
27
|
+
MetricFu.rcov[:environment] = "metrics"
|
28
|
+
@rcov.should_receive(:`).with(/RAILS_ENV=metrics/)
|
29
|
+
@rcov.emit
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe "with RCOV_OUTPUT fed into" do
|
34
|
+
before :each do
|
35
|
+
MetricFu.rcov[:external] = nil
|
36
|
+
File.should_receive(:open).
|
37
|
+
with(MetricFu::Rcov.metric_directory + '/rcov.txt').
|
38
|
+
and_return(mock("io", :read => RCOV_OUTPUT))
|
39
|
+
@files = @rcov.analyze
|
40
|
+
end
|
41
|
+
|
42
|
+
describe "analyze" do
|
43
|
+
it "should compute percent of lines run" do
|
44
|
+
@files["lib/templates/awesome/awesome_template.rb"][:percent_run].should == 13
|
45
|
+
@files["lib/templates/standard/standard_template.rb"][:percent_run].should == 14
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should know which lines were run" do
|
49
|
+
@files["lib/templates/awesome/awesome_template.rb"][:lines].
|
50
|
+
should include({:content=>"require 'fileutils'", :was_run=>true})
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should know which lines NOT were run" do
|
54
|
+
@files["lib/templates/awesome/awesome_template.rb"][:lines].
|
55
|
+
should include({:content=>" if template_exists?(section)", :was_run=>false})
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe "to_h" do
|
60
|
+
it "should calculate total percentage for all files" do
|
61
|
+
@rcov.to_h[:rcov][:global_percent_run].should == 13.7
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
describe "with external configuration option set" do
|
66
|
+
before :each do
|
67
|
+
@rcov.stub!(:puts)
|
68
|
+
MetricFu.rcov[:external] = "coverage/rcov.txt"
|
69
|
+
end
|
70
|
+
|
71
|
+
it "should emit nothing if external configuration option is set" do
|
72
|
+
FileUtils.should_not_receive(:rm_rf)
|
73
|
+
@rcov.emit
|
74
|
+
end
|
75
|
+
|
76
|
+
it "should open the external rcov analysis file" do
|
77
|
+
File.should_receive(:open).
|
78
|
+
with(MetricFu.rcov[:external]).
|
79
|
+
and_return(mock("io", :read => RCOV_OUTPUT))
|
80
|
+
@files = @rcov.analyze
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
84
|
+
|
85
|
+
|
86
|
+
RCOV_OUTPUT = <<-HERE
|
87
|
+
Profiling enabled.
|
88
|
+
.............................................................................................................................................................................................
|
89
|
+
|
90
|
+
|
91
|
+
Top 10 slowest examples:
|
92
|
+
0.2707830 MetricFu::RoodiGrapher responding to #get_metrics should push 13 to roodi_count
|
93
|
+
0.1994550 MetricFu::RcovGrapher responding to #get_metrics should update labels with the date
|
94
|
+
0.1985800 MetricFu::ReekGrapher responding to #get_metrics should set a hash of code smells to reek_count
|
95
|
+
0.1919860 MetricFu::ReekGrapher responding to #get_metrics should update labels with the date
|
96
|
+
0.1907400 MetricFu::RoodiGrapher responding to #get_metrics should update labels with the date
|
97
|
+
0.1883000 MetricFu::FlogGrapher responding to #get_metrics should update labels with the date
|
98
|
+
0.1882650 MetricFu::FlayGrapher responding to #get_metrics should push 476 to flay_score
|
99
|
+
0.1868780 MetricFu::FlogGrapher responding to #get_metrics should push to top_five_percent_average
|
100
|
+
0.1847730 MetricFu::FlogGrapher responding to #get_metrics should push 9.9 to flog_average
|
101
|
+
0.1844090 MetricFu::FlayGrapher responding to #get_metrics should update labels with the date
|
102
|
+
|
103
|
+
Finished in 2.517686 seconds
|
104
|
+
|
105
|
+
189 examples, 0 failures
|
106
|
+
================================================================================
|
107
|
+
lib/templates/awesome/awesome_template.rb
|
108
|
+
================================================================================
|
109
|
+
require 'fileutils'
|
110
|
+
|
111
|
+
class AwesomeTemplate < MetricFu::Template
|
112
|
+
|
113
|
+
def write
|
114
|
+
!! # Getting rid of the crap before and after the project name from integrity
|
115
|
+
!! @name = File.basename(Dir.pwd).gsub(/^\w+-|-\w+$/, "")
|
116
|
+
!!
|
117
|
+
!! # Copy Bluff javascripts to output directory
|
118
|
+
!! Dir[File.join(this_directory, '..', 'javascripts', '*')].each do |f|
|
119
|
+
!! FileUtils.copy(f, File.join(MetricFu.output_directory, File.basename(f)))
|
120
|
+
!! end
|
121
|
+
!!
|
122
|
+
!! report.each_pair do |section, contents|
|
123
|
+
!! if template_exists?(section)
|
124
|
+
!! create_instance_var(section, contents)
|
125
|
+
!! @html = erbify(section)
|
126
|
+
!! html = erbify('layout')
|
127
|
+
!! fn = output_filename(section)
|
128
|
+
!! MetricFu.report.save_output(html, MetricFu.output_directory, fn)
|
129
|
+
!! end
|
130
|
+
!! end
|
131
|
+
!!
|
132
|
+
!! # Instance variables we need should already be created from above
|
133
|
+
!! if template_exists?('index')
|
134
|
+
!! @html = erbify('index')
|
135
|
+
!! html = erbify('layout')
|
136
|
+
!! fn = output_filename('index')
|
137
|
+
!! MetricFu.report.save_output(html, MetricFu.output_directory, fn)
|
138
|
+
!! end
|
139
|
+
!! end
|
140
|
+
|
141
|
+
def this_directory
|
142
|
+
!! File.dirname(__FILE__)
|
143
|
+
!! end
|
144
|
+
!! end
|
145
|
+
|
146
|
+
================================================================================
|
147
|
+
lib/templates/standard/standard_template.rb
|
148
|
+
================================================================================
|
149
|
+
class StandardTemplate < MetricFu::Template
|
150
|
+
|
151
|
+
|
152
|
+
def write
|
153
|
+
!! report.each_pair do |section, contents|
|
154
|
+
!! if template_exists?(section)
|
155
|
+
!! create_instance_var(section, contents)
|
156
|
+
!! html = erbify(section)
|
157
|
+
!! fn = output_filename(section)
|
158
|
+
!! MetricFu.report.save_output(html, MetricFu.output_directory, fn)
|
159
|
+
!! end
|
160
|
+
!! end
|
161
|
+
!!
|
162
|
+
!! # Instance variables we need should already be created from above
|
163
|
+
!! if template_exists?('index')
|
164
|
+
!! html = erbify('index')
|
165
|
+
!! fn = output_filename('index')
|
166
|
+
!! MetricFu.report.save_output(html, MetricFu.output_directory, fn)
|
167
|
+
!! end
|
168
|
+
!! end
|
169
|
+
|
170
|
+
def this_directory
|
171
|
+
!! File.dirname(__FILE__)
|
172
|
+
!! end
|
173
|
+
!! end
|
174
|
+
|
175
|
+
HERE
|
176
|
+
|
177
|
+
end
|
178
|
+
|
179
|
+
|
180
|
+
|
@@ -0,0 +1,134 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
|
2
|
+
|
3
|
+
describe Reek do
|
4
|
+
describe "emit" do
|
5
|
+
it "should include config parameters" do
|
6
|
+
MetricFu::Configuration.run do |config|
|
7
|
+
config.reek = {:config_file_pattern => 'lib/config/*.reek', :dirs_to_reek => []}
|
8
|
+
end
|
9
|
+
reek = MetricFu::Reek.new
|
10
|
+
reek.should_receive(:`).with(/--config lib\/config\/\*\.reek/).and_return("")
|
11
|
+
reek.emit
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "analyze method" do
|
16
|
+
before :each do
|
17
|
+
@lines = <<-HERE
|
18
|
+
"app/controllers/activity_reports_controller.rb" -- 4 warnings:
|
19
|
+
ActivityReportsController#authorize_user calls current_user.primary_site_ids multiple times (Duplication)
|
20
|
+
ActivityReportsController#authorize_user calls params[id] multiple times (Duplication)
|
21
|
+
ActivityReportsController#authorize_user calls params[primary_site_id] multiple times (Duplication)
|
22
|
+
ActivityReportsController#authorize_user has approx 6 statements (Long Method)
|
23
|
+
|
24
|
+
"app/controllers/application.rb" -- 1 warnings:
|
25
|
+
ApplicationController#start_background_task/block/block is nested (Nested Iterators)
|
26
|
+
|
27
|
+
"app/controllers/link_targets_controller.rb" -- 1 warnings:
|
28
|
+
LinkTargetsController#authorize_user calls current_user.role multiple times (Duplication)
|
29
|
+
|
30
|
+
"app/controllers/newline_controller.rb" -- 1 warnings:
|
31
|
+
NewlineController#some_method calls current_user.<< "new line\n" multiple times (Duplication)
|
32
|
+
HERE
|
33
|
+
MetricFu::Configuration.run {}
|
34
|
+
File.stub!(:directory?).and_return(true)
|
35
|
+
reek = MetricFu::Reek.new
|
36
|
+
reek.instance_variable_set(:@output, @lines)
|
37
|
+
@matches = reek.analyze
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should find the code smell's method name" do
|
41
|
+
smell = @matches.first[:code_smells].first
|
42
|
+
smell[:method].should == "ActivityReportsController#authorize_user"
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should find the code smell's type" do
|
46
|
+
smell = @matches[1][:code_smells].first
|
47
|
+
smell[:type].should == "Nested Iterators"
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should find the code smell's message" do
|
51
|
+
smell = @matches[1][:code_smells].first
|
52
|
+
smell[:message].should == "is nested"
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should find the code smell's type" do
|
56
|
+
smell = @matches.first
|
57
|
+
smell[:file_path].should == "app/controllers/activity_reports_controller.rb"
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should NOT insert nil smells into the array when there's a newline in the method call" do
|
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=>"\"",
|
65
|
+
:message=>"multiple times"}]}
|
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
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
71
|
+
|
72
|
+
describe Reek do
|
73
|
+
before :each do
|
74
|
+
MetricFu::Configuration.run {}
|
75
|
+
@reek = MetricFu::Reek.new
|
76
|
+
@lines11 = <<-HERE
|
77
|
+
"app/controllers/activity_reports_controller.rb" -- 4 warnings:
|
78
|
+
ActivityReportsController#authorize_user calls current_user.primary_site_ids multiple times (Duplication)
|
79
|
+
ActivityReportsController#authorize_user calls params[id] multiple times (Duplication)
|
80
|
+
ActivityReportsController#authorize_user calls params[primary_site_id] multiple times (Duplication)
|
81
|
+
ActivityReportsController#authorize_user has approx 6 statements (Long Method)
|
82
|
+
|
83
|
+
"app/controllers/application.rb" -- 1 warnings:
|
84
|
+
ApplicationController#start_background_task/block/block is nested (Nested Iterators)
|
85
|
+
|
86
|
+
"app/controllers/link_targets_controller.rb" -- 1 warnings:
|
87
|
+
LinkTargetsController#authorize_user calls current_user.role multiple times (Duplication)
|
88
|
+
|
89
|
+
"app/controllers/newline_controller.rb" -- 1 warnings:
|
90
|
+
NewlineController#some_method calls current_user.<< "new line\n" multiple times (Duplication)
|
91
|
+
HERE
|
92
|
+
@lines12 = <<-HERE
|
93
|
+
app/controllers/activity_reports_controller.rb -- 4 warnings (+3 masked):
|
94
|
+
ActivityReportsController#authorize_user calls current_user.primary_site_ids multiple times (Duplication)
|
95
|
+
ActivityReportsController#authorize_user calls params[id] multiple times (Duplication)
|
96
|
+
ActivityReportsController#authorize_user calls params[primary_site_id] multiple times (Duplication)
|
97
|
+
ActivityReportsController#authorize_user has approx 6 statements (Long Method)
|
98
|
+
app/controllers/application.rb -- 1 warnings:
|
99
|
+
ApplicationController#start_background_task/block/block is nested (Nested Iterators)
|
100
|
+
app/controllers/link_targets_controller.rb -- 1 warnings (+1 masked):
|
101
|
+
LinkTargetsController#authorize_user calls current_user.role multiple times (Duplication)
|
102
|
+
app/controllers/newline_controller.rb -- 1 warnings:
|
103
|
+
NewlineController#some_method calls current_user.<< "new line\n" multiple times (Duplication)
|
104
|
+
HERE
|
105
|
+
end
|
106
|
+
|
107
|
+
context 'with Reek 1.1 output format' do
|
108
|
+
it 'reports 1.1 style when the output is empty' do
|
109
|
+
@reek.instance_variable_set(:@output, "")
|
110
|
+
@reek.should_not be_reek_12
|
111
|
+
end
|
112
|
+
it 'detects 1.1 format output' do
|
113
|
+
@reek.instance_variable_set(:@output, @lines11)
|
114
|
+
@reek.should_not be_reek_12
|
115
|
+
end
|
116
|
+
|
117
|
+
it 'massages empty output to be unchanged' do
|
118
|
+
@reek.instance_variable_set(:@output, "")
|
119
|
+
@reek.massage_for_reek_12.should be_empty
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
context 'with Reek 1.2 output format' do
|
124
|
+
it 'detects 1.2 format output' do
|
125
|
+
@reek.instance_variable_set(:@output, @lines12)
|
126
|
+
@reek.should be_reek_12
|
127
|
+
end
|
128
|
+
|
129
|
+
it 'correctly massages 1.2 output' do
|
130
|
+
@reek.instance_variable_set(:@output, @lines12)
|
131
|
+
@reek.massage_for_reek_12.should == @lines11
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
|
2
|
+
|
3
|
+
describe Roodi do
|
4
|
+
describe "emit" do
|
5
|
+
it "should add config options when present" do
|
6
|
+
MetricFu::Configuration.run do |config|
|
7
|
+
config.roodi = {:roodi_config => 'lib/config/roodi_config.yml', :dirs_to_roodi => []}
|
8
|
+
end
|
9
|
+
roodi = MetricFu::Roodi.new
|
10
|
+
roodi.should_receive(:`).with(/-config=lib\/config\/roodi_config\.yml/).and_return("")
|
11
|
+
roodi.emit
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should NOT add config options when NOT present" do
|
15
|
+
MetricFu::Configuration.run do |config|
|
16
|
+
config.roodi = {:dirs_to_roodi => []}
|
17
|
+
end
|
18
|
+
roodi = MetricFu::Roodi.new
|
19
|
+
roodi.stub(:`)
|
20
|
+
roodi.should_receive(:`).with(/-config/).never
|
21
|
+
roodi.emit
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
require File.expand_path(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 == 'app/controllers/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 "per_file_info method" do
|
38
|
+
before :all do
|
39
|
+
MetricFu::Configuration.run {}
|
40
|
+
File.stub!(:directory?).and_return(true)
|
41
|
+
@saikuro = MetricFu::Saikuro.new
|
42
|
+
@saikuro.stub!(:metric_directory).and_return(File.join(File.dirname(__FILE__), "..", "resources", "saikuro"))
|
43
|
+
@saikuro.analyze
|
44
|
+
@output = @saikuro.to_h
|
45
|
+
end
|
46
|
+
|
47
|
+
it "doesn't try to get information if the file does not exist" do
|
48
|
+
File.should_receive(:exists?).at_least(:once).and_return(false)
|
49
|
+
@saikuro.per_file_info('ignore_me')
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
describe "format_directories method" do
|
54
|
+
it "should format the directories" do
|
55
|
+
MetricFu::Configuration.run {}
|
56
|
+
File.stub!(:directory?).and_return(true)
|
57
|
+
saikuro = MetricFu::Saikuro.new
|
58
|
+
|
59
|
+
MetricFu.saikuro[:input_directory] = ["app", "lib"]
|
60
|
+
|
61
|
+
saikuro.format_directories.should == "\"app | lib\""
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
describe Saikuro::SFile do
|
66
|
+
describe "getting elements from a Saikuro result file" do
|
67
|
+
it "should parse nested START/END sections" do
|
68
|
+
path = File.join(File.dirname(__FILE__), "..", "resources", "saikuro_sfiles", "thing.rb_cyclo.html")
|
69
|
+
sfile = Saikuro::SFile.new path
|
70
|
+
sfile.elements.map { |e| e.complexity }.sort.should eql(["0","0","2"])
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|