devver-metric_fu 1.3.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (90) hide show
  1. data/HISTORY +182 -0
  2. data/MIT-LICENSE +22 -0
  3. data/Manifest.txt +25 -0
  4. data/README.textile +27 -0
  5. data/Rakefile +15 -0
  6. data/TODO +9 -0
  7. data/lib/base/base_template.rb +145 -0
  8. data/lib/base/configuration.rb +182 -0
  9. data/lib/base/generator.rb +167 -0
  10. data/lib/base/graph.rb +39 -0
  11. data/lib/base/md5_tracker.rb +52 -0
  12. data/lib/base/report.rb +100 -0
  13. data/lib/generators/churn.rb +34 -0
  14. data/lib/generators/flay.rb +35 -0
  15. data/lib/generators/flog.rb +167 -0
  16. data/lib/generators/rails_best_practices.rb +31 -0
  17. data/lib/generators/rcov.rb +82 -0
  18. data/lib/generators/reek.rb +64 -0
  19. data/lib/generators/roodi.rb +33 -0
  20. data/lib/generators/saikuro.rb +221 -0
  21. data/lib/generators/stats.rb +59 -0
  22. data/lib/graphs/engines/bluff.rb +99 -0
  23. data/lib/graphs/engines/gchart.rb +118 -0
  24. data/lib/graphs/flay_grapher.rb +20 -0
  25. data/lib/graphs/flog_grapher.rb +40 -0
  26. data/lib/graphs/grapher.rb +11 -0
  27. data/lib/graphs/rails_best_practices_grapher.rb +20 -0
  28. data/lib/graphs/rcov_grapher.rb +20 -0
  29. data/lib/graphs/reek_grapher.rb +32 -0
  30. data/lib/graphs/roodi_grapher.rb +20 -0
  31. data/lib/metric_fu.rb +31 -0
  32. data/lib/templates/awesome/awesome_template.rb +37 -0
  33. data/lib/templates/awesome/churn.html.erb +58 -0
  34. data/lib/templates/awesome/css/buttons.css +82 -0
  35. data/lib/templates/awesome/css/default.css +91 -0
  36. data/lib/templates/awesome/css/integrity.css +335 -0
  37. data/lib/templates/awesome/css/reset.css +7 -0
  38. data/lib/templates/awesome/flay.html.erb +34 -0
  39. data/lib/templates/awesome/flog.html.erb +53 -0
  40. data/lib/templates/awesome/index.html.erb +31 -0
  41. data/lib/templates/awesome/layout.html.erb +30 -0
  42. data/lib/templates/awesome/rails_best_practices.html.erb +27 -0
  43. data/lib/templates/awesome/rcov.html.erb +42 -0
  44. data/lib/templates/awesome/reek.html.erb +40 -0
  45. data/lib/templates/awesome/roodi.html.erb +27 -0
  46. data/lib/templates/awesome/saikuro.html.erb +71 -0
  47. data/lib/templates/awesome/stats.html.erb +41 -0
  48. data/lib/templates/javascripts/bluff-min.js +1 -0
  49. data/lib/templates/javascripts/excanvas.js +35 -0
  50. data/lib/templates/javascripts/js-class.js +1 -0
  51. data/lib/templates/standard/churn.html.erb +31 -0
  52. data/lib/templates/standard/default.css +64 -0
  53. data/lib/templates/standard/flay.html.erb +34 -0
  54. data/lib/templates/standard/flog.html.erb +53 -0
  55. data/lib/templates/standard/index.html.erb +41 -0
  56. data/lib/templates/standard/rails_best_practices.html.erb +29 -0
  57. data/lib/templates/standard/rcov.html.erb +43 -0
  58. data/lib/templates/standard/reek.html.erb +42 -0
  59. data/lib/templates/standard/roodi.html.erb +29 -0
  60. data/lib/templates/standard/saikuro.html.erb +84 -0
  61. data/lib/templates/standard/standard_template.rb +26 -0
  62. data/lib/templates/standard/stats.html.erb +55 -0
  63. data/spec/base/base_template_spec.rb +161 -0
  64. data/spec/base/configuration_spec.rb +270 -0
  65. data/spec/base/generator_spec.rb +244 -0
  66. data/spec/base/graph_spec.rb +24 -0
  67. data/spec/base/md5_tracker_spec.rb +57 -0
  68. data/spec/base/report_spec.rb +139 -0
  69. data/spec/generators/churn_spec.rb +43 -0
  70. data/spec/generators/flay_spec.rb +110 -0
  71. data/spec/generators/flog_spec.rb +238 -0
  72. data/spec/generators/reek_spec.rb +125 -0
  73. data/spec/generators/saikuro_spec.rb +58 -0
  74. data/spec/generators/stats_spec.rb +74 -0
  75. data/spec/graphs/engines/bluff_spec.rb +18 -0
  76. data/spec/graphs/engines/gchart_spec.rb +108 -0
  77. data/spec/graphs/flay_grapher_spec.rb +37 -0
  78. data/spec/graphs/flog_grapher_spec.rb +45 -0
  79. data/spec/graphs/rcov_grapher_spec.rb +37 -0
  80. data/spec/graphs/reek_grapher_spec.rb +46 -0
  81. data/spec/graphs/roodi_grapher_spec.rb +37 -0
  82. data/spec/resources/saikuro/app/controllers/sessions_controller.rb_cyclo.html +10 -0
  83. data/spec/resources/saikuro/app/controllers/users_controller.rb_cyclo.html +16 -0
  84. data/spec/resources/saikuro/index_cyclo.html +155 -0
  85. data/spec/resources/saikuro_sfiles/thing.rb_cyclo.html +11 -0
  86. data/spec/resources/yml/20090630.yml +7844 -0
  87. data/spec/spec.opts +6 -0
  88. data/spec/spec_helper.rb +7 -0
  89. data/tasks/metric_fu.rake +22 -0
  90. metadata +253 -0
