metric_fu 4.11.1 → 4.13.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (206) hide show
  1. checksums.yaml +5 -13
  2. data/.gitignore +6 -0
  3. data/.rubocop.yml +15 -0
  4. data/.rubocop_todo.yml +69 -0
  5. data/.simplecov +35 -3
  6. data/.travis.yml +6 -10
  7. data/CONTRIBUTORS +12 -11
  8. data/Gemfile +48 -29
  9. data/Guardfile +9 -9
  10. data/HISTORY.md +47 -1
  11. data/README.md +70 -57
  12. data/Rakefile +1 -15
  13. data/appveyor.yml +34 -0
  14. data/certs/bf4.pem +20 -20
  15. data/checksum/metric_fu-4.11.1.gem.sha512 +1 -0
  16. data/checksum/metric_fu-4.11.2.gem.sha512 +1 -0
  17. data/checksum/metric_fu-4.11.3.gem.sha512 +1 -0
  18. data/checksum/metric_fu-4.11.4.gem.sha512 +1 -0
  19. data/checksum/metric_fu-4.12.0.gem.sha512 +1 -0
  20. data/checksum/metric_fu-4.13.0.gem.sha512 +1 -0
  21. data/config/rubocop.yml +269 -0
  22. data/gem_tasks/build.rake +1 -0
  23. data/gem_tasks/rubocop.rake +10 -0
  24. data/gem_tasks/yard.rake +24 -0
  25. data/lib/metric_fu.rb +20 -9
  26. data/lib/metric_fu/calculate.rb +0 -1
  27. data/lib/metric_fu/cli/client.rb +6 -6
  28. data/lib/metric_fu/cli/helper.rb +22 -13
  29. data/lib/metric_fu/cli/parser.rb +14 -18
  30. data/lib/metric_fu/configuration.rb +7 -11
  31. data/lib/metric_fu/constantize.rb +4 -4
  32. data/lib/metric_fu/data_structures/line_numbers.rb +10 -11
  33. data/lib/metric_fu/data_structures/location.rb +12 -14
  34. data/lib/metric_fu/data_structures/sexp_node.rb +31 -13
  35. data/lib/metric_fu/environment.rb +29 -31
  36. data/lib/metric_fu/formatter.rb +4 -6
  37. data/lib/metric_fu/formatter/html.rb +13 -13
  38. data/lib/metric_fu/formatter/syntax.rb +5 -7
  39. data/lib/metric_fu/formatter/yaml.rb +1 -1
  40. data/lib/metric_fu/gem_run.rb +13 -15
  41. data/lib/metric_fu/gem_version.rb +10 -12
  42. data/lib/metric_fu/generator.rb +6 -9
  43. data/lib/metric_fu/io.rb +13 -15
  44. data/lib/metric_fu/loader.rb +17 -18
  45. data/lib/metric_fu/logger.rb +15 -18
  46. data/lib/metric_fu/logging/mf_debugger.rb +4 -4
  47. data/lib/metric_fu/metric.rb +11 -12
  48. data/lib/metric_fu/metrics/cane/generator.rb +10 -9
  49. data/lib/metric_fu/metrics/cane/grapher.rb +5 -7
  50. data/lib/metric_fu/metrics/cane/metric.rb +6 -8
  51. data/lib/metric_fu/metrics/cane/report.html.erb +3 -3
  52. data/lib/metric_fu/metrics/cane/violations.rb +6 -6
  53. data/lib/metric_fu/metrics/churn/generator.rb +2 -6
  54. data/lib/metric_fu/metrics/churn/hotspot.rb +1 -3
  55. data/lib/metric_fu/metrics/churn/metric.rb +5 -7
  56. data/lib/metric_fu/metrics/flay/generator.rb +7 -11
  57. data/lib/metric_fu/metrics/flay/grapher.rb +5 -6
  58. data/lib/metric_fu/metrics/flay/hotspot.rb +5 -7
  59. data/lib/metric_fu/metrics/flay/metric.rb +5 -7
  60. data/lib/metric_fu/metrics/flog/generator.rb +35 -24
  61. data/lib/metric_fu/metrics/flog/grapher.rb +11 -11
  62. data/lib/metric_fu/metrics/flog/hotspot.rb +3 -5
  63. data/lib/metric_fu/metrics/flog/metric.rb +3 -5
  64. data/lib/metric_fu/metrics/hotspots/analysis/analyzed_problems.rb +0 -1
  65. data/lib/metric_fu/metrics/hotspots/analysis/analyzer_tables.rb +19 -18
  66. data/lib/metric_fu/metrics/hotspots/analysis/grouping.rb +0 -2
  67. data/lib/metric_fu/metrics/hotspots/analysis/groupings.rb +1 -3
  68. data/lib/metric_fu/metrics/hotspots/analysis/problems.rb +4 -6
  69. data/lib/metric_fu/metrics/hotspots/analysis/ranked_problem_location.rb +14 -17
  70. data/lib/metric_fu/metrics/hotspots/analysis/ranking.rb +4 -5
  71. data/lib/metric_fu/metrics/hotspots/analysis/rankings.rb +1 -3
  72. data/lib/metric_fu/metrics/hotspots/analysis/record.rb +3 -5
  73. data/lib/metric_fu/metrics/hotspots/analysis/scoring_strategies.rb +0 -2
  74. data/lib/metric_fu/metrics/hotspots/analysis/table.rb +3 -4
  75. data/lib/metric_fu/metrics/hotspots/generator.rb +3 -6
  76. data/lib/metric_fu/metrics/hotspots/hotspot.rb +13 -13
  77. data/lib/metric_fu/metrics/hotspots/hotspot_analyzer.rb +5 -8
  78. data/lib/metric_fu/metrics/hotspots/metric.rb +1 -3
  79. data/lib/metric_fu/metrics/hotspots/report.html.erb +1 -1
  80. data/lib/metric_fu/metrics/rails_best_practices/generator.rb +14 -12
  81. data/lib/metric_fu/metrics/rails_best_practices/grapher.rb +5 -6
  82. data/lib/metric_fu/metrics/rails_best_practices/metric.rb +5 -4
  83. data/lib/metric_fu/metrics/rcov/external_client.rb +1 -3
  84. data/lib/metric_fu/metrics/rcov/generator.rb +13 -15
  85. data/lib/metric_fu/metrics/rcov/grapher.rb +6 -7
  86. data/lib/metric_fu/metrics/rcov/hotspot.rb +5 -7
  87. data/lib/metric_fu/metrics/rcov/metric.rb +5 -7
  88. data/lib/metric_fu/metrics/rcov/rcov_format_coverage.rb +16 -55
  89. data/lib/metric_fu/metrics/rcov/rcov_line.rb +48 -0
  90. data/lib/metric_fu/metrics/rcov/report.html.erb +2 -2
  91. data/lib/metric_fu/metrics/rcov/simplecov_formatter.rb +10 -11
  92. data/lib/metric_fu/metrics/reek/generator.rb +36 -82
  93. data/lib/metric_fu/metrics/reek/grapher.rb +5 -6
  94. data/lib/metric_fu/metrics/reek/hotspot.rb +5 -7
  95. data/lib/metric_fu/metrics/reek/metric.rb +2 -4
  96. data/lib/metric_fu/metrics/roodi/generator.rb +9 -10
  97. data/lib/metric_fu/metrics/roodi/grapher.rb +5 -6
  98. data/lib/metric_fu/metrics/roodi/hotspot.rb +1 -3
  99. data/lib/metric_fu/metrics/roodi/metric.rb +2 -4
  100. data/lib/metric_fu/metrics/saikuro/generator.rb +23 -27
  101. data/lib/metric_fu/metrics/saikuro/hotspot.rb +1 -3
  102. data/lib/metric_fu/metrics/saikuro/metric.rb +7 -8
  103. data/lib/metric_fu/metrics/saikuro/parsing_element.rb +6 -8
  104. data/lib/metric_fu/metrics/saikuro/report.html.erb +1 -1
  105. data/lib/metric_fu/metrics/saikuro/scratch_file.rb +24 -29
  106. data/lib/metric_fu/metrics/stats/generator.rb +9 -12
  107. data/lib/metric_fu/metrics/stats/grapher.rb +8 -9
  108. data/lib/metric_fu/metrics/stats/hotspot.rb +1 -3
  109. data/lib/metric_fu/metrics/stats/metric.rb +3 -5
  110. data/lib/metric_fu/reporter.rb +1 -1
  111. data/lib/metric_fu/reporting/graphs/graph.rb +8 -12
  112. data/lib/metric_fu/reporting/graphs/grapher.rb +7 -9
  113. data/lib/metric_fu/reporting/result.rb +0 -3
  114. data/lib/metric_fu/run.rb +12 -3
  115. data/lib/metric_fu/tasks/metric_fu.rake +8 -8
  116. data/lib/metric_fu/templates/configuration.rb +2 -5
  117. data/lib/metric_fu/templates/metrics_template.rb +45 -32
  118. data/lib/metric_fu/templates/report.rb +5 -8
  119. data/lib/metric_fu/templates/template.rb +20 -24
  120. data/lib/metric_fu/utility.rb +15 -8
  121. data/lib/metric_fu/version.rb +7 -1
  122. data/metric_fu.gemspec +29 -32
  123. data/spec/capture_warnings.rb +29 -22
  124. data/spec/cli/helper_spec.rb +9 -16
  125. data/spec/dummy/lib/bad_encoding.rb +1 -1
  126. data/spec/fixtures/coverage-153.rb +2 -2
  127. data/spec/fixtures/coverage.rb +2 -2
  128. data/spec/metric_fu/calculate_spec.rb +3 -3
  129. data/spec/metric_fu/configuration_spec.rb +71 -83
  130. data/spec/metric_fu/data_structures/line_numbers_spec.rb +3 -5
  131. data/spec/metric_fu/data_structures/location_spec.rb +13 -31
  132. data/spec/metric_fu/formatter/configuration_spec.rb +18 -20
  133. data/spec/metric_fu/formatter/html_spec.rb +21 -28
  134. data/spec/metric_fu/formatter/yaml_spec.rb +9 -17
  135. data/spec/metric_fu/formatter_spec.rb +16 -16
  136. data/spec/metric_fu/gem_version_spec.rb +4 -6
  137. data/spec/metric_fu/generator_spec.rb +33 -43
  138. data/spec/metric_fu/loader_spec.rb +5 -4
  139. data/spec/metric_fu/metric_spec.rb +21 -25
  140. data/spec/metric_fu/metrics/cane/configuration_spec.rb +14 -14
  141. data/spec/metric_fu/metrics/cane/generator_spec.rb +26 -29
  142. data/spec/metric_fu/metrics/churn/configuration_spec.rb +7 -9
  143. data/spec/metric_fu/metrics/churn/generator_spec.rb +6 -11
  144. data/spec/metric_fu/metrics/flay/configuration_spec.rb +7 -9
  145. data/spec/metric_fu/metrics/flay/generator_spec.rb +36 -37
  146. data/spec/metric_fu/metrics/flay/grapher_spec.rb +2 -2
  147. data/spec/metric_fu/metrics/flog/configuration_spec.rb +12 -14
  148. data/spec/metric_fu/metrics/flog/generator_spec.rb +31 -32
  149. data/spec/metric_fu/metrics/flog/grapher_spec.rb +8 -10
  150. data/spec/metric_fu/metrics/hotspots/analysis/analyzed_problems_spec.rb +18 -24
  151. data/spec/metric_fu/metrics/hotspots/analysis/analyzer_tables_spec.rb +12 -17
  152. data/spec/metric_fu/metrics/hotspots/analysis/ranking_spec.rb +2 -6
  153. data/spec/metric_fu/metrics/hotspots/analysis/rankings_spec.rb +5 -14
  154. data/spec/metric_fu/metrics/hotspots/analysis/table_spec.rb +1 -3
  155. data/spec/metric_fu/metrics/hotspots/generator_spec.rb +6 -8
  156. data/spec/metric_fu/metrics/hotspots/hotspot_analyzer_spec.rb +1 -3
  157. data/spec/metric_fu/metrics/hotspots/hotspot_spec.rb +4 -5
  158. data/spec/metric_fu/metrics/rails_best_practices/configuration_spec.rb +25 -17
  159. data/spec/metric_fu/metrics/rails_best_practices/generator_spec.rb +2 -3
  160. data/spec/metric_fu/metrics/rails_best_practices/grapher_spec.rb +3 -3
  161. data/spec/metric_fu/metrics/rcov/configuration_spec.rb +21 -23
  162. data/spec/metric_fu/metrics/rcov/generator_spec.rb +6 -10
  163. data/spec/metric_fu/metrics/rcov/grapher_spec.rb +2 -2
  164. data/spec/metric_fu/metrics/rcov/hotspot_spec.rb +8 -8
  165. data/spec/metric_fu/metrics/rcov/rcov_line_spec.rb +89 -0
  166. data/spec/metric_fu/metrics/rcov/simplecov_formatter_spec.rb +31 -33
  167. data/spec/metric_fu/metrics/reek/configuration_spec.rb +7 -7
  168. data/spec/metric_fu/metrics/reek/generator_spec.rb +131 -111
  169. data/spec/metric_fu/metrics/reek/grapher_spec.rb +4 -4
  170. data/spec/metric_fu/metrics/roodi/configuration_spec.rb +8 -10
  171. data/spec/metric_fu/metrics/roodi/generator_spec.rb +3 -3
  172. data/spec/metric_fu/metrics/roodi/grapher_spec.rb +2 -2
  173. data/spec/metric_fu/metrics/saikuro/configuration_spec.rb +22 -23
  174. data/spec/metric_fu/metrics/saikuro/generator_spec.rb +7 -7
  175. data/spec/metric_fu/metrics/stats/generator_spec.rb +10 -10
  176. data/spec/metric_fu/metrics/stats/grapher_spec.rb +2 -2
  177. data/spec/metric_fu/reporter_spec.rb +8 -9
  178. data/spec/metric_fu/reporting/graphs/graph_spec.rb +1 -4
  179. data/spec/metric_fu/reporting/graphs/grapher_spec.rb +5 -5
  180. data/spec/metric_fu/reporting/result_spec.rb +12 -14
  181. data/spec/metric_fu/run_spec.rb +19 -33
  182. data/spec/metric_fu/templates/configuration_spec.rb +34 -40
  183. data/spec/metric_fu/templates/metrics_template_spec.rb +11 -0
  184. data/spec/metric_fu/templates/report_spec.rb +4 -4
  185. data/spec/metric_fu/templates/template_spec.rb +78 -64
  186. data/spec/metric_fu/utility_spec.rb +3 -3
  187. data/spec/metric_fu_spec.rb +23 -6
  188. data/spec/quality_spec.rb +43 -15
  189. data/spec/shared/configured.rb +9 -11
  190. data/spec/shared/test_coverage.rb +5 -9
  191. data/spec/spec_helper.rb +13 -31
  192. data/spec/{dummy → support}/.metrics +0 -0
  193. data/spec/support/deferred_garbaged_collection.rb +1 -2
  194. data/spec/support/matcher_create_file.rb +6 -4
  195. data/spec/support/matcher_create_files.rb +6 -4
  196. data/spec/support/samples/reek/alfa.rb +1 -0
  197. data/spec/support/suite.rb +3 -3
  198. data/spec/support/test_fixtures.rb +5 -7
  199. data/spec/support/timeout.rb +1 -1
  200. data/spec/support/usage_test.rb +24 -25
  201. data/spec/usage_test_spec.rb +30 -32
  202. metadata +104 -103
  203. checksums.yaml.gz.sig +0 -0
  204. data.tar.gz.sig +0 -0
  205. data/gemfiles/Gemfile.travis +0 -10
  206. metadata.gz.sig +0 -0
