code_metric_fu 4.14.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (296) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +28 -0
  3. data/.metrics +3 -0
  4. data/.rspec +2 -0
  5. data/.rubocop.yml +15 -0
  6. data/.rubocop_todo.yml +69 -0
  7. data/.simplecov +74 -0
  8. data/.travis.yml +22 -0
  9. data/.yardopts +4 -0
  10. data/AUTHORS +12 -0
  11. data/CONTRIBUTING.md +47 -0
  12. data/CONTRIBUTORS +76 -0
  13. data/DEV.md +76 -0
  14. data/Gemfile +74 -0
  15. data/Guardfile +30 -0
  16. data/HISTORY.md +705 -0
  17. data/MIT-LICENSE +22 -0
  18. data/README.md +299 -0
  19. data/Rakefile +27 -0
  20. data/TODO.md +118 -0
  21. data/appveyor.yml +31 -0
  22. data/bin/metric_fu +9 -0
  23. data/bin/mf-cane +10 -0
  24. data/bin/mf-churn +10 -0
  25. data/bin/mf-flay +10 -0
  26. data/bin/mf-reek +10 -0
  27. data/bin/mf-roodi +10 -0
  28. data/bin/mf-saikuro +10 -0
  29. data/certs/bf4.pem +22 -0
  30. data/checksum/.gitkeep +0 -0
  31. data/checksum/metric_fu-4.10.0.gem.sha512 +1 -0
  32. data/checksum/metric_fu-4.11.0.gem.sha512 +1 -0
  33. data/checksum/metric_fu-4.11.1.gem.sha512 +1 -0
  34. data/checksum/metric_fu-4.11.2.gem.sha512 +1 -0
  35. data/checksum/metric_fu-4.11.3.gem.sha512 +1 -0
  36. data/checksum/metric_fu-4.11.4.gem.sha512 +1 -0
  37. data/checksum/metric_fu-4.12.0.gem.sha512 +1 -0
  38. data/checksum/metric_fu-4.2.0.gem.sha512 +1 -0
  39. data/checksum/metric_fu-4.2.1.gem.sha512 +1 -0
  40. data/checksum/metric_fu-4.3.0.gem.sha512 +1 -0
  41. data/checksum/metric_fu-4.3.1.gem.sha512 +1 -0
  42. data/checksum/metric_fu-4.4.0.gem.sha512 +1 -0
  43. data/checksum/metric_fu-4.4.1.gem.sha512 +1 -0
  44. data/checksum/metric_fu-4.4.2.gem.sha512 +1 -0
  45. data/checksum/metric_fu-4.4.3.gem.sha512 +1 -0
  46. data/checksum/metric_fu-4.4.4.gem.sha512 +1 -0
  47. data/checksum/metric_fu-4.5.0.gem.sha512 +1 -0
  48. data/checksum/metric_fu-4.5.1.gem.sha512 +1 -0
  49. data/checksum/metric_fu-4.5.2.gem.sha512 +1 -0
  50. data/checksum/metric_fu-4.6.0.gem.sha512 +1 -0
  51. data/checksum/metric_fu-4.7.0.gem.sha512 +1 -0
  52. data/checksum/metric_fu-4.7.1.gem.sha512 +1 -0
  53. data/checksum/metric_fu-4.7.2.gem.sha512 +1 -0
  54. data/checksum/metric_fu-4.7.3.gem.sha512 +1 -0
  55. data/checksum/metric_fu-4.7.4.gem.sha512 +1 -0
  56. data/checksum/metric_fu-4.8.0.gem.sha512 +1 -0
  57. data/checksum/metric_fu-4.9.0.gem.sha512 +1 -0
  58. data/config/roodi_config.yml +22 -0
  59. data/config/rubocop.yml +269 -0
  60. data/gem_tasks/build.rake +197 -0
  61. data/gem_tasks/rubocop.rake +10 -0
  62. data/gem_tasks/usage_test.rake +19 -0
  63. data/gem_tasks/yard.rake +24 -0
  64. data/lib/metric_fu/calculate.rb +10 -0
  65. data/lib/metric_fu/cli/client.rb +26 -0
  66. data/lib/metric_fu/cli/helper.rb +80 -0
  67. data/lib/metric_fu/cli/parser.rb +138 -0
  68. data/lib/metric_fu/configuration.rb +150 -0
  69. data/lib/metric_fu/constantize.rb +57 -0
  70. data/lib/metric_fu/data_structures/line_numbers.rb +112 -0
  71. data/lib/metric_fu/data_structures/location.rb +110 -0
  72. data/lib/metric_fu/data_structures/sexp_node.rb +107 -0
  73. data/lib/metric_fu/environment.rb +129 -0
  74. data/lib/metric_fu/errors/analysis_error.rb +4 -0
  75. data/lib/metric_fu/formatter/html.rb +96 -0
  76. data/lib/metric_fu/formatter/syntax.rb +45 -0
  77. data/lib/metric_fu/formatter/yaml.rb +18 -0
  78. data/lib/metric_fu/formatter.rb +40 -0
  79. data/lib/metric_fu/gem_run.rb +70 -0
  80. data/lib/metric_fu/gem_version.rb +92 -0
  81. data/lib/metric_fu/generator.rb +135 -0
  82. data/lib/metric_fu/io.rb +132 -0
  83. data/lib/metric_fu/loader.rb +105 -0
  84. data/lib/metric_fu/logger.rb +62 -0
  85. data/lib/metric_fu/logging/mf_debugger.rb +23 -0
  86. data/lib/metric_fu/metric.rb +143 -0
  87. data/lib/metric_fu/metrics/cane/generator.rb +95 -0
  88. data/lib/metric_fu/metrics/cane/grapher.rb +37 -0
  89. data/lib/metric_fu/metrics/cane/metric.rb +34 -0
  90. data/lib/metric_fu/metrics/cane/report.html.erb +87 -0
  91. data/lib/metric_fu/metrics/cane/violations.rb +46 -0
  92. data/lib/metric_fu/metrics/churn/generator.rb +37 -0
  93. data/lib/metric_fu/metrics/churn/hotspot.rb +43 -0
  94. data/lib/metric_fu/metrics/churn/metric.rb +29 -0
  95. data/lib/metric_fu/metrics/churn/report.html.erb +58 -0
  96. data/lib/metric_fu/metrics/flay/generator.rb +51 -0
  97. data/lib/metric_fu/metrics/flay/grapher.rb +37 -0
  98. data/lib/metric_fu/metrics/flay/hotspot.rb +52 -0
  99. data/lib/metric_fu/metrics/flay/metric.rb +28 -0
  100. data/lib/metric_fu/metrics/flay/report.html.erb +29 -0
  101. data/lib/metric_fu/metrics/flog/generator.rb +113 -0
  102. data/lib/metric_fu/metrics/flog/grapher.rb +77 -0
  103. data/lib/metric_fu/metrics/flog/hotspot.rb +46 -0
  104. data/lib/metric_fu/metrics/flog/metric.rb +29 -0
  105. data/lib/metric_fu/metrics/flog/report.html.erb +50 -0
  106. data/lib/metric_fu/metrics/hotspots/analysis/analyzed_problems.rb +34 -0
  107. data/lib/metric_fu/metrics/hotspots/analysis/analyzer_tables.rb +114 -0
  108. data/lib/metric_fu/metrics/hotspots/analysis/grouping.rb +23 -0
  109. data/lib/metric_fu/metrics/hotspots/analysis/groupings.rb +12 -0
  110. data/lib/metric_fu/metrics/hotspots/analysis/problems.rb +20 -0
  111. data/lib/metric_fu/metrics/hotspots/analysis/ranked_problem_location.rb +70 -0
  112. data/lib/metric_fu/metrics/hotspots/analysis/ranking.rb +29 -0
  113. data/lib/metric_fu/metrics/hotspots/analysis/rankings.rb +91 -0
  114. data/lib/metric_fu/metrics/hotspots/analysis/record.rb +32 -0
  115. data/lib/metric_fu/metrics/hotspots/analysis/scoring_strategies.rb +24 -0
  116. data/lib/metric_fu/metrics/hotspots/analysis/table.rb +67 -0
  117. data/lib/metric_fu/metrics/hotspots/generator.rb +40 -0
  118. data/lib/metric_fu/metrics/hotspots/hotspot.rb +87 -0
  119. data/lib/metric_fu/metrics/hotspots/hotspot_analyzer.rb +61 -0
  120. data/lib/metric_fu/metrics/hotspots/metric.rb +20 -0
  121. data/lib/metric_fu/metrics/hotspots/report.html.erb +60 -0
  122. data/lib/metric_fu/metrics/rails_best_practices/generator.rb +47 -0
  123. data/lib/metric_fu/metrics/rails_best_practices/grapher.rb +38 -0
  124. data/lib/metric_fu/metrics/rails_best_practices/metric.rb +31 -0
  125. data/lib/metric_fu/metrics/rails_best_practices/report.html.erb +22 -0
  126. data/lib/metric_fu/metrics/rcov/external_client.rb +22 -0
  127. data/lib/metric_fu/metrics/rcov/generator.rb +75 -0
  128. data/lib/metric_fu/metrics/rcov/grapher.rb +37 -0
  129. data/lib/metric_fu/metrics/rcov/hotspot.rb +46 -0
  130. data/lib/metric_fu/metrics/rcov/metric.rb +61 -0
  131. data/lib/metric_fu/metrics/rcov/rcov_format_coverage.rb +149 -0
  132. data/lib/metric_fu/metrics/rcov/rcov_line.rb +48 -0
  133. data/lib/metric_fu/metrics/rcov/report.html.erb +40 -0
  134. data/lib/metric_fu/metrics/rcov/simplecov_formatter.rb +74 -0
  135. data/lib/metric_fu/metrics/reek/generator.rb +97 -0
  136. data/lib/metric_fu/metrics/reek/grapher.rb +55 -0
  137. data/lib/metric_fu/metrics/reek/hotspot.rb +95 -0
  138. data/lib/metric_fu/metrics/reek/metric.rb +26 -0
  139. data/lib/metric_fu/metrics/reek/report.html.erb +35 -0
  140. data/lib/metric_fu/metrics/roodi/generator.rb +41 -0
  141. data/lib/metric_fu/metrics/roodi/grapher.rb +37 -0
  142. data/lib/metric_fu/metrics/roodi/hotspot.rb +39 -0
  143. data/lib/metric_fu/metrics/roodi/metric.rb +24 -0
  144. data/lib/metric_fu/metrics/roodi/report.html.erb +22 -0
  145. data/lib/metric_fu/metrics/saikuro/generator.rb +145 -0
  146. data/lib/metric_fu/metrics/saikuro/hotspot.rb +51 -0
  147. data/lib/metric_fu/metrics/saikuro/metric.rb +31 -0
  148. data/lib/metric_fu/metrics/saikuro/parsing_element.rb +37 -0
  149. data/lib/metric_fu/metrics/saikuro/report.html.erb +71 -0
  150. data/lib/metric_fu/metrics/saikuro/scratch_file.rb +108 -0
  151. data/lib/metric_fu/metrics/stats/generator.rb +82 -0
  152. data/lib/metric_fu/metrics/stats/grapher.rb +40 -0
  153. data/lib/metric_fu/metrics/stats/hotspot.rb +35 -0
  154. data/lib/metric_fu/metrics/stats/metric.rb +28 -0
  155. data/lib/metric_fu/metrics/stats/report.html.erb +44 -0
  156. data/lib/metric_fu/reporter.rb +37 -0
  157. data/lib/metric_fu/reporting/graphs/graph.rb +69 -0
  158. data/lib/metric_fu/reporting/graphs/grapher.rb +66 -0
  159. data/lib/metric_fu/reporting/result.rb +59 -0
  160. data/lib/metric_fu/run.rb +82 -0
  161. data/lib/metric_fu/tasks/metric_fu.rake +54 -0
  162. data/lib/metric_fu/templates/_gem_info.html.erb +8 -0
  163. data/lib/metric_fu/templates/_graph.html.erb +2 -0
  164. data/lib/metric_fu/templates/_report_footer.html.erb +1 -0
  165. data/lib/metric_fu/templates/configuration.rb +25 -0
  166. data/lib/metric_fu/templates/css/bluff.css +15 -0
  167. data/lib/metric_fu/templates/css/buttons.css +82 -0
  168. data/lib/metric_fu/templates/css/default.css +43 -0
  169. data/lib/metric_fu/templates/css/integrity.css +337 -0
  170. data/lib/metric_fu/templates/css/rcov.css +32 -0
  171. data/lib/metric_fu/templates/css/reset.css +7 -0
  172. data/lib/metric_fu/templates/css/syntax.css +19 -0
  173. data/lib/metric_fu/templates/index.html.erb +13 -0
  174. data/lib/metric_fu/templates/javascripts/bluff-min.js +1 -0
  175. data/lib/metric_fu/templates/javascripts/bluff_graph.js +15 -0
  176. data/lib/metric_fu/templates/javascripts/excanvas.js +35 -0
  177. data/lib/metric_fu/templates/javascripts/highcharts.js +294 -0
  178. data/lib/metric_fu/templates/javascripts/highcharts_graph.js +38 -0
  179. data/lib/metric_fu/templates/javascripts/js-class.js +1 -0
  180. data/lib/metric_fu/templates/javascripts/standalone-framework.js +17 -0
  181. data/lib/metric_fu/templates/javascripts/utils.js +9 -0
  182. data/lib/metric_fu/templates/layout.html.erb +41 -0
  183. data/lib/metric_fu/templates/metrics_template.rb +86 -0
  184. data/lib/metric_fu/templates/report.html.erb +31 -0
  185. data/lib/metric_fu/templates/report.rb +41 -0
  186. data/lib/metric_fu/templates/template.rb +247 -0
  187. data/lib/metric_fu/utility.rb +79 -0
  188. data/lib/metric_fu/version.rb +9 -0
  189. data/lib/metric_fu.rb +143 -0
  190. data/metric_fu.gemspec +72 -0
  191. data/spec/capture_warnings.rb +55 -0
  192. data/spec/cli/helper_spec.rb +165 -0
  193. data/spec/dummy/.gitignore +1 -0
  194. data/spec/dummy/.gitkeep +0 -0
  195. data/spec/dummy/.metrics +4 -0
  196. data/spec/dummy/lib/.gitkeep +0 -0
  197. data/spec/dummy/lib/bad_encoding.rb +6 -0
  198. data/spec/dummy/spec/.gitkeep +0 -0
  199. data/spec/fixtures/20090630.yml +7922 -0
  200. data/spec/fixtures/coverage-153.rb +11 -0
  201. data/spec/fixtures/coverage.rb +13 -0
  202. data/spec/fixtures/exit0.sh +3 -0
  203. data/spec/fixtures/exit1.sh +3 -0
  204. data/spec/fixtures/hotspots/flog.yml +86 -0
  205. data/spec/fixtures/hotspots/generator.yml +47 -0
  206. data/spec/fixtures/hotspots/generator_analysis.yml +53 -0
  207. data/spec/fixtures/hotspots/reek.yml +14 -0
  208. data/spec/fixtures/hotspots/roodi.yml +13 -0
  209. data/spec/fixtures/hotspots/saikuro.yml +27 -0
  210. data/spec/fixtures/hotspots/several_metrics.yml +47 -0
  211. data/spec/fixtures/hotspots/stats.yml +4 -0
  212. data/spec/fixtures/hotspots/three_metrics_on_same_file.yml +36 -0
  213. data/spec/fixtures/line_numbers/foo.rb +33 -0
  214. data/spec/fixtures/line_numbers/module.rb +11 -0
  215. data/spec/fixtures/line_numbers/module_surrounds_class.rb +15 -0
  216. data/spec/fixtures/line_numbers/two_classes.rb +11 -0
  217. data/spec/fixtures/metric_missing.yml +1 -0
  218. data/spec/fixtures/rcov_output.txt +135 -0
  219. data/spec/fixtures/saikuro/app/controllers/sessions_controller.rb_cyclo.html +10 -0
  220. data/spec/fixtures/saikuro/app/controllers/users_controller.rb_cyclo.html +16 -0
  221. data/spec/fixtures/saikuro/index_cyclo.html +155 -0
  222. data/spec/fixtures/saikuro_sfiles/thing.rb_cyclo.html +11 -0
  223. data/spec/metric_fu/calculate_spec.rb +21 -0
  224. data/spec/metric_fu/configuration_spec.rb +90 -0
  225. data/spec/metric_fu/data_structures/line_numbers_spec.rb +63 -0
  226. data/spec/metric_fu/data_structures/location_spec.rb +110 -0
  227. data/spec/metric_fu/formatter/configuration_spec.rb +44 -0
  228. data/spec/metric_fu/formatter/html_spec.rb +138 -0
  229. data/spec/metric_fu/formatter/yaml_spec.rb +61 -0
  230. data/spec/metric_fu/formatter_spec.rb +49 -0
  231. data/spec/metric_fu/gem_version_spec.rb +12 -0
  232. data/spec/metric_fu/generator_spec.rb +130 -0
  233. data/spec/metric_fu/loader_spec.rb +10 -0
  234. data/spec/metric_fu/metric_spec.rb +46 -0
  235. data/spec/metric_fu/metrics/cane/configuration_spec.rb +22 -0
  236. data/spec/metric_fu/metrics/cane/generator_spec.rb +184 -0
  237. data/spec/metric_fu/metrics/churn/configuration_spec.rb +13 -0
  238. data/spec/metric_fu/metrics/churn/generator_spec.rb +64 -0
  239. data/spec/metric_fu/metrics/flay/configuration_spec.rb +13 -0
  240. data/spec/metric_fu/metrics/flay/generator_spec.rb +105 -0
  241. data/spec/metric_fu/metrics/flay/grapher_spec.rb +57 -0
  242. data/spec/metric_fu/metrics/flog/configuration_spec.rb +18 -0
  243. data/spec/metric_fu/metrics/flog/generator_spec.rb +77 -0
  244. data/spec/metric_fu/metrics/flog/grapher_spec.rb +107 -0
  245. data/spec/metric_fu/metrics/hotspots/analysis/analyzed_problems_spec.rb +104 -0
  246. data/spec/metric_fu/metrics/hotspots/analysis/analyzer_tables_spec.rb +71 -0
  247. data/spec/metric_fu/metrics/hotspots/analysis/ranking_spec.rb +30 -0
  248. data/spec/metric_fu/metrics/hotspots/analysis/rankings_spec.rb +97 -0
  249. data/spec/metric_fu/metrics/hotspots/analysis/table_spec.rb +6 -0
  250. data/spec/metric_fu/metrics/hotspots/generator_spec.rb +46 -0
  251. data/spec/metric_fu/metrics/hotspots/hotspot_analyzer_spec.rb +10 -0
  252. data/spec/metric_fu/metrics/hotspots/hotspot_spec.rb +16 -0
  253. data/spec/metric_fu/metrics/rails_best_practices/configuration_spec.rb +55 -0
  254. data/spec/metric_fu/metrics/rails_best_practices/generator_spec.rb +33 -0
  255. data/spec/metric_fu/metrics/rails_best_practices/grapher_spec.rb +62 -0
  256. data/spec/metric_fu/metrics/rcov/configuration_spec.rb +28 -0
  257. data/spec/metric_fu/metrics/rcov/generator_spec.rb +22 -0
  258. data/spec/metric_fu/metrics/rcov/grapher_spec.rb +57 -0
  259. data/spec/metric_fu/metrics/rcov/hotspot_spec.rb +20 -0
  260. data/spec/metric_fu/metrics/rcov/rcov_line_spec.rb +89 -0
  261. data/spec/metric_fu/metrics/rcov/simplecov_formatter_spec.rb +67 -0
  262. data/spec/metric_fu/metrics/reek/configuration_spec.rb +13 -0
  263. data/spec/metric_fu/metrics/reek/generator_spec.rb +169 -0
  264. data/spec/metric_fu/metrics/reek/grapher_spec.rb +66 -0
  265. data/spec/metric_fu/metrics/roodi/configuration_spec.rb +14 -0
  266. data/spec/metric_fu/metrics/roodi/generator_spec.rb +82 -0
  267. data/spec/metric_fu/metrics/roodi/grapher_spec.rb +57 -0
  268. data/spec/metric_fu/metrics/saikuro/configuration_spec.rb +25 -0
  269. data/spec/metric_fu/metrics/saikuro/generator_spec.rb +71 -0
  270. data/spec/metric_fu/metrics/stats/generator_spec.rb +96 -0
  271. data/spec/metric_fu/metrics/stats/grapher_spec.rb +69 -0
  272. data/spec/metric_fu/reporter_spec.rb +41 -0
  273. data/spec/metric_fu/reporting/graphs/graph_spec.rb +44 -0
  274. data/spec/metric_fu/reporting/graphs/grapher_spec.rb +24 -0
  275. data/spec/metric_fu/reporting/result_spec.rb +50 -0
  276. data/spec/metric_fu/run_spec.rb +197 -0
  277. data/spec/metric_fu/templates/configuration_spec.rb +51 -0
  278. data/spec/metric_fu/templates/metrics_template_spec.rb +11 -0
  279. data/spec/metric_fu/templates/report_spec.rb +15 -0
  280. data/spec/metric_fu/templates/template_spec.rb +233 -0
  281. data/spec/metric_fu/utility_spec.rb +12 -0
  282. data/spec/metric_fu_spec.rb +33 -0
  283. data/spec/quality_spec.rb +114 -0
  284. data/spec/shared/configured.rb +45 -0
  285. data/spec/shared/test_coverage.rb +95 -0
  286. data/spec/spec_helper.rb +54 -0
  287. data/spec/support/deferred_garbaged_collection.rb +33 -0
  288. data/spec/support/helper_methods.rb +32 -0
  289. data/spec/support/matcher_create_file.rb +37 -0
  290. data/spec/support/matcher_create_files.rb +43 -0
  291. data/spec/support/suite.rb +26 -0
  292. data/spec/support/test_fixtures.rb +37 -0
  293. data/spec/support/timeout.rb +7 -0
  294. data/spec/support/usage_test.rb +150 -0
  295. data/spec/usage_test_spec.rb +93 -0
  296. metadata +757 -0