@@ -0,0 +1,43 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
2
+
3
+ describe Churn do
4
+
5
+ describe "analyze method" do
6
+ before :each do
7
+ MetricFu::Configuration.run {}
8
+ File.stub!(:directory?).and_return(true)
9
+ MetricFu::Churn.should_receive(:verify_dependencies!).and_return(true)
10
+ @changes = {"lib/generators/flog.rb"=>2, "lib/metric_fu.rb"=>3}
11
+ end
12
+
13
+ it "should be empty on error" do
14
+ churn = MetricFu::Churn.new
15
+ churn.instance_variable_set(:@output, "fatal: Not a git repository")
16
+ result = churn.analyze
17
+ result.should == [:churn => {}]
18
+ end
19
+
20
+ it "should return yaml results" do
21
+ churn = MetricFu::Churn.new
22
+ churn.instance_variable_set(:@output, "--- \n:churn: \n :changed_files: \n - spec/graphs/flog_grapher_spec.rb\n - spec/base/graph_spec.rb\n - lib/templates/awesome/layout.html.erb\n - lib/graphs/rcov_grapher.rb\n - lib/base/base_template.rb\n - spec/graphs/grapher_spec.rb\n - lib/templates/awesome/flog.html.erb\n - lib/templates/awesome/flay.html.erb\n - lib/graphs/roodi_grapher.rb\n - lib/graphs/reek_grapher.rb\n - HISTORY\n - spec/graphs/roodi_grapher_spec.rb\n - lib/generators/rcov.rb\n - spec/graphs/engines/gchart_spec.rb\n - spec/graphs/rcov_grapher_spec.rb\n - lib/templates/javascripts/excanvas.js\n - lib/templates/javascripts/bluff-min.js\n - spec/graphs/reek_grapher_spec.rb\n")
23
+ result = churn.analyze
24
+ result.should == {:churn=>{:changed_files=>["spec/graphs/flog_grapher_spec.rb", "spec/base/graph_spec.rb", "lib/templates/awesome/layout.html.erb", "lib/graphs/rcov_grapher.rb", "lib/base/base_template.rb", "spec/graphs/grapher_spec.rb", "lib/templates/awesome/flog.html.erb", "lib/templates/awesome/flay.html.erb", "lib/graphs/roodi_grapher.rb", "lib/graphs/reek_grapher.rb", "HISTORY", "spec/graphs/roodi_grapher_spec.rb", "lib/generators/rcov.rb", "spec/graphs/engines/gchart_spec.rb", "spec/graphs/rcov_grapher_spec.rb", "lib/templates/javascripts/excanvas.js", "lib/templates/javascripts/bluff-min.js", "spec/graphs/reek_grapher_spec.rb"]}}
25
+ end
26
+
27
+ end
28
+
29
+ describe "to_h method" do
30
+ before :each do
31
+ MetricFu::Configuration.run {}
32
+ File.stub!(:directory?).and_return(true)
33
+ MetricFu::Churn.should_receive(:verify_dependencies!).and_return(true)
34
+ end
35
+
36
+ it "should put the changes into a hash" do
37
+ churn = MetricFu::Churn.new
38
+ churn.instance_variable_set(:@churn, {:churn => 'results'})
39
+ churn.to_h[:churn].should == "results"
40
+ end
41
+ end
42
+ end
43
+
@@ -0,0 +1,110 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
2
+
3
+ describe Flay do
4
+ before :each do
5
+ MetricFu::Flay.stub!(:verify_dependencies!).and_return(true)
6
+ end
7
+ describe "emit method" do
8
+ it "should look at the dirs" do
9
+ MetricFu::Configuration.run {|config| config.flay = { :dirs_to_flay => ['app', 'lib'] } }
10
+ File.stub!(:directory?).and_return(true)
11
+ @flay = MetricFu::Flay.new('base_dir')
12
+
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
+
19
+ it "should limit flay scores by the minimum_score" do
20
+ MetricFu::Configuration.run {|config| config.flay = { :dirs_to_flay => [], :minimum_score => 99 } }
21
+ File.stub!(:directory?).and_return(true)
22
+ @flay = MetricFu::Flay.new('base_dir')
23
+
24
+ @flay.should_receive(:`).with("flay --mass 99 ")
25
+ output = @flay.emit
26
+ end
27
+ end
28
+
29
+ describe "analyze method" do
30
+ before :each do
31
+ lines = <<-HERE
32
+ Total score (lower is better) = 246
33
+
34
+
35
+ 1) IDENTICAL code found in :or (mass*2 = 68)
36
+ app/controllers/link_targets_controller.rb:57
37
+ app/controllers/primary_sites_controller.rb:138
38
+
39
+ 2) Similar code found in :if (mass = 64)
40
+ app/controllers/primary_sites_controller.rb:75
41
+ app/controllers/primary_sites_controller.rb:76
42
+ app/controllers/primary_sites_controller.rb:88
43
+ app/controllers/primary_sites_controller.rb:89
44
+ HERE
45
+ MetricFu::Configuration.run {}
46
+ File.stub!(:directory?).and_return(true)
47
+ @flay = MetricFu::Flay.new('base_dir')
48
+ @flay.instance_variable_set(:@output, lines)
49
+ end
50
+
51
+ it "should analyze and return matches" do
52
+ @flay.analyze.should == [ ["Total score (lower is better) = 246"],
53
+ ["\n1) IDENTICAL code found in :or (mass*2 = 68)",
54
+ "app/controllers/link_targets_controller.rb:57",
55
+ "app/controllers/primary_sites_controller.rb:138"],
56
+ ["2) Similar code found in :if (mass = 64)",
57
+ "app/controllers/primary_sites_controller.rb:75",
58
+ "app/controllers/primary_sites_controller.rb:76",
59
+ "app/controllers/primary_sites_controller.rb:88",
60
+ "app/controllers/primary_sites_controller.rb:89"] ]
61
+ end
62
+ end
63
+
64
+ describe "to_h method" do
65
+
66
+ before :each do
67
+ lines = [ ["Total score (lower is better) = 284"],
68
+ ["\n1) IDENTICAL code found in :or (mass*2 = 68)",
69
+ "app/controllers/link_targets_controller.rb:57",
70
+ "app/controllers/primary_sites_controller.rb:138"],
71
+ ["2) Similar code found in :if (mass = 64)",
72
+ "app/controllers/primary_sites_controller.rb:75",
73
+ "app/controllers/primary_sites_controller.rb:76",
74
+ "app/controllers/primary_sites_controller.rb:88",
75
+ "app/controllers/primary_sites_controller.rb:89"],
76
+ ["3) Similar code found in :defn (mass = 40)",
77
+ "app/controllers/link_targets_controller.rb:40",
78
+ "app/controllers/primary_sites_controller.rb:98"],
79
+ ["4) Similar code found in :defn (mass = 38)",
80
+ "app/controllers/link_targets_controller.rb:13",
81
+ "app/controllers/primary_sites_controller.rb:50"],
82
+ ["5) Similar code found in :defn (mass = 38)",
83
+ "app/models/primary_site.rb:104",
84
+ "app/models/primary_site.rb:109"],
85
+ ["6) Similar code found in :call (mass = 36)",
86
+ "app/controllers/bookmarklet_integration_controller.rb:6",
87
+ "app/controllers/bookmarklet_integration_controller.rb:17"]]
88
+
89
+ MetricFu::Configuration.run {}
90
+ File.stub!(:directory?).and_return(true)
91
+ flay = MetricFu::Flay.new('base_dir')
92
+ flay.instance_variable_set(:@matches, lines)
93
+ @results = flay.to_h
94
+ end
95
+
96
+ it "should find the total_score" do
97
+ @results[:flay][:total_score].should == '284'
98
+ end
99
+
100
+ it "should have 6 matches" do
101
+ @results[:flay][:matches].size.should == 6
102
+ end
103
+
104
+ it "should capture info for match" do
105
+ @results[:flay][:matches].first[:reason].should =~ /IDENTICAL/
106
+ @results[:flay][:matches].first[:matches].first[:name].should =~ /link_targets_controller/
107
+ @results[:flay][:matches].first[:matches].first[:line].should == "57"
108
+ end
109
+ end
110
+ end
@@ -0,0 +1,238 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
2
+ describe Flog do
3
+ before :each do
4
+ @text = <<-HERE
5
+ 157.9: flog total
6
+ 11.3: flog/method average
7
+
8
+ 34.8: UsersController#create
9
+ 9.2: branch
10
+ 6.8: current_user
11
+ 5.2: assignment
12
+ 3.4: role
13
+ 3.0: render
14
+ 3.0: ==
15
+ 2.8: flash
16
+ 1.6: after_create_page
17
+ 1.6: params
18
+ 1.5: activate!
19
+ 1.5: errors
20
+ 1.4: login
21
+ 1.4: redirect_to
22
+ 1.4: []
23
+ 1.3: empty?
24
+ 1.3: save
25
+ 1.2: new
26
+ 24.2: UsersController#authorize_user
27
+ 4.8: branch
28
+ 4.7: current_user
29
+ 3.6: params
30
+ 3.2: []
31
+ 2.6: ==
32
+ 1.5: role
33
+ 1.5: to_i
34
+ 1.5: id
35
+ 1.4: new_session_path
36
+ 1.3: include?
37
+ 1.2: assignment
38
+ 1.2: flash
39
+ 1.2: redirect_to
40
+ 16.4: UsersController#thank_you
41
+ 4.0: assignment
42
+ 3.3: params
43
+ 2.9: []
44
+ 2.7: redirect_to
45
+ 2.4: branch
46
+ 1.5: new_session_path
47
+ 1.4: flash
48
+ 1.4: activate!
49
+ 1.3: can_activate?
50
+ 1.2: find_by_id
51
+ 14.2: UsersController#update
52
+ 3.2: params
53
+ 2.8: []
54
+ 2.6: assignment
55
+ 1.4: login
56
+ 1.4: flash
57
+ 1.4: redirect_to
58
+ 1.3: render
59
+ 1.2: branch
60
+ 1.2: update_attributes
61
+ 1.2: find_by_id
62
+ 12.5: UsersController#sanitize_params
63
+ 3.9: assignment
64
+ 3.6: branch
65
+ 3.0: current_user
66
+ 1.6: params
67
+ 1.5: role
68
+ 1.4: []
69
+ 1.3: include?
70
+ 1.3: ==
71
+ 1.2: reject!
72
+ 10.6: UsersController#users_have_changed
73
+ 3.9: assignment
74
+ 2.6: branch
75
+ 1.6: params
76
+ 1.5: refresh_from_external
77
+ 1.4: find_by_id
78
+ 1.4: []
79
+ 1.2: split
80
+ 1.2: each
81
+ 1.2: head
82
+ 10.0: UsersController#after_create_page
83
+ 3.0: current_user
84
+ 2.6: id
85
+ 2.4: branch
86
+ 1.5: role
87
+ 1.3: login
88
+ 1.3: ==
89
+ 8.4: UsersController#add_primary_site
90
+ 2.4: assignment
91
+ 1.6: params
92
+ 1.4: []
93
+ 1.4: new
94
+ 1.2: find_by_id
95
+ 1.2: all
96
+ 1.2: render
97
+ 7.7: UsersController#none
98
+ 3.3: before_filter
99
+ 1.1: private
100
+ 1.1: caches_page
101
+ 1.1: after_filter
102
+ 1.1: skip_before_filter
103
+ 7.2: UsersController#destroy
104
+ 1.8: params
105
+ 1.6: []
106
+ 1.4: find_by_id
107
+ 1.2: destroy
108
+ 1.2: redirect_to
109
+ 5.9: UsersController#edit
110
+ 2.4: assignment
111
+ 1.6: params
112
+ 1.4: []
113
+ 1.2: all
114
+ 1.2: find_by_id
115
+ 2.7: UsersController#signup
116
+ 1.2: render
117
+ 1.2: assignment
118
+ 1.2: new
119
+ 1.7: UsersController#new
120
+ 1.2: assignment
121
+ 1.2: new
122
+ 1.7: UsersController#index
123
+ 1.2: assignment
124
+ 1.2: all
125
+ HERE
126
+ MetricFu::Flog.stub!(:verify_dependencies!).and_return(true)
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
+
161
+ it "should find the name of the method even if namespaced" do
162
+ text = <<-HERE
163
+ 157.9: flog total
164
+ 11.3: flog/method average
165
+
166
+ 34.8: SomeNamespace::UsersController#create
167
+ HERE
168
+ flog = MetricFu::Flog.new('base_dir')
169
+ flog_page = flog.parse(text)
170
+ flog_page.scanned_methods.first.name.should == "SomeNamespace::UsersController#create"
171
+ end
172
+
173
+ it "should parse empty flog files" do
174
+ text = ""
175
+ flog = MetricFu::Flog.new('base_dir')
176
+ flog_page = flog.parse(text)
177
+ flog_page.should be_nil
178
+ end
179
+ end
180
+
181
+ describe "to_h function with results" do
182
+ before :each do
183
+ MetricFu::Configuration.run {}
184
+ File.stub!(:directory?).and_return(true)
185
+ flog = MetricFu::Flog.new('base_dir')
186
+ flog.should_receive(:open).and_return(@text)
187
+ flog.stub!(:is_file_current?).and_return(true)
188
+ Dir.should_receive(:glob).and_return(["tmp/metric_fu/scratch/flog/app/controllers/user_controller.txt"])
189
+ flog.analyze
190
+ @flog_hash = flog.to_h
191
+ end
192
+
193
+ it "should put the total in the hash" do
194
+ @flog_hash[:flog][:total].should == 157.9
195
+ end
196
+
197
+ it "should put the average in the hash" do
198
+ @flog_hash[:flog][:average].should == 11.3
199
+ end
200
+
201
+ it "should put pages into the hash" do
202
+ @flog_hash[:flog][:pages].first[:scanned_methods].first[:score].should == 34.8
203
+ end
204
+
205
+ it "should put the filename into the hash" do
206
+ @flog_hash[:flog][:pages].first[:path].should == "/app/controllers/user_controller.rb"
207
+ end
208
+ end
209
+
210
+ describe "to_h function ignore files not current" do
211
+ before :each do
212
+ MetricFu::Configuration.run {}
213
+ File.stub!(:directory?).and_return(true)
214
+ flog = MetricFu::Flog.new('base_dir')
215
+ flog.should_receive(:open).and_return(@text)
216
+ flog.stub!(:is_file_current?).and_return(false)
217
+ Dir.should_receive(:glob).and_return(["tmp/metric_fu/scratch/flog/app/controllers/user_controller.txt"])
218
+ flog.analyze
219
+ @flog_hash = flog.to_h
220
+ end
221
+
222
+ it "should put the total in the hash" do
223
+ @flog_hash.should == {:flog=>{:total=>0, :pages=>[], :average=>0}}
224
+ end
225
+
226
+ end
227
+
228
+ describe "to_h function with zero total" do
229
+ it "should not blow up" do
230
+ MetricFu::Configuration.run {}
231
+ File.stub!(:directory?).and_return(true)
232
+ flog = MetricFu::Flog.new('base_dir')
233
+ flog.should_receive(:open).and_return("") # some sort of empty or unparsable file
234
+ Dir.should_receive(:glob).and_return(["empty_file.txt"])
235
+ flog.analyze
236
+ end
237
+ end
238
+ end
@@ -0,0 +1,125 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
2
+
3
+ describe Reek do
4
+ describe "analyze method" do
5
+ before :each do
6
+ MetricFu::Reek.stub!(:verify_dependencies!).and_return(true)
7
+ @lines = <<-HERE
8
+ "app/controllers/activity_reports_controller.rb" -- 4 warnings:
9
+ ActivityReportsController#authorize_user calls current_user.primary_site_ids multiple times (Duplication)
10
+ ActivityReportsController#authorize_user calls params[id] multiple times (Duplication)
11
+ ActivityReportsController#authorize_user calls params[primary_site_id] multiple times (Duplication)
12
+ ActivityReportsController#authorize_user has approx 6 statements (Long Method)
13
+
14
+ "app/controllers/application.rb" -- 1 warnings:
15
+ ApplicationController#start_background_task/block/block is nested (Nested Iterators)
16
+
17
+ "app/controllers/link_targets_controller.rb" -- 1 warnings:
18
+ LinkTargetsController#authorize_user calls current_user.role multiple times (Duplication)
19
+
20
+ "app/controllers/newline_controller.rb" -- 1 warnings:
21
+ NewlineController#some_method calls current_user.<< "new line\n" multiple times (Duplication)
22
+ HERE
23
+ MetricFu::Configuration.run {}
24
+ File.stub!(:directory?).and_return(true)
25
+ reek = MetricFu::Reek.new
26
+ reek.instance_variable_set(:@output, @lines)
27
+ @matches = reek.analyze
28
+ end
29
+
30
+ it "should find the code smell's method name" do
31
+ smell = @matches.first[:code_smells].first
32
+ smell[:method].should == "ActivityReportsController#authorize_user"
33
+ end
34
+
35
+ it "should find the code smell's type" do
36
+ smell = @matches[1][:code_smells].first
37
+ smell[:type].should == "Nested Iterators"
38
+ end
39
+
40
+ it "should find the code smell's message" do
41
+ smell = @matches[1][:code_smells].first
42
+ smell[:message].should == "is nested"
43
+ end
44
+
45
+ it "should find the code smell's type" do
46
+ smell = @matches.first
47
+ smell[:file_path].should == "app/controllers/activity_reports_controller.rb"
48
+ end
49
+
50
+ it "should NOT insert nil smells into the array when there's a newline in the method call" do
51
+ @matches.last[:code_smells].should == @matches.last[:code_smells].compact
52
+ @matches.last.should == {:file_path=>"app/controllers/newline_controller.rb",
53
+ :code_smells=>[{:type=>"Duplication",
54
+ :method=>"\"",
55
+ :message=>"multiple times"}]}
56
+ # Note: hopefully a temporary solution until I figure out how to deal with newlines in the method call more effectively -Jake 5/11/2009
57
+ end
58
+ end
59
+
60
+ end
61
+
62
+ describe Reek do
63
+ before :each do
64
+ MetricFu::Reek.stub!(:verify_dependencies!).and_return(true)
65
+ MetricFu::Configuration.run {}
66
+ @reek = MetricFu::Reek.new
67
+ @lines11 = <<-HERE
68
+ "app/controllers/activity_reports_controller.rb" -- 4 warnings:
69
+ ActivityReportsController#authorize_user calls current_user.primary_site_ids multiple times (Duplication)
70
+ ActivityReportsController#authorize_user calls params[id] multiple times (Duplication)
71
+ ActivityReportsController#authorize_user calls params[primary_site_id] multiple times (Duplication)
72
+ ActivityReportsController#authorize_user has approx 6 statements (Long Method)
73
+
74
+ "app/controllers/application.rb" -- 1 warnings:
75
+ ApplicationController#start_background_task/block/block is nested (Nested Iterators)
76
+
77
+ "app/controllers/link_targets_controller.rb" -- 1 warnings:
78
+ LinkTargetsController#authorize_user calls current_user.role multiple times (Duplication)
79
+
80
+ "app/controllers/newline_controller.rb" -- 1 warnings:
81
+ NewlineController#some_method calls current_user.<< "new line\n" multiple times (Duplication)
82
+ HERE
83
+ @lines12 = <<-HERE
84
+ app/controllers/activity_reports_controller.rb -- 4 warnings (+3 masked):
85
+ ActivityReportsController#authorize_user calls current_user.primary_site_ids multiple times (Duplication)
86
+ ActivityReportsController#authorize_user calls params[id] multiple times (Duplication)
87
+ ActivityReportsController#authorize_user calls params[primary_site_id] multiple times (Duplication)
88
+ ActivityReportsController#authorize_user has approx 6 statements (Long Method)
89
+ app/controllers/application.rb -- 1 warnings:
90
+ ApplicationController#start_background_task/block/block is nested (Nested Iterators)
91
+ app/controllers/link_targets_controller.rb -- 1 warnings (+1 masked):
92
+ LinkTargetsController#authorize_user calls current_user.role multiple times (Duplication)
93
+ app/controllers/newline_controller.rb -- 1 warnings:
94
+ NewlineController#some_method calls current_user.<< "new line\n" multiple times (Duplication)
95
+ HERE
96
+ end
97
+
98
+ context 'with Reek 1.1 output format' do
99
+ it 'reports 1.1 style when the output is empty' do
100
+ @reek.instance_variable_set(:@output, "")
101
+ @reek.should_not be_reek_12
102
+ end
103
+ it 'detects 1.1 format output' do
104
+ @reek.instance_variable_set(:@output, @lines11)
105
+ @reek.should_not be_reek_12
106
+ end
107
+
108
+ it 'massages empty output to be unchanged' do
109
+ @reek.instance_variable_set(:@output, "")
110
+ @reek.massage_for_reek_12.should be_empty
111
+ end
112
+ end
113
+
114
+ context 'with Reek 1.2 output format' do
115
+ it 'detects 1.2 format output' do
116
+ @reek.instance_variable_set(:@output, @lines12)
117
+ @reek.should be_reek_12
118
+ end
119
+
120
+ it 'correctly massages 1.2 output' do
121
+ @reek.instance_variable_set(:@output, @lines12)
122
+ @reek.massage_for_reek_12.should == @lines11
123
+ end
124
+ end
125
+ end