@@ -1,12 +1,12 @@
1
- require 'spec_helper'
2
- require 'shared/configured'
1
+ require "spec_helper"
2
+ require "shared/configured"
3
3
 
4
- describe MetricFu::Configuration, 'for reek' do
5
- it_behaves_like 'configured' do
6
- it 'should set @reek to {:dirs_to_reek => @code_dirs}' do
7
- load_metric 'reek'
4
+ describe MetricFu::Configuration, "for reek" do
5
+ it_behaves_like "configured" do
6
+ it "should set @reek to {:dirs_to_reek => @code_dirs}" do
7
+ load_metric "reek"
8
8
  expect(MetricFu::Metric.get_metric(:reek).run_options).to eq(
9
- {:config_file_pattern=>nil, :dirs_to_reek => ['lib']}
9
+ config_file_pattern: nil, dirs_to_reek: ["lib"]
10
10
  )
11
11
  end
12
12
  end
@@ -1,74 +1,115 @@
1
1
  require "spec_helper"
2
- MetricFu.metrics_require { 'reek/generator' }
2
+
3
+ MetricFu.metrics_require { "reek/generator" }
3
4
 
4
5
  describe MetricFu::ReekGenerator do
5
6
  describe "emit" do
6
- let(:options) { {:dirs_to_reek => []} }
7
- let(:files_to_analyze) { ['lib/foo.rb','lib/bar.rb'] }
7
+ let(:options) { { dirs_to_reek: [] } }
8
+ let(:files_to_analyze) { ["lib/foo.rb", "lib/bar.rb"] }
8
9
  let(:reek) { MetricFu::ReekGenerator.new(options) }