@@ -0,0 +1,61 @@
1
+ require "spec_helper"
2
+ MetricFu.formatter_require { "yaml" }
3
+
4
+ describe MetricFu::Formatter::YAML do
5
+ before do
6
+ setup_fs
7
+
8
+ config = MetricFu.configuration
9
+
10
+ if config.mri?
11
+ @metric1 = :cane
12
+ else
13
+ @metric1 = :stats
14
+ config.templates_configuration do |c|
15
+ c.syntax_highlighting = false
16
+ end
17
+ end
18
+ allow(MetricFu::Metric.get_metric(@metric1)).to receive(:run_external).and_return("")
19
+ @metric2 = :hotspots
20
+ MetricFu.result.add(@metric1)
21
+ MetricFu.result.add(@metric2)
22
+ end
23
+
24
+ context "In general" do
25
+ it "creates a report yaml file" do
26
+ expect {
27
+ MetricFu::Formatter::YAML.new.finish
28
+ }.to create_file("#{directory('base_directory')}/report.yml")
29
+ end
30
+ end
31
+
32
+ context "given a custom output file" do
33
+ before do
34
+ @output = "customreport.yml"
35
+ end
36
+
37
+ it "creates a report yaml file to the custom output path" do
38
+ expect {
39
+ MetricFu::Formatter::YAML.new(output: @output).finish
40
+ }.to create_file("#{directory('base_directory')}/customreport.yml")
41
+ end
42
+ end
43
+
44
+ context "given a custom output stream" do
45
+ before do
46
+ @output = $stdout
47
+ end
48
+
49
+ it "creates a report yaml in the custom stream" do
50
+ out = MetricFu::Utility.capture_output {
51
+ MetricFu::Formatter::YAML.new(output: @output).finish
52
+ }
53
+ expect(out).to include ":#{@metric1}:"
54
+ expect(out).to include ":#{@metric2}:"
55
+ end
56
+ end
57
+
58
+ after do
59
+ cleanup_fs
60
+ end
61
+ end
@@ -0,0 +1,49 @@
1
+ require "spec_helper"
2
+
3
+ describe MetricFu::Formatter do
4
+ describe "formatter class loading" do
5
+ context "given a built-in formatter (string)" do
6
+ subject { MetricFu::Formatter.class_for("html") }
7
+
8
+ it "returns the formatter class" do
9
+ expect(subject).to eq(MetricFu::Formatter::HTML)
10
+ end
11
+ end
12
+
13
+ context "given a built-in formatter (symbol)" do
14
+ subject { MetricFu::Formatter.class_for(:yaml) }
15
+
16
+ it "returns the formatter class" do
17
+ expect(subject).to eq(MetricFu::Formatter::YAML)
18
+ end
19
+ end
20
+
21
+ context "given an unknown built-in formatter" do
22
+ subject { MetricFu::Formatter.class_for(:unknown) }
23
+
24
+ it "raises an error" do
25
+ expect { subject }.to raise_error(NameError)
26
+ end
27
+ end
28
+
29
+ context "given a custom formatter that exists" do
30
+ subject { MetricFu::Formatter.class_for("MyCustomFormatter") }
31
+
32
+ before do
33
+ stub_const("MyCustomFormatter", Class.new { def initialize(*); end })
34
+ end
35
+
36
+ it "returns the formatter class" do
37
+ expect(subject).to eq(MyCustomFormatter)
38
+ end
39
+ end
40
+
41
+ context "given a custom formatter that doesnt exist" do
42
+ subject { MetricFu::Formatter.class_for("MyNonExistentCustomFormatter") }
43
+
44
+ it "raises an error" do
45
+ expect { subject }.to raise_error(NameError)
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,12 @@
1
+ require "spec_helper"
2
+ MetricFu.lib_require { "gem_version" }
3
+
4
+ describe MetricFu::GemVersion do
5
+ it "has a list of gem deps" do
6
+ gem_version = MetricFu::GemVersion.new
7
+ gem_deps = gem_version.gem_runtime_dependencies.map(&:name)
8
+ MetricFu::Metric.metrics.reject { |metric| metric.name == :hotspots || metric.name == :stats }.map(&:name).map(&:to_s).each do |metric_name|
9
+ expect(gem_deps).to include(metric_name)
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,130 @@
1
+ require "spec_helper"
2
+
3
+ describe MetricFu::Generator do
4
+ include TestConstruct::Helpers
5
+
6
+ class ConcreteClass < MetricFu::Generator
7
+ def self.metric
8
+ :concrete
9
+ end
10
+
11
+ def emit
12
+ end
13
+
14
+ def analyze
15
+ end
16
+
17
+ def to_h
18
+ end
19
+ end
20
+
21
+ before(:each) do
22
+ ENV["CC_BUILD_ARTIFACTS"] = nil
23
+ MetricFu.configuration.reset
24
+ MetricFu.configure
25
+ @concrete_class = ConcreteClass.new
26
+ end
27
+
28
+ describe "ConcreteClass#metric_directory" do
29
+ it "should be '{artifact_dir}/scratch/concreteclass'" do
30
+ concrete_metric = double("concrete_metric")
31
+ expect(MetricFu::Metric).to receive(:get_metric).with(:concrete).and_return(concrete_metric)
32
+ expect(concrete_metric).to receive(:run_options).and_return({})
33
+ compare_paths(ConcreteClass.metric_directory, scratch_directory("concrete"))
34
+ end
35
+ end
36
+
37
+ describe "#metric_directory" do
38
+ it "should return the results of ConcreteClass#metric_directory" do
39
+ allow(ConcreteClass).to receive(:metric_directory).and_return("foo")
40
+ expect(@concrete_class.metric_directory).to eq("foo")
41
+ end
42
+ end
43
+
44
+ describe "#generate_result" do
45
+ it "should raise an error when calling #emit" do
46
+ @abstract_class = MetricFu::Generator.new
47
+ expect { @abstract_class.generate_result }.to raise_error NotImplementedError
48
+ end
49
+
50
+ it "should call #analyze" do
51
+ @abstract_class = MetricFu::Generator.new
52
+ expect { @abstract_class.generate_result }.to raise_error NotImplementedError
53
+ end
54
+
55
+ it "should call #to_h" do
56
+ @abstract_class = MetricFu::Generator.new
57
+ expect { @abstract_class.generate_result }.to raise_error NotImplementedError
58
+ end
59
+ end
60
+
61
+ describe "#generate_result (in a concrete class)" do
62
+ %w[emit analyze].each do |meth|
63
+ it "should call ##{meth}" do
64
+ expect(@concrete_class).to receive("#{meth}")
65
+ @concrete_class.generate_result
66
+ end
67
+ end
68
+
69
+ it "should call #to_h" do
70
+ expect(@concrete_class).to receive(:to_h)
71
+ @concrete_class.generate_result
72
+ end
73
+ end
74
+
75
+ describe "path filter" do
76
+ context "given a list of paths" do
77
+ before do
78
+ @paths = %w(lib/fake/fake.rb
79
+ lib/this/dan_file.rb
80
+ lib/this/ben_file.rb
81
+ lib/this/avdi_file.rb
82
+ basic.rb
83
+ lib/bad/one.rb
84
+ lib/bad/two.rb
85
+ lib/bad/three.rb
86
+ lib/worse/four.rb)
87
+ @container = create_construct
88
+ @paths.each do |path|
89
+ @container.file(path)
90
+ end
91
+ @old_dir = MetricFu.run_dir
92
+ Dir.chdir(@container)
93
+ end
94
+
95
+ after do
96
+ Dir.chdir(@old_dir)
97
+ @container.destroy!
98
+ end
99
+
100
+ it "should return entire pathlist given no exclude pattens" do
101
+ files = @concrete_class.remove_excluded_files(@paths)
102
+ expect(files).to eq(@paths)
103
+ end
104
+
105
+ it "should filter filename at root level" do
106
+ files = @concrete_class.remove_excluded_files(@paths, ["basic.rb"])
107
+ expect(files).not_to include("basic.rb")
108
+ end
109
+
110
+ it "should remove files that are two levels deep" do
111
+ files = @concrete_class.remove_excluded_files(@paths, ["**/fake.rb"])
112
+ expect(files).not_to include("lib/fake/fake.rb")
113
+ end
114
+
115
+ it "should remove files from an excluded directory" do
116
+ files = @concrete_class.remove_excluded_files(@paths, ["lib/bad/**"])
117
+ expect(files).not_to include("lib/bad/one.rb")
118
+ expect(files).not_to include("lib/bad/two.rb")
119
+ expect(files).not_to include("lib/bad/three.rb")
120
+ end
121
+
122
+ it "should support shell alternation globs" do
123
+ files = @concrete_class.remove_excluded_files(@paths, ["lib/this/{ben,dan}_file.rb"])
124
+ expect(files).not_to include("lib/this/dan_file.rb")
125
+ expect(files).not_to include("lib/this/ben_file.rb")
126
+ expect(files).to include("lib/this/avdi_file.rb")
127
+ end
128
+ end
129
+ end
130
+ end
@@ -0,0 +1,10 @@
1
+ require "spec_helper"
2
+
3
+ describe MetricFu do
4
+ it "loads the .metrics file" do
5
+ # Global only for testing that this file gets loaded
6
+ $metric_file_loaded = false
7
+ MetricFu.loader.load_user_configuration
8
+ expect($metric_file_loaded).to be_truthy
9
+ end
10
+ end
@@ -0,0 +1,46 @@
1
+ require "spec_helper"
2
+
3
+ describe MetricFu::Metric do
4
+ before do
5
+ @metric = MetricFu::Metric.get_metric(:flog)
6
+ # @original_options = @metric.run_options.dup
7
+ end
8
+
9
+ # it "can have its run_options over-written" do
10
+ # new_options = {:foo => 'bar'}
11
+ # @metric.run_options = new_options
12
+ # expect(@original_options).to_not eq(new_options)
13
+ # expect(@metric.run_options).to eq(new_options)
14
+ # end
15
+
16
+ # it "can have its run_options modified" do
17
+ # new_options = {:foo => 'bar'}
18
+ # @metric.run_options.merge!(new_options)
19
+ # expect(@metric.run_options).to eq(@original_options.merge(new_options))
20
+ # end
21
+
22
+ context "given a valid configurable option" do
23
+ before do
24
+ allow(@metric).to receive(:default_run_options).and_return(foo: "baz")
25
+ end
26
+
27
+ it "can be configured as an attribute" do
28
+ @metric.foo = "qux"
29
+ expect(@metric.run_options[:foo]).to eq("qux")
30
+ end
31
+ end
32
+
33
+ context "given an invalid configurable option" do
34
+ before do
35
+ allow(@metric).to receive(:default_run_options).and_return({})
36
+ end
37
+
38
+ it "raises an error" do
39
+ expect { @metric.foo = "bar" }.to raise_error(RuntimeError, /not a valid configuration option/)
40
+ end
41
+ end
42
+
43
+ after do
44
+ @metric.configured_run_options.clear
45
+ end
46
+ end
@@ -0,0 +1,22 @@
1
+ require "spec_helper"
2
+ require "shared/configured"
3
+
4
+ describe MetricFu::Configuration, "for cane" do
5
+ it_behaves_like "configured" do
6
+ if MetricFu.configuration.mri?
7
+ it "should set @cane to " +
8
+ ':dirs_to_cane => @code_dirs, :abc_max => 15, :line_length => 80, :no_doc => "n", :no_readme => "y"' do
9
+ load_metric "cane"
10
+ expect(MetricFu::Metric.get_metric(:cane).run_options).to eq(
11
+
12
+ dirs_to_cane: directory("code_dirs"),
13
+ filetypes: ["rb"],
14
+ abc_max: 15,
15
+ line_length: 80,
16
+ no_doc: "n",
17
+ no_readme: "n"
18
+ )
19
+ end
20
+ end
21
+ end # end it_behaves
22
+ end
@@ -0,0 +1,184 @@
1
+ require "spec_helper"
2
+ MetricFu.metrics_require { "cane/generator" }
3
+
4
+ describe CaneGenerator do
5
+ describe "emit method" do
6
+ it "should execute cane command" do
7
+ options = {}
8
+ @cane = MetricFu::CaneGenerator.new(options)
9
+ expect(@cane).to receive(:run!).with("")
10
+ output = @cane.emit
11
+ end
12
+
13
+ it "should use abc max option" do
14
+ options = { abc_max: 20 }
15
+ @cane = MetricFu::CaneGenerator.new(options)
16
+ expect(@cane).to receive(:run!).with(" --abc-max 20")
17
+ output = @cane.emit
18
+ end
19
+
20
+ it "should use style max line length option" do
21
+ options = { line_length: 100 }
22
+ @cane = MetricFu::CaneGenerator.new(options)
23
+ expect(@cane).to receive(:run!).with(" --style-measure 100")
24
+ output = @cane.emit
25
+ end
26
+
27
+ it "should use no-doc if specified" do
28
+ options = { no_doc: "y" }
29
+ @cane = MetricFu::CaneGenerator.new(options)
30
+ expect(@cane).to receive(:run!).with(" --no-doc")
31
+ output = @cane.emit
32
+ end
33
+
34
+ it "should include doc violations if no_doc != 'y'" do
35
+ options = { no_doc: "n" }
36
+ @cane = MetricFu::CaneGenerator.new(options)
37
+ expect(@cane).to receive(:run!).with("")
38
+ output = @cane.emit
39
+ end
40
+
41
+ it "should use no-readme if specified" do
42
+ options = { no_readme: "y" }
43
+ @cane = MetricFu::CaneGenerator.new(options)
44
+ expect(@cane).to receive(:run!).with(" --no-readme")
45
+ output = @cane.emit
46
+ end
47
+
48
+ it "should include README violations if no_readme != 'y'" do
49
+ options = { no_readme: "n" }
50
+ @cane = MetricFu::CaneGenerator.new(options)
51
+ expect(@cane).to receive(:run!).with("")
52
+ output = @cane.emit
53
+ end
54
+ end
55
+
56
+ describe "parse cane empty output" do
57
+ before :each do
58
+ # MetricFu::Configuration.run {}
59
+ allow(File).to receive(:directory?).and_return(true)
60
+ options = {}
61
+ @cane = MetricFu::CaneGenerator.new(options)
62
+ @cane.instance_variable_set(:@output, "")
63
+ end
64
+
65
+ describe "analyze method" do
66
+ it "should find total violations" do
67
+ @cane.analyze
68
+ expect(@cane.total_violations).to eq(0)
69
+ end
70
+ end
71
+ end
72
+
73
+ describe "parse cane output" do
74
+ before :each do
75
+ lines = sample_cane_output
76
+ MetricFu::Configuration.run {}
77
+ allow(File).to receive(:directory?).and_return(true)
78
+ @cane = MetricFu::CaneGenerator.new("base_dir")
79
+ @cane.instance_variable_set(:@output, lines)
80
+ end
81
+
82
+ describe "analyze method" do
83
+ it "should find total violations" do
84
+ @cane.analyze
85
+ expect(@cane.total_violations).to eq(6)
86
+ end
87
+
88
+ it "should extract abc complexity violations" do
89
+ @cane.analyze
90
+ expect(@cane.violations[:abc_complexity]).to eq([
91
+ { file: "lib/abc/foo.rb", method: "Abc::Foo#method", complexity: "11" },
92
+ { file: "lib/abc/bar.rb", method: "Abc::Bar#method", complexity: "22" }
93
+ ])
94
+ end
95
+
96
+ it "should extract line style violations" do
97
+ @cane.analyze
98
+ expect(@cane.violations[:line_style]).to eq([
99
+ { line: "lib/line/foo.rb:1", description: "Line is >80 characters (135)" },
100
+ { line: "lib/line/bar.rb:2", description: "Line contains trailing whitespace" }
101
+ ])
102
+ end
103
+
104
+ it "should extract comment violations" do
105
+ @cane.analyze
106
+ expect(@cane.violations[:comment]).to eq([
107
+ { line: "lib/comments/foo.rb:1", class_name: "Foo" },
108
+ { line: "lib/comments/bar.rb:2", class_name: "Bar" }
109
+ ])
110
+ end
111
+
112
+ it "should extract no readme violations if present" do
113
+ @cane.analyze
114
+ expect(@cane.violations[:documentation]).to eq([
115
+ { description: "No README found" },
116
+ ])
117
+ end
118
+
119
+ it "should extract unknown violations in others category" do
120
+ @cane.analyze
121
+ expect(@cane.violations[:others]).to eq([
122
+ { description: "Misc issue 1" },
123
+ { description: "Misc issue 2" }
124
+ ])
125
+ end
126
+ end
127
+
128
+ describe "to_h method" do
129
+ it "should have total violations" do
130
+ @cane.analyze
131
+ expect(@cane.to_h[:cane][:total_violations]).to eq(6)
132
+ end
133
+
134
+ it "should have violations by category" do
135
+ @cane.analyze
136
+ expect(@cane.to_h[:cane][:violations][:abc_complexity]).to eq([
137
+ { file: "lib/abc/foo.rb", method: "Abc::Foo#method", complexity: "11" },
138
+ { file: "lib/abc/bar.rb", method: "Abc::Bar#method", complexity: "22" }
139
+ ])
140
+ expect(@cane.to_h[:cane][:violations][:line_style]).to eq([
141
+ { line: "lib/line/foo.rb:1", description: "Line is >80 characters (135)" },
142
+ { line: "lib/line/bar.rb:2", description: "Line contains trailing whitespace" }
143
+ ])
144
+ expect(@cane.to_h[:cane][:violations][:comment]).to eq([
145
+ { line: "lib/comments/foo.rb:1", class_name: "Foo" },
146
+ { line: "lib/comments/bar.rb:2", class_name: "Bar" }
147
+ ])
148
+ end
149
+ end
150
+ end
151
+
152
+ def sample_cane_output
153
+ <<-OUTPUT
154
+ Methods exceeded maximum allowed ABC complexity (33):
155
+
156
+ lib/abc/foo.rb Abc::Foo#method 11
157
+ lib/abc/bar.rb Abc::Bar#method 22
158
+
159
+ Lines violated style requirements (340):
160
+
161
+ lib/line/foo.rb:1 Line is >80 characters (135)
162
+ lib/line/bar.rb:2 Line contains trailing whitespace
163
+
164
+ Missing documentation (1):
165
+
166
+ No README found
167
+
168
+ Class definitions require explanatory comments on preceding line (2):
169
+
170
+ lib/comments/foo.rb:1 Foo
171
+ lib/comments/bar.rb:2 Bar
172
+
173
+ Unknown violation (1):
174
+
175
+ Misc issue 1
176
+
177
+ Another Unknown violation (1):
178
+
179
+ Misc issue 2
180
+
181
+ Total Violations: 6
182
+ OUTPUT
183
+ end
184
+ end
@@ -0,0 +1,13 @@
1
+ require "spec_helper"
2
+ require "shared/configured"
3
+
4
+ describe MetricFu::Configuration, "for churn" do
5
+ it_behaves_like "configured" do
6
+ it "should set @churn to {}" do
7
+ load_metric "churn"
8
+ expect(MetricFu::Metric.get_metric(:churn).run_options).to eq(
9
+ start_date: '"1 year ago"', minimum_churn_count: 10, ignore_files: [], data_directory: MetricFu::Io::FileSystem.scratch_directory("churn")
10
+ )
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,64 @@
1
+ require "spec_helper"
2
+ MetricFu.metrics_require { "churn/generator" }
3
+
4
+ describe MetricFu::ChurnGenerator do
5
+ # TODO extract yaml
6
+ let(:churn_hash) { YAML::load("--- \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") }
7
+
8
+ let(:config_setup) {
9
+ ENV["CC_BUILD_ARTIFACTS"] = nil
10
+ MetricFu.configure.reset
11
+ }
12
+
13
+ describe "analyze method" do
14
+ before :each do
15
+ config_setup
16
+ @changes = { "lib/generators/flog.rb" => 2, "lib/metric_fu.rb" => 3 }
17
+ end
18
+
19
+ it "should be empty on error no output captured" do
20
+ churn = MetricFu::ChurnGenerator.new
21
+ churn.instance_variable_set(:@output, nil)
22
+ result = churn.analyze
23
+ expect(result).to eq(churn: {})
24
+ end
25
+
26
+ it "should return yaml results" do
27
+ churn = MetricFu::ChurnGenerator.new
28
+ churn.instance_variable_set(:@output, churn_hash)
29
+ result = churn.analyze
30
+ expect(result).to eq(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"] })
31
+ end
32
+ end
33
+
34
+ describe "to_h method" do
35
+ before :each do
36
+ config_setup
37
+ end
38
+
39
+ it "should put the changes into a hash" do
40
+ churn = MetricFu::ChurnGenerator.new
41
+ churn.instance_variable_set(:@churn, churn: "results")
42
+ expect(churn.to_h[:churn]).to eq("results")
43
+ end
44
+ end
45
+
46
+ describe "emit method" do
47
+ before :each do
48
+ config_setup
49
+ @churn = MetricFu::ChurnGenerator.new
50
+ end
51
+
52
+ it "returns churn output" do
53
+ allow(@churn).to receive(:run).and_return(churn_hash)
54
+ result = @churn.emit
55
+ expect(result).to eq(churn_hash)
56
+ end
57
+
58
+ it "returns nil, when churn result is not yaml" do
59
+ allow(@churn).to receive(:run).and_return(nil)
60
+ result = @churn.emit
61
+ expect(result).to be nil
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,13 @@
1
+ require "spec_helper"
2
+ require "shared/configured"
3
+
4
+ describe MetricFu::Configuration, "for flay" do
5
+ it_behaves_like "configured" do
6
+ it "should set @flay to {:dirs_to_flay => @code_dirs}" do
7
+ load_metric "flay"
8
+ expect(MetricFu::Metric.get_metric(:flay).run_options).to eq(
9
+ dirs_to_flay: ["lib"], minimum_score: nil
10
+ )
11
+ end
12
+ end
13
+ end