fastruby-metric_fu 5.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +28 -0
- data/.metrics +3 -0
- data/.rspec +2 -0
- data/.rubocop.yml +15 -0
- data/.rubocop_todo.yml +69 -0
- data/.simplecov +74 -0
- data/.travis.yml +18 -0
- data/.yardopts +4 -0
- data/AUTHORS +12 -0
- data/CONTRIBUTING.md +47 -0
- data/CONTRIBUTORS +76 -0
- data/DEV.md +76 -0
- data/Gemfile +58 -0
- data/Guardfile +30 -0
- data/HISTORY.md +705 -0
- data/MIT-LICENSE +22 -0
- data/README.md +299 -0
- data/Rakefile +27 -0
- data/TODO.md +118 -0
- data/appveyor.yml +29 -0
- data/bin/metric_fu +9 -0
- data/bin/mf-cane +10 -0
- data/bin/mf-churn +10 -0
- data/bin/mf-flay +10 -0
- data/bin/mf-reek +10 -0
- data/bin/mf-roodi +10 -0
- data/bin/mf-saikuro +10 -0
- data/certs/bf4.pem +22 -0
- data/checksum/.gitkeep +0 -0
- data/checksum/metric_fu-4.10.0.gem.sha512 +1 -0
- data/checksum/metric_fu-4.11.0.gem.sha512 +1 -0
- data/checksum/metric_fu-4.11.1.gem.sha512 +1 -0
- data/checksum/metric_fu-4.11.2.gem.sha512 +1 -0
- data/checksum/metric_fu-4.11.3.gem.sha512 +1 -0
- data/checksum/metric_fu-4.11.4.gem.sha512 +1 -0
- data/checksum/metric_fu-4.12.0.gem.sha512 +1 -0
- data/checksum/metric_fu-4.2.0.gem.sha512 +1 -0
- data/checksum/metric_fu-4.2.1.gem.sha512 +1 -0
- data/checksum/metric_fu-4.3.0.gem.sha512 +1 -0
- data/checksum/metric_fu-4.3.1.gem.sha512 +1 -0
- data/checksum/metric_fu-4.4.0.gem.sha512 +1 -0
- data/checksum/metric_fu-4.4.1.gem.sha512 +1 -0
- data/checksum/metric_fu-4.4.2.gem.sha512 +1 -0
- data/checksum/metric_fu-4.4.3.gem.sha512 +1 -0
- data/checksum/metric_fu-4.4.4.gem.sha512 +1 -0
- data/checksum/metric_fu-4.5.0.gem.sha512 +1 -0
- data/checksum/metric_fu-4.5.1.gem.sha512 +1 -0
- data/checksum/metric_fu-4.5.2.gem.sha512 +1 -0
- data/checksum/metric_fu-4.6.0.gem.sha512 +1 -0
- data/checksum/metric_fu-4.7.0.gem.sha512 +1 -0
- data/checksum/metric_fu-4.7.1.gem.sha512 +1 -0
- data/checksum/metric_fu-4.7.2.gem.sha512 +1 -0
- data/checksum/metric_fu-4.7.3.gem.sha512 +1 -0
- data/checksum/metric_fu-4.7.4.gem.sha512 +1 -0
- data/checksum/metric_fu-4.8.0.gem.sha512 +1 -0
- data/checksum/metric_fu-4.9.0.gem.sha512 +1 -0
- data/config/roodi_config.yml +22 -0
- data/config/rubocop.yml +269 -0
- data/gem_tasks/build.rake +197 -0
- data/gem_tasks/rubocop.rake +10 -0
- data/gem_tasks/usage_test.rake +19 -0
- data/gem_tasks/yard.rake +24 -0
- data/lib/metric_fu.rb +151 -0
- data/lib/metric_fu/calculate.rb +10 -0
- data/lib/metric_fu/cli/client.rb +26 -0
- data/lib/metric_fu/cli/helper.rb +80 -0
- data/lib/metric_fu/cli/parser.rb +138 -0
- data/lib/metric_fu/configuration.rb +150 -0
- data/lib/metric_fu/constantize.rb +57 -0
- data/lib/metric_fu/data_structures/line_numbers.rb +112 -0
- data/lib/metric_fu/data_structures/location.rb +110 -0
- data/lib/metric_fu/data_structures/sexp_node.rb +107 -0
- data/lib/metric_fu/environment.rb +129 -0
- data/lib/metric_fu/errors/analysis_error.rb +4 -0
- data/lib/metric_fu/formatter.rb +40 -0
- data/lib/metric_fu/formatter/html.rb +96 -0
- data/lib/metric_fu/formatter/syntax.rb +45 -0
- data/lib/metric_fu/formatter/yaml.rb +18 -0
- data/lib/metric_fu/gem_run.rb +70 -0
- data/lib/metric_fu/gem_version.rb +92 -0
- data/lib/metric_fu/generator.rb +135 -0
- data/lib/metric_fu/io.rb +132 -0
- data/lib/metric_fu/loader.rb +105 -0
- data/lib/metric_fu/logger.rb +62 -0
- data/lib/metric_fu/logging/mf_debugger.rb +23 -0
- data/lib/metric_fu/metric.rb +143 -0
- data/lib/metric_fu/metrics/cane/generator.rb +95 -0
- data/lib/metric_fu/metrics/cane/grapher.rb +37 -0
- data/lib/metric_fu/metrics/cane/metric.rb +34 -0
- data/lib/metric_fu/metrics/cane/report.html.erb +87 -0
- data/lib/metric_fu/metrics/cane/violations.rb +46 -0
- data/lib/metric_fu/metrics/churn/generator.rb +37 -0
- data/lib/metric_fu/metrics/churn/hotspot.rb +43 -0
- data/lib/metric_fu/metrics/churn/metric.rb +29 -0
- data/lib/metric_fu/metrics/churn/report.html.erb +58 -0
- data/lib/metric_fu/metrics/flay/generator.rb +51 -0
- data/lib/metric_fu/metrics/flay/grapher.rb +37 -0
- data/lib/metric_fu/metrics/flay/hotspot.rb +52 -0
- data/lib/metric_fu/metrics/flay/metric.rb +28 -0
- data/lib/metric_fu/metrics/flay/report.html.erb +29 -0
- data/lib/metric_fu/metrics/flog/generator.rb +113 -0
- data/lib/metric_fu/metrics/flog/grapher.rb +77 -0
- data/lib/metric_fu/metrics/flog/hotspot.rb +46 -0
- data/lib/metric_fu/metrics/flog/metric.rb +29 -0
- data/lib/metric_fu/metrics/flog/report.html.erb +50 -0
- data/lib/metric_fu/metrics/hotspots/analysis/analyzed_problems.rb +34 -0
- data/lib/metric_fu/metrics/hotspots/analysis/analyzer_tables.rb +114 -0
- data/lib/metric_fu/metrics/hotspots/analysis/grouping.rb +23 -0
- data/lib/metric_fu/metrics/hotspots/analysis/groupings.rb +12 -0
- data/lib/metric_fu/metrics/hotspots/analysis/problems.rb +20 -0
- data/lib/metric_fu/metrics/hotspots/analysis/ranked_problem_location.rb +70 -0
- data/lib/metric_fu/metrics/hotspots/analysis/ranking.rb +29 -0
- data/lib/metric_fu/metrics/hotspots/analysis/rankings.rb +91 -0
- data/lib/metric_fu/metrics/hotspots/analysis/record.rb +32 -0
- data/lib/metric_fu/metrics/hotspots/analysis/scoring_strategies.rb +24 -0
- data/lib/metric_fu/metrics/hotspots/analysis/table.rb +67 -0
- data/lib/metric_fu/metrics/hotspots/generator.rb +40 -0
- data/lib/metric_fu/metrics/hotspots/hotspot.rb +87 -0
- data/lib/metric_fu/metrics/hotspots/hotspot_analyzer.rb +61 -0
- data/lib/metric_fu/metrics/hotspots/metric.rb +20 -0
- data/lib/metric_fu/metrics/hotspots/report.html.erb +60 -0
- data/lib/metric_fu/metrics/rails_best_practices/generator.rb +47 -0
- data/lib/metric_fu/metrics/rails_best_practices/grapher.rb +38 -0
- data/lib/metric_fu/metrics/rails_best_practices/metric.rb +31 -0
- data/lib/metric_fu/metrics/rails_best_practices/report.html.erb +22 -0
- data/lib/metric_fu/metrics/rcov/external_client.rb +22 -0
- data/lib/metric_fu/metrics/rcov/generator.rb +75 -0
- data/lib/metric_fu/metrics/rcov/grapher.rb +37 -0
- data/lib/metric_fu/metrics/rcov/hotspot.rb +46 -0
- data/lib/metric_fu/metrics/rcov/metric.rb +61 -0
- data/lib/metric_fu/metrics/rcov/rcov_format_coverage.rb +149 -0
- data/lib/metric_fu/metrics/rcov/rcov_line.rb +48 -0
- data/lib/metric_fu/metrics/rcov/report.html.erb +40 -0
- data/lib/metric_fu/metrics/rcov/simplecov_formatter.rb +74 -0
- data/lib/metric_fu/metrics/reek/generator.rb +94 -0
- data/lib/metric_fu/metrics/reek/grapher.rb +55 -0
- data/lib/metric_fu/metrics/reek/hotspot.rb +95 -0
- data/lib/metric_fu/metrics/reek/metric.rb +26 -0
- data/lib/metric_fu/metrics/reek/report.html.erb +35 -0
- data/lib/metric_fu/metrics/roodi/generator.rb +40 -0
- data/lib/metric_fu/metrics/roodi/grapher.rb +37 -0
- data/lib/metric_fu/metrics/roodi/hotspot.rb +39 -0
- data/lib/metric_fu/metrics/roodi/metric.rb +24 -0
- data/lib/metric_fu/metrics/roodi/report.html.erb +22 -0
- data/lib/metric_fu/metrics/saikuro/generator.rb +145 -0
- data/lib/metric_fu/metrics/saikuro/hotspot.rb +51 -0
- data/lib/metric_fu/metrics/saikuro/metric.rb +31 -0
- data/lib/metric_fu/metrics/saikuro/parsing_element.rb +37 -0
- data/lib/metric_fu/metrics/saikuro/report.html.erb +71 -0
- data/lib/metric_fu/metrics/saikuro/scratch_file.rb +108 -0
- data/lib/metric_fu/metrics/stats/generator.rb +82 -0
- data/lib/metric_fu/metrics/stats/grapher.rb +40 -0
- data/lib/metric_fu/metrics/stats/hotspot.rb +35 -0
- data/lib/metric_fu/metrics/stats/metric.rb +28 -0
- data/lib/metric_fu/metrics/stats/report.html.erb +44 -0
- data/lib/metric_fu/reporter.rb +37 -0
- data/lib/metric_fu/reporting/graphs/graph.rb +69 -0
- data/lib/metric_fu/reporting/graphs/grapher.rb +66 -0
- data/lib/metric_fu/reporting/result.rb +59 -0
- data/lib/metric_fu/run.rb +82 -0
- data/lib/metric_fu/tasks/metric_fu.rake +54 -0
- data/lib/metric_fu/templates/_graph.html.erb +2 -0
- data/lib/metric_fu/templates/_report_footer.html.erb +1 -0
- data/lib/metric_fu/templates/configuration.rb +25 -0
- data/lib/metric_fu/templates/css/bluff.css +15 -0
- data/lib/metric_fu/templates/css/buttons.css +82 -0
- data/lib/metric_fu/templates/css/default.css +43 -0
- data/lib/metric_fu/templates/css/integrity.css +337 -0
- data/lib/metric_fu/templates/css/rcov.css +32 -0
- data/lib/metric_fu/templates/css/reset.css +7 -0
- data/lib/metric_fu/templates/css/syntax.css +19 -0
- data/lib/metric_fu/templates/index.html.erb +10 -0
- data/lib/metric_fu/templates/javascripts/bluff-min.js +1 -0
- data/lib/metric_fu/templates/javascripts/bluff_graph.js +15 -0
- data/lib/metric_fu/templates/javascripts/excanvas.js +35 -0
- data/lib/metric_fu/templates/javascripts/highcharts.js +294 -0
- data/lib/metric_fu/templates/javascripts/highcharts_graph.js +38 -0
- data/lib/metric_fu/templates/javascripts/js-class.js +1 -0
- data/lib/metric_fu/templates/javascripts/standalone-framework.js +17 -0
- data/lib/metric_fu/templates/javascripts/utils.js +9 -0
- data/lib/metric_fu/templates/layout.html.erb +37 -0
- data/lib/metric_fu/templates/metrics_template.rb +80 -0
- data/lib/metric_fu/templates/report.html.erb +31 -0
- data/lib/metric_fu/templates/report.rb +41 -0
- data/lib/metric_fu/templates/template.rb +244 -0
- data/lib/metric_fu/utility.rb +79 -0
- data/lib/metric_fu/version.rb +9 -0
- data/metric_fu.gemspec +71 -0
- data/spec/capture_warnings.rb +55 -0
- data/spec/cli/helper_spec.rb +165 -0
- data/spec/dummy/.gitignore +1 -0
- data/spec/dummy/.gitkeep +0 -0
- data/spec/dummy/lib/.gitkeep +0 -0
- data/spec/dummy/lib/bad_encoding.rb +6 -0
- data/spec/dummy/spec/.gitkeep +0 -0
- data/spec/fixtures/20090630.yml +7922 -0
- data/spec/fixtures/coverage-153.rb +11 -0
- data/spec/fixtures/coverage.rb +13 -0
- data/spec/fixtures/exit0.sh +3 -0
- data/spec/fixtures/exit1.sh +3 -0
- data/spec/fixtures/hotspots/flog.yml +86 -0
- data/spec/fixtures/hotspots/generator.yml +47 -0
- data/spec/fixtures/hotspots/generator_analysis.yml +53 -0
- data/spec/fixtures/hotspots/reek.yml +14 -0
- data/spec/fixtures/hotspots/roodi.yml +13 -0
- data/spec/fixtures/hotspots/saikuro.yml +27 -0
- data/spec/fixtures/hotspots/several_metrics.yml +47 -0
- data/spec/fixtures/hotspots/stats.yml +4 -0
- data/spec/fixtures/hotspots/three_metrics_on_same_file.yml +36 -0
- data/spec/fixtures/line_numbers/foo.rb +33 -0
- data/spec/fixtures/line_numbers/module.rb +11 -0
- data/spec/fixtures/line_numbers/module_surrounds_class.rb +15 -0
- data/spec/fixtures/line_numbers/two_classes.rb +11 -0
- data/spec/fixtures/metric_missing.yml +1 -0
- data/spec/fixtures/rcov_output.txt +135 -0
- data/spec/fixtures/saikuro/app/controllers/sessions_controller.rb_cyclo.html +10 -0
- data/spec/fixtures/saikuro/app/controllers/users_controller.rb_cyclo.html +16 -0
- data/spec/fixtures/saikuro/index_cyclo.html +155 -0
- data/spec/fixtures/saikuro_sfiles/thing.rb_cyclo.html +11 -0
- data/spec/metric_fu/calculate_spec.rb +21 -0
- data/spec/metric_fu/configuration_spec.rb +90 -0
- data/spec/metric_fu/data_structures/line_numbers_spec.rb +63 -0
- data/spec/metric_fu/data_structures/location_spec.rb +110 -0
- data/spec/metric_fu/formatter/configuration_spec.rb +44 -0
- data/spec/metric_fu/formatter/html_spec.rb +138 -0
- data/spec/metric_fu/formatter/yaml_spec.rb +61 -0
- data/spec/metric_fu/formatter_spec.rb +49 -0
- data/spec/metric_fu/gem_version_spec.rb +12 -0
- data/spec/metric_fu/generator_spec.rb +130 -0
- data/spec/metric_fu/loader_spec.rb +13 -0
- data/spec/metric_fu/metric_spec.rb +46 -0
- data/spec/metric_fu/metrics/cane/configuration_spec.rb +22 -0
- data/spec/metric_fu/metrics/cane/generator_spec.rb +184 -0
- data/spec/metric_fu/metrics/churn/configuration_spec.rb +13 -0
- data/spec/metric_fu/metrics/churn/generator_spec.rb +64 -0
- data/spec/metric_fu/metrics/flay/configuration_spec.rb +13 -0
- data/spec/metric_fu/metrics/flay/generator_spec.rb +105 -0
- data/spec/metric_fu/metrics/flay/grapher_spec.rb +57 -0
- data/spec/metric_fu/metrics/flog/configuration_spec.rb +18 -0
- data/spec/metric_fu/metrics/flog/generator_spec.rb +77 -0
- data/spec/metric_fu/metrics/flog/grapher_spec.rb +107 -0
- data/spec/metric_fu/metrics/hotspots/analysis/analyzed_problems_spec.rb +104 -0
- data/spec/metric_fu/metrics/hotspots/analysis/analyzer_tables_spec.rb +71 -0
- data/spec/metric_fu/metrics/hotspots/analysis/ranking_spec.rb +30 -0
- data/spec/metric_fu/metrics/hotspots/analysis/rankings_spec.rb +97 -0
- data/spec/metric_fu/metrics/hotspots/analysis/table_spec.rb +6 -0
- data/spec/metric_fu/metrics/hotspots/generator_spec.rb +46 -0
- data/spec/metric_fu/metrics/hotspots/hotspot_analyzer_spec.rb +10 -0
- data/spec/metric_fu/metrics/hotspots/hotspot_spec.rb +16 -0
- data/spec/metric_fu/metrics/rails_best_practices/configuration_spec.rb +55 -0
- data/spec/metric_fu/metrics/rails_best_practices/generator_spec.rb +33 -0
- data/spec/metric_fu/metrics/rails_best_practices/grapher_spec.rb +62 -0
- data/spec/metric_fu/metrics/rcov/configuration_spec.rb +28 -0
- data/spec/metric_fu/metrics/rcov/generator_spec.rb +22 -0
- data/spec/metric_fu/metrics/rcov/grapher_spec.rb +57 -0
- data/spec/metric_fu/metrics/rcov/hotspot_spec.rb +20 -0
- data/spec/metric_fu/metrics/rcov/rcov_line_spec.rb +89 -0
- data/spec/metric_fu/metrics/rcov/simplecov_formatter_spec.rb +67 -0
- data/spec/metric_fu/metrics/reek/configuration_spec.rb +13 -0
- data/spec/metric_fu/metrics/reek/generator_spec.rb +203 -0
- data/spec/metric_fu/metrics/reek/grapher_spec.rb +66 -0
- data/spec/metric_fu/metrics/roodi/configuration_spec.rb +14 -0
- data/spec/metric_fu/metrics/roodi/generator_spec.rb +82 -0
- data/spec/metric_fu/metrics/roodi/grapher_spec.rb +57 -0
- data/spec/metric_fu/metrics/saikuro/configuration_spec.rb +25 -0
- data/spec/metric_fu/metrics/saikuro/generator_spec.rb +71 -0
- data/spec/metric_fu/metrics/stats/generator_spec.rb +96 -0
- data/spec/metric_fu/metrics/stats/grapher_spec.rb +69 -0
- data/spec/metric_fu/reporter_spec.rb +41 -0
- data/spec/metric_fu/reporting/graphs/graph_spec.rb +44 -0
- data/spec/metric_fu/reporting/graphs/grapher_spec.rb +24 -0
- data/spec/metric_fu/reporting/result_spec.rb +50 -0
- data/spec/metric_fu/run_spec.rb +197 -0
- data/spec/metric_fu/templates/configuration_spec.rb +51 -0
- data/spec/metric_fu/templates/metrics_template_spec.rb +11 -0
- data/spec/metric_fu/templates/report_spec.rb +15 -0
- data/spec/metric_fu/templates/template_spec.rb +233 -0
- data/spec/metric_fu/utility_spec.rb +12 -0
- data/spec/metric_fu_spec.rb +52 -0
- data/spec/quality_spec.rb +114 -0
- data/spec/shared/configured.rb +45 -0
- data/spec/shared/test_coverage.rb +95 -0
- data/spec/spec_helper.rb +46 -0
- data/spec/support/.metrics +4 -0
- data/spec/support/deferred_garbaged_collection.rb +33 -0
- data/spec/support/helper_methods.rb +32 -0
- data/spec/support/matcher_create_file.rb +37 -0
- data/spec/support/matcher_create_files.rb +43 -0
- data/spec/support/samples/reek/alfa.rb +1 -0
- data/spec/support/suite.rb +26 -0
- data/spec/support/test_fixtures.rb +37 -0
- data/spec/support/timeout.rb +7 -0
- data/spec/support/usage_test.rb +150 -0
- data/spec/usage_test_spec.rb +93 -0
- metadata +735 -0
@@ -0,0 +1,22 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
MetricFu.metrics_require { "rcov/generator" }
|
3
|
+
require "shared/test_coverage"
|
4
|
+
|
5
|
+
describe MetricFu::RcovGenerator, "configured as rcov" do
|
6
|
+
it_behaves_like "rcov test coverage generator", :rcov do
|
7
|
+
describe "emit" do
|
8
|
+
before :each do
|
9
|
+
options = { external: nil }
|
10
|
+
@test_coverage = MetricFu::RcovGenerator.new(@default_options.merge(options))
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should set the RAILS_ENV" do
|
14
|
+
expect(MetricFu::Utility).to receive(:rm_rf).with(MetricFu::RcovGenerator.metric_directory, verbose: false)
|
15
|
+
expect(MetricFu::Utility).to receive(:mkdir_p).with(MetricFu::RcovGenerator.metric_directory)
|
16
|
+
options = { environment: "metrics", external: nil }
|
17
|
+
@test_coverage = MetricFu::RcovGenerator.new(@default_options.merge(options))
|
18
|
+
expect(@test_coverage.command).to include("RAILS_ENV=metrics")
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
MetricFu.metrics_require { "rcov/grapher" }
|
3
|
+
|
4
|
+
describe RcovGrapher do
|
5
|
+
before :each do
|
6
|
+
@rcov_grapher = MetricFu::RcovGrapher.new
|
7
|
+
MetricFu.configuration
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should respond to rcov_percent and labels" do
|
11
|
+
expect(@rcov_grapher).to respond_to(:rcov_percent)
|
12
|
+
expect(@rcov_grapher).to respond_to(:labels)
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "responding to #initialize" do
|
16
|
+
it "should initialise rcov_percent and labels" do
|
17
|
+
expect(@rcov_grapher.rcov_percent).to eq([])
|
18
|
+
expect(@rcov_grapher.labels).to eq({})
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "responding to #get_metrics" do
|
23
|
+
context "when metrics were not generated" do
|
24
|
+
before(:each) do
|
25
|
+
@metrics = FIXTURE.load_metric("metric_missing.yml")
|
26
|
+
@date = "1/2"
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should not push to rcov_percent" do
|
30
|
+
expect(@rcov_grapher.rcov_percent).not_to receive(:push)
|
31
|
+
@rcov_grapher.get_metrics(@metrics, @date)
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should not update labels with the date" do
|
35
|
+
expect(@rcov_grapher.labels).not_to receive(:update)
|
36
|
+
@rcov_grapher.get_metrics(@metrics, @date)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
context "when metrics have been generated" do
|
41
|
+
before(:each) do
|
42
|
+
@metrics = FIXTURE.load_metric("20090630.yml")
|
43
|
+
@date = "1/2"
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should push to rcov_percent" do
|
47
|
+
expect(@rcov_grapher.rcov_percent).to receive(:push).with(49.6)
|
48
|
+
@rcov_grapher.get_metrics(@metrics, @date)
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should update labels with the date" do
|
52
|
+
expect(@rcov_grapher.labels).to receive(:update).with(0 => "1/2")
|
53
|
+
@rcov_grapher.get_metrics(@metrics, @date)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
MetricFu.metrics_require { "hotspots/metric" }
|
3
|
+
MetricFu.metrics_require { "hotspots/hotspot" }
|
4
|
+
MetricFu.metrics_require { "hotspots/analysis/record" }
|
5
|
+
MetricFu.metrics_require { "rcov/hotspot" }
|
6
|
+
|
7
|
+
describe MetricFu::RcovHotspot do
|
8
|
+
describe "map" do
|
9
|
+
let(:zero_row) do
|
10
|
+
MetricFu::Record.new({ "percentage_uncovered" => 0.0 }, nil)
|
11
|
+
end
|
12
|
+
|
13
|
+
let(:non_zero_row) do
|
14
|
+
MetricFu::Record.new({ "percentage_uncovered" => 0.75 }, nil)
|
15
|
+
end
|
16
|
+
|
17
|
+
it { expect(subject.map(zero_row)).to eql(0.0) }
|
18
|
+
it { expect(subject.map(non_zero_row)).to eql(0.75) }
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "metric_fu/metrics/rcov/rcov_line"
|
3
|
+
|
4
|
+
describe MetricFu::RCovLine do
|
5
|
+
describe "#to_h" do
|
6
|
+
it "returns a hash with the content and was_run" do
|
7
|
+
rcov_line = RCovLine.new("some content", 1)
|
8
|
+
|
9
|
+
expect(rcov_line.to_h).to eq(content: "some content", was_run: 1)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "#covered?" do
|
14
|
+
it "returns true if was_run is 1" do
|
15
|
+
rcov_line = RCovLine.new("", 1)
|
16
|
+
|
17
|
+
expect(rcov_line.covered?).to eq(true)
|
18
|
+
end
|
19
|
+
|
20
|
+
it "returns false if was_run is 0" do
|
21
|
+
rcov_line = RCovLine.new("", 0)
|
22
|
+
|
23
|
+
expect(rcov_line.covered?).to eq(false)
|
24
|
+
end
|
25
|
+
|
26
|
+
it "returns false if was_run is nil" do
|
27
|
+
rcov_line = RCovLine.new("", nil)
|
28
|
+
|
29
|
+
expect(rcov_line.covered?).to eq(false)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe "#missed?" do
|
34
|
+
it "returns true if was_run is 0" do
|
35
|
+
rcov_line = RCovLine.new("", 0)
|
36
|
+
|
37
|
+
expect(rcov_line.missed?).to eq(true)
|
38
|
+
end
|
39
|
+
|
40
|
+
it "returns false if was_run is 1" do
|
41
|
+
rcov_line = RCovLine.new("", 1)
|
42
|
+
|
43
|
+
expect(rcov_line.missed?).to eq(false)
|
44
|
+
end
|
45
|
+
|
46
|
+
it "returns false if was_run is nil" do
|
47
|
+
rcov_line = RCovLine.new("", nil)
|
48
|
+
|
49
|
+
expect(rcov_line.missed?).to eq(false)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
describe "#ignored?" do
|
54
|
+
it "returns true if was_run is nil" do
|
55
|
+
rcov_line = RCovLine.new("", nil)
|
56
|
+
|
57
|
+
expect(rcov_line.ignored?).to eq(true)
|
58
|
+
end
|
59
|
+
|
60
|
+
it "returns false if was_run is 1" do
|
61
|
+
rcov_line = RCovLine.new("", 1)
|
62
|
+
|
63
|
+
expect(rcov_line.ignored?).to eq(false)
|
64
|
+
end
|
65
|
+
|
66
|
+
it "returns false if was_run is 0" do
|
67
|
+
rcov_line = RCovLine.new("", 0)
|
68
|
+
|
69
|
+
expect(rcov_line.ignored?).to eq(false)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
describe "#css_class" do
|
74
|
+
it "returns 'rcov_run' for an ignored line" do
|
75
|
+
rcov_line = RCovLine.new("", nil)
|
76
|
+
expect(rcov_line.css_class).to eq("rcov_run")
|
77
|
+
end
|
78
|
+
|
79
|
+
it "returns 'rcov_not_run' for a missed line" do
|
80
|
+
rcov_line = RCovLine.new("", 0)
|
81
|
+
expect(rcov_line.css_class).to eq("rcov_not_run")
|
82
|
+
end
|
83
|
+
|
84
|
+
it "returns 'rcov_run' for a covered line" do
|
85
|
+
rcov_line = RCovLine.new("", 1)
|
86
|
+
expect(rcov_line.css_class).to eq("rcov_run")
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "simplecov"
|
3
|
+
require "metric_fu/metrics/rcov/simplecov_formatter"
|
4
|
+
require "metric_fu/metrics/rcov/generator"
|
5
|
+
|
6
|
+
describe SimpleCov::Formatter::MetricFu do
|
7
|
+
before do
|
8
|
+
@rcov_file = subject.coverage_file_path
|
9
|
+
File.delete(@rcov_file) if File.exists?(@rcov_file)
|
10
|
+
|
11
|
+
@result = SimpleCov::Result.new(
|
12
|
+
|
13
|
+
FIXTURE.fixtures_path.join("coverage.rb").expand_path.to_s =>
|
14
|
+
[1, 1, 1, 1, nil, 1, 0, 1, 1, nil, 0, 1, 1]
|
15
|
+
|
16
|
+
)
|
17
|
+
end
|
18
|
+
|
19
|
+
it "test_format" do
|
20
|
+
SimpleCov::Formatter::MetricFu.new.format(@result)
|
21
|
+
|
22
|
+
expect(File.exists?(@rcov_file)).to be_truthy
|
23
|
+
end
|
24
|
+
|
25
|
+
if SimpleCov.running
|
26
|
+
MetricFu.logger.info "Skipping specs while SimpleCov is running"
|
27
|
+
else
|
28
|
+
it "test_create_content" do
|
29
|
+
content = SimpleCov::Formatter::MetricFu::FormatLikeRCov.new(@result).format
|
30
|
+
test = "\=" * 80
|
31
|
+
|
32
|
+
expect(content).to match(/#{test}/)
|
33
|
+
expect(content).to match(/!! value \* value/)
|
34
|
+
end
|
35
|
+
|
36
|
+
if defined?(JRUBY_VERSION)
|
37
|
+
STDOUT.puts "Skipping spec 'cause JRuby doesn't do Coverage right"
|
38
|
+
else
|
39
|
+
it "calculates the same coverage from an RCov report as from SimpleCov" do
|
40
|
+
SimpleCov.start # start coverage
|
41
|
+
require "fixtures/coverage-153"
|
42
|
+
result = SimpleCov.result # end coverage
|
43
|
+
source_file = result.source_files.first
|
44
|
+
|
45
|
+
# formatter ouputs this from simplecov result
|
46
|
+
rcov_text = SimpleCov::Formatter::MetricFu::FormatLikeRCov.new(result).format
|
47
|
+
|
48
|
+
# generator analyzes the rcov text
|
49
|
+
analyzed_rcov_text = MetricFu::RCovFormatCoverage.new(rcov_text).to_h
|
50
|
+
# [:lines, :percent_run, :methods]
|
51
|
+
covered_lines_from_rcov_text = analyzed_rcov_text["./spec/fixtures/coverage-153.rb"][:lines]
|
52
|
+
# https://github.com/colszowka/simplecov/blob/master/lib/simplecov/source_file.rb
|
53
|
+
expect(source_file.coverage.count).to eq(covered_lines_from_rcov_text.count)
|
54
|
+
|
55
|
+
line_coverage_from_rcov_text = covered_lines_from_rcov_text.map { |line| line[:was_run] }
|
56
|
+
expect(source_file.coverage).to eq(line_coverage_from_rcov_text)
|
57
|
+
|
58
|
+
expect(source_file.covered_percent).to eq(MetricFu::RCovFormatCoverage::TestCoverage.percent_run(covered_lines_from_rcov_text))
|
59
|
+
|
60
|
+
source_file.lines.each_with_index do |line, index|
|
61
|
+
expect(line.coverage).to eq(line_coverage_from_rcov_text[index])
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "shared/configured"
|
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"
|
8
|
+
expect(MetricFu::Metric.get_metric(:reek).run_options).to eq(
|
9
|
+
config_file_pattern: nil, dirs_to_reek: ["lib"]
|
10
|
+
)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,203 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
MetricFu.metrics_require { "reek/generator" }
|
4
|
+
|
5
|
+
describe MetricFu::ReekGenerator do
|
6
|
+
describe "emit" do
|
7
|
+
let(:options) { { dirs_to_reek: [] } }
|
8
|
+
let(:files_to_analyze) { ["lib/foo.rb", "lib/bar.rb"] }
|
9
|
+
let(:reek) { MetricFu::ReekGenerator.new(options) }
|
10
|
+
|
11
|
+
before(:each) do
|
12
|
+
allow(reek).to receive(:files_to_analyze).and_return(files_to_analyze)
|
13
|
+
end
|
14
|
+
|
15
|
+
it "includes config file pattern into reek parameters when specified" do
|
16
|
+
options.merge!(config_file_pattern: "lib/config/*.reek")
|
17
|
+
|
18
|
+
expect(reek).to receive(:run!) do |_files, config_files|
|
19
|
+
expect(config_files).to eq(["lib/config/*.reek"])
|
20
|
+
end.and_return("")
|
21
|
+
|
22
|
+
reek.emit
|
23
|
+
end
|
24
|
+
|
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
|
+
|
30
|
+
reek.emit
|
31
|
+
end
|
32
|
+
|
33
|
+
it "includes files to analyze into reek parameters" do
|
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
|
+
|
38
|
+
reek.emit
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe "analyze method" do
|
43
|
+
before :each do
|
44
|
+
MetricFu::Configuration.run {}
|
45
|
+
allow(File).to receive(:directory?).and_return(true)
|
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
|
52
|
+
end
|
53
|
+
|
54
|
+
context "with reek warnings" do
|
55
|
+
before :each do
|
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])
|
113
|
+
end
|
114
|
+
|
115
|
+
it "should find the code smell's method name" do
|
116
|
+
smell = @matches.first[:code_smells].first
|
117
|
+
expect(smell[:method]).to eq("ActivityReportsController#authorize_user")
|
118
|
+
end
|
119
|
+
|
120
|
+
it "should find the code smell's type" do
|
121
|
+
smell = @matches[1][:code_smells].first
|
122
|
+
expect(smell[:type]).to eq("Nested Iterators")
|
123
|
+
end
|
124
|
+
|
125
|
+
it "should find the code smell's message" do
|
126
|
+
smell = @matches[1][:code_smells].first
|
127
|
+
expect(smell[:message]).to eq("is nested")
|
128
|
+
end
|
129
|
+
|
130
|
+
it "should find the code smell's type" do
|
131
|
+
smell = @matches.first
|
132
|
+
expect(smell[:file_path]).to eq("app/controllers/activity_reports_controller.rb")
|
133
|
+
end
|
134
|
+
|
135
|
+
it "should NOT insert nil smells into the array when there's a newline in the method call" do
|
136
|
+
expect(@matches.last[:code_smells]).to eq(@matches.last[:code_smells].compact)
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
context "with reek 1.3 output" do
|
141
|
+
before :each do
|
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
|
154
|
+
end
|
155
|
+
|
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')
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
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
|
176
|
+
|
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
|
181
|
+
|
182
|
+
@matches = @generator.analyze
|
183
|
+
|
184
|
+
expect(@matches.first).to eq(result)
|
185
|
+
end
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
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
|
201
|
+
end
|
202
|
+
end
|
203
|
+
end
|