9
10
 
10
- before :each do
11
+ before(:each) do
11
12
  allow(reek).to receive(:files_to_analyze).and_return(files_to_analyze)
12
13
  end
13
14
 
14
15
  it "includes config file pattern into reek parameters when specified" do
15
- options.merge!({:config_file_pattern => 'lib/config/*.reek' })
16
- expect(reek).to receive(:run!).with(/--config lib\/config\/\*\.reek /).and_return("")
17
- reek.emit
18
- end
16
+ options.merge!(config_file_pattern: "lib/config/*.reek")
19
17
 
20
- it "turns off color output from reek output, for reek 1.3.7 or greater" do
21
- allow(reek).to receive(:reek_version).and_return('1.3.7')
22
- expect(reek).to receive(:run!).with(/(?=--no-color)/).and_return("")
23
- reek.emit
24
- end
18
+ expect(reek).to receive(:run!) do |_files, config_files|
19
+ expect(config_files).to eq(["lib/config/*.reek"])
20
+ end.and_return("")
25
21
 
26
- it "does not set an (invalid) --no-color option for reek < 1.3.7" do
27
- allow(reek).to receive(:reek_version).and_return('1.3.6')
28
- expect(reek).to receive(:run!).with(/(?!--no-color)/).and_return("")
29
22
  reek.emit
30
23
  end
31
24
 
32
- it "disables lines numbers from reek output" do
33
- expect(reek).to receive(:run!).with(/--no-line-numbers /).and_return("")
25
+ it "passes an empty array when no config file pattern is specified" do
26
+ expect(reek).to receive(:run!) do |_files, config_files|
27
+ expect(config_files).to eq([])
28
+ end.and_return("")
29
+
34
30
  reek.emit
35
31
  end
36
32
 
37
33
  it "includes files to analyze into reek parameters" do
38
- expect(reek).to receive(:run!).with(/lib\/foo.rb lib\/bar.rb$/).and_return("")
34
+ expect(reek).to receive(:run!) do |files, _config_files|
35
+ expect(files).to eq(["lib/foo.rb", "lib/bar.rb"])
36
+ end.and_return("")
37
+
39
38
  reek.emit
40
39
  end
41
40
  end
42
41
 
43
- #TODO review tested output
44
42
  describe "analyze method" do
45
-
46
43
  before :each do
47
44
  MetricFu::Configuration.run {}
48
45
  allow(File).to receive(:directory?).and_return(true)
49
- @reek = MetricFu::ReekGenerator.new
46
+ @generator = MetricFu::ReekGenerator.new
47
+ @examiner = @generator.send(:examiner)
48
+ @smell_warning = Reek.const_defined?(:SmellWarning) ? Reek.const_get(:SmellWarning) : Reek.const_get(:Smells).const_get(:SmellWarning)
49
+ if @smell_warning.instance_methods.include?(:subclass)
50
+ @smell_warning.send(:alias_method, :smell_type, :subclass)
51
+ end
50
52
  end
51
53
 
52
54
  context "with reek warnings" do
53
55
  before :each do
54
- @lines = <<-HERE
55
- "app/controllers/activity_reports_controller.rb" -- 4 warnings:
56
- ActivityReportsController#authorize_user calls current_user.primary_site_ids multiple times (Duplication)
57
- ActivityReportsController#authorize_user calls params[id] multiple times (Duplication)
58
- ActivityReportsController#authorize_user calls params[primary_site_id] multiple times (Duplication)
59
- ActivityReportsController#authorize_user has approx 6 statements (Long Method)
60
-
61
- "app/controllers/application.rb" -- 1 warnings:
62
- ApplicationController#start_background_task/block/block is nested (Nested Iterators)
63
-
64
- "app/controllers/link_targets_controller.rb" -- 1 warnings:
65
- LinkTargetsController#authorize_user calls current_user.role multiple times (Duplication)
66
-
67
- "app/controllers/newline_controller.rb" -- 1 warnings:
68
- NewlineController#some_method calls current_user.<< "new line\n" multiple times (Duplication)
69
- HERE
70
- @reek.instance_variable_set(:@output, @lines)
71
- @matches = @reek.analyze
56
+ @smells = [
57
+ instance_double(@smell_warning,
58
+ source: "app/controllers/activity_reports_controller.rb",
59
+ context: "ActivityReportsController#authorize_user",
60
+ message: "calls current_user.primary_site_ids multiple times",
61
+ smell_type: "Duplication",
62
+ lines: [2, 4]),
63
+ instance_double(@smell_warning,
64
+ source: "app/controllers/activity_reports_controller.rb",
65
+ context: "ActivityReportsController#authorize_user",
66
+ message: "calls params[id] multiple times",
67
+ smell_type: "Duplication",
68
+ lines: [5, 7]),
69
+ instance_double(@smell_warning,
70
+ source: "app/controllers/activity_reports_controller.rb",
71
+ context: "ActivityReportsController#authorize_user",
72
+ message: "calls params[primary_site_id] multiple times",
73
+ smell_type: "Duplication",
74
+ lines: [11, 15]),
75
+ instance_double(@smell_warning,
76
+ source: "app/controllers/activity_reports_controller.rb",
77
+ context: "ActivityReportsController#authorize_user",
78
+ message: "has approx 6 statements",
79
+ smell_type: "Long Method",
80
+ lines: [8]),
81
+
82
+ instance_double(@smell_warning,
83
+ source: "app/controllers/application.rb",
84
+ context: "ApplicationController#start_background_task/block/block",
85
+ message: "is nested",
86
+ smell_type: "Nested Iterators",
87
+ lines: [23]),
88
+
89
+ instance_double(@smell_warning,
90
+ source: "app/controllers/link_targets_controller.rb",
91
+ context: "LinkTargetsController#authorize_user",
92
+ message: "calls current_user.role multiple times",
93
+ smell_type: "Duplication",
94
+ lines: [8]),
95
+
96
+ instance_double(@smell_warning,
97
+ source: "app/controllers/newline_controller.rb",
98
+ context: "NewlineController#some_method",
99
+ message: "calls current_user.<< \"new line\n\" multiple times",
100
+ smell_type: "Duplication",
101
+ lines: [6, 9])
102
+ ]
103
+ @examiners = [
104
+ instance_double(Reek::Examiner, smells: @smells)
105
+ ]
106
+ @generator.instance_variable_set(:@output, @examiners)
107
+ @matches = @generator.analyze
108
+ end
109
+
110
+ it "should find the code smell's line numbers" do
111
+ smell = @matches.first[:code_smells].first
112
+ expect(smell[:lines]).to eq([2, 4])
72
113
  end
73
114
 
74
115
  it "should find the code smell's method name" do
@@ -93,91 +134,70 @@ NewlineController#some_method calls current_user.<< "new line\n" multiple times
93
134
 
94
135
  it "should NOT insert nil smells into the array when there's a newline in the method call" do
95
136
  expect(@matches.last[:code_smells]).to eq(@matches.last[:code_smells].compact)
96
- expect(@matches.last).to eq({:file_path=>"app/controllers/newline_controller.rb",
97
- :code_smells=>[{:type=>"Duplication",
98
- :method=>"\"",
99
- :message=>"multiple times"}]})
100
- # Note: hopefully a temporary solution until I figure out how to deal with newlines in the method call more effectively -Jake 5/11/2009
101
137
  end
102
138
  end
103
139
 
104
- context "without reek warnings" do
140
+ context "with reek 1.3 output" do
105
141
  before :each do
106
- @lines = <<-HERE
107
-
108
- 0 total warnings
109
- HERE
110
- @reek.instance_variable_set(:@output, @lines)
111
- @matches = @reek.analyze
142
+ @smells = [
143
+ double(source: "app/controllers/activity_reports_controller.rb",
144
+ context: "ActivityReportsController#authorize_user",
145
+ message: "calls current_user.primary_site_ids multiple times",
146
+ subclass: "Duplication",
147
+ lines: [2, 4]),
148
+ ]
149
+ @examiners = [
150
+ instance_double(Reek::Examiner, smells: @smells)
151
+ ]
152
+ @generator.instance_variable_set(:@output, @examiners)
153
+ @matches = @generator.analyze
112
154
  end
113
155
 
114
- it "returns empty analysis" do
115
- expect(@matches).to eq({})
156
+ it "uses the subclass field to find the smell type" do
157
+ smell = @matches.first[:code_smells].first
158
+ expect(smell[:type]).to eq('Duplication')
116
159
  end
117
160
  end
118
- end
119
- end
120
161
 
121
- describe MetricFu::ReekGenerator do
122
- before :each do
123
- MetricFu::Configuration.run {}
124
- @reek = MetricFu::ReekGenerator.new
125
- @lines11 = <<-HERE
126
- "app/controllers/activity_reports_controller.rb" -- 4 warnings:
127
- ActivityReportsController#authorize_user calls current_user.primary_site_ids multiple times (Duplication)
128
- ActivityReportsController#authorize_user calls params[id] multiple times (Duplication)
129
- ActivityReportsController#authorize_user calls params[primary_site_id] multiple times (Duplication)
130
- ActivityReportsController#authorize_user has approx 6 statements (Long Method)
131
-
132
- "app/controllers/application.rb" -- 1 warnings:
133
- ApplicationController#start_background_task/block/block is nested (Nested Iterators)
134
-
135
- "app/controllers/link_targets_controller.rb" -- 1 warnings:
136
- LinkTargetsController#authorize_user calls current_user.role multiple times (Duplication)
137
-
138
- "app/controllers/newline_controller.rb" -- 1 warnings:
139
- NewlineController#some_method calls current_user.<< "new line\n" multiple times (Duplication)
140
- HERE
141
- @lines12 = <<-HERE
142
- app/controllers/activity_reports_controller.rb -- 4 warnings (+3 masked):
143
- ActivityReportsController#authorize_user calls current_user.primary_site_ids multiple times (Duplication)
144
- ActivityReportsController#authorize_user calls params[id] multiple times (Duplication)
145
- ActivityReportsController#authorize_user calls params[primary_site_id] multiple times (Duplication)
146
- ActivityReportsController#authorize_user has approx 6 statements (Long Method)
147
- app/controllers/application.rb -- 1 warnings:
148
- ApplicationController#start_background_task/block/block is nested (Nested Iterators)
149
- app/controllers/link_targets_controller.rb -- 1 warnings (+1 masked):
150
- LinkTargetsController#authorize_user calls current_user.role multiple times (Duplication)
151
- app/controllers/newline_controller.rb -- 1 warnings:
152
- NewlineController#some_method calls current_user.<< "new line\n" multiple times (Duplication)
153
- HERE
154
- end
162
+ context "with real output, not mocked nor doubled" do
163
+ let(:result) do
164
+ {
165
+ file_path: "spec/support/samples/reek/alfa.rb",
166
+ code_smells: [
167
+ {
168
+ lines: [1],
169
+ message: "has unused parameter 'echo'",
170
+ method: "foo",
171
+ type: "UnusedParameters"
172
+ }
173
+ ]
174
+ }
175
+ end
155
176
 
156
- context 'with Reek 1.1 output format' do
157
- it 'reports 1.1 style when the output is empty' do
158
- @reek.instance_variable_set(:@output, "")
159
- expect(@reek).not_to be_reek_12
160
- end
161
- it 'detects 1.1 format output' do
162
- @reek.instance_variable_set(:@output, @lines11)
163
- expect(@reek).not_to be_reek_12
164
- end
177
+ it "returns real data" do
178
+ MetricFu.with_run_dir File.expand_path("../../..", __FILE__) do
179
+ @generator = MetricFu::ReekGenerator.new(dirs_to_reek: ["spec/support/samples"])
180
+ @generator.emit
165
181
 
166
- it 'massages empty output to be unchanged' do
167
- @reek.instance_variable_set(:@output, "")
168
- expect(@reek.massage_for_reek_12).to be_empty
169
- end
170
- end
182
+ @matches = @generator.analyze
171
183
 
172
- context 'with Reek 1.2 output format' do
173
- it 'detects 1.2 format output' do
174
- @reek.instance_variable_set(:@output, @lines12)
175
- expect(@reek).to be_reek_12
184
+ expect(@matches.first).to eq(result)
185
+ end
186
+ end
176
187
  end
177
188
 
178
- it 'correctly massages 1.2 output' do
179
- @reek.instance_variable_set(:@output, @lines12)
180
- expect(@reek.massage_for_reek_12).to eq(@lines11)
189
+ context "without reek warnings" do
190
+ before :each do
191
+ @examiners = [
192
+ instance_double(Reek::Examiner, smells: [])
193
+ ]
194
+ @generator.instance_variable_set(:@output, @examiners)
195
+ @matches = @generator.analyze
196
+ end
197
+
198
+ it "returns empty analysis" do
199
+ expect(@matches).to eq([])
200
+ end
181
201
  end
182
202
  end
183
203
  end
@@ -1,5 +1,5 @@
1
1
  require "spec_helper"
2
- MetricFu.metrics_require { 'reek/grapher' }
2
+ MetricFu.metrics_require { "reek/grapher" }
3
3
 
4
4
  describe ReekGrapher do
5
5
  before :each do
@@ -45,7 +45,7 @@ describe ReekGrapher do
45
45
 
46
46
  it "should set a hash of code smells to reek_count" do
47
47
  @reek_grapher.get_metrics(@metrics, @date)
48
- expect(@reek_grapher.reek_count).to eq({
48
+ expect(@reek_grapher.reek_count).to eq(
49
49
  "Uncommunicative Name" => [27],
50
50
  "Feature Envy" => [20],
51
51
  "Utility Function" => [15],
@@ -54,11 +54,11 @@ describe ReekGrapher do
54
54
  "Control Couple" => [4],
55
55
  "Duplication" => [48],
56
56
  "Large Class" => [1]
57
- })
57
+ )
58
58
  end
59
59
 
60
60
  it "should update labels with the date" do
61
- expect(@reek_grapher.labels).to receive(:update).with({ 0 => "1/2" })
61
+ expect(@reek_grapher.labels).to receive(:update).with(0 => "1/2")
62
62
  @reek_grapher.get_metrics(@metrics, @date)
63
63
  end
64
64
  end
@@ -1,16 +1,14 @@
1
- require 'spec_helper'
2
- require 'shared/configured'
1
+ require "spec_helper"
2
+ require "shared/configured"
3
3
 
4
- describe MetricFu::Configuration, 'for roodi' do
5
- it_behaves_like 'configured' do
6
-
7
- it 'should set @roodi to {:dirs_to_roodi => @code_dirs}' do
8
- load_metric 'roodi'
4
+ describe MetricFu::Configuration, "for roodi" do
5
+ it_behaves_like "configured" do
6
+ it "should set @roodi to {:dirs_to_roodi => @code_dirs}" do
7
+ load_metric "roodi"
9
8
  expect(MetricFu::Metric.get_metric(:roodi).run_options).to eq(
10
- { :dirs_to_roodi => directory('code_dirs'),
11
- :roodi_config => "#{directory('root_directory')}/config/roodi_config.yml"}
9
+ dirs_to_roodi: directory("code_dirs"),
10
+ roodi_config: "#{directory('root_directory')}/config/roodi_config.yml"
12
11
  )
13
12
  end
14
-
15
13
  end
16
14
  end
@@ -1,17 +1,17 @@
1
1
  require "spec_helper"
2
- MetricFu.metrics_require { 'roodi/generator' }
2
+ MetricFu.metrics_require { "roodi/generator" }
3
3
 
4
4
  describe MetricFu::RoodiGenerator do
5
5
  describe "emit" do
6
6
  it "should add config options when present" do
7
- options = {:roodi_config => 'lib/config/roodi_config.yml', :dirs_to_roodi => []}
7
+ options = { roodi_config: "lib/config/roodi_config.yml", dirs_to_roodi: [] }
8
8
  roodi = MetricFu::RoodiGenerator.new(options)
9
9
  expect(roodi).to receive(:run!).with(/-config=lib\/config\/roodi_config\.yml/).and_return("")
10
10
  roodi.emit
11
11
  end
12
12
 
13
13
  it "should NOT add config options when NOT present" do
14
- options = {:dirs_to_roodi => []}
14
+ options = { dirs_to_roodi: [] }
15
15
  roodi = MetricFu::RoodiGenerator.new(options)
16
16
  allow(roodi).to receive(:run!)
17
17
  expect(roodi).to receive(:run!).with(/-config/).never
@@ -1,5 +1,5 @@
1
1
  require "spec_helper"
2
- MetricFu.metrics_require { 'roodi/grapher' }
2
+ MetricFu.metrics_require { "roodi/grapher" }
3
3
 
4
4
  describe RoodiGrapher do
5
5
  before :each do
@@ -49,7 +49,7 @@ describe RoodiGrapher do
49
49
  end
50
50
 
51
51
  it "should update labels with the date" do
52
- expect(@roodi_grapher.labels).to receive(:update).with({ 0 => "1/2" })
52
+ expect(@roodi_grapher.labels).to receive(:update).with(0 => "1/2")
53
53
  @roodi_grapher.get_metrics(@metrics, @date)
54
54
  end
55
55
  end
@@ -1,26 +1,25 @@
1
- require 'spec_helper'
2
- require 'shared/configured'
1
+ require "spec_helper"
2
+ require "shared/configured"
3
3
 
4
- describe MetricFu::Configuration, 'for saikuro' do
5
- it_behaves_like 'configured' do
6
-
7
- it 'should set @saikuro to { :output_directory => @scratch_directory + "/saikuro",
8
- :input_directory => @code_dirs,
9
- :cyclo => "",
10
- :filter_cyclo => "0",
11
- :warn_cyclo => "5",
12
- :error_cyclo => "7",
13
- :formater => "text" }' do
14
- load_metric 'saikuro'
15
- expect(MetricFu::Metric.get_metric(:saikuro).run_options).to eq(
16
- { :output_directory => "#{scratch_directory}/saikuro",
17
- :input_directory => ['lib'],
18
- :cyclo => "",
19
- :filter_cyclo => "0",
20
- :warn_cyclo => "5",
21
- :error_cyclo => "7",
22
- :formater => "text"}
23
- )
24
- end
4
+ describe MetricFu::Configuration, "for saikuro" do
5
+ it_behaves_like "configured" do
6
+ it "should set @saikuro to { :output_directory => @scratch_directory + '/saikuro',
7
+ :input_directory => @code_dirs,
8
+ :cyclo => '',
9
+ :filter_cyclo => '0',
10
+ :warn_cyclo => '5',
11
+ :error_cyclo => '7',
12
+ :formater => 'text' }" do
13
+ load_metric "saikuro"
14
+ expect(MetricFu::Metric.get_metric(:saikuro).run_options).to eq(
15
+ output_directory: "#{scratch_directory}/saikuro",
16
+ input_directory: ["lib"],
17
+ cyclo: "",
18
+ filter_cyclo: "0",
19
+ warn_cyclo: "5",
20
+ error_cyclo: "7",
21
+ formater: "text"
22
+ )
23
+ end
25
24
  end
26
25
  end