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.
- checksums.yaml +5 -13
- data/.gitignore +6 -0
- data/.rubocop.yml +15 -0
- data/.rubocop_todo.yml +69 -0
- data/.simplecov +35 -3
- data/.travis.yml +6 -10
- data/CONTRIBUTORS +12 -11
- data/Gemfile +48 -29
- data/Guardfile +9 -9
- data/HISTORY.md +47 -1
- data/README.md +70 -57
- data/Rakefile +1 -15
- data/appveyor.yml +34 -0
- data/certs/bf4.pem +20 -20
- 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.13.0.gem.sha512 +1 -0
- data/config/rubocop.yml +269 -0
- data/gem_tasks/build.rake +1 -0
- data/gem_tasks/rubocop.rake +10 -0
- data/gem_tasks/yard.rake +24 -0
- data/lib/metric_fu.rb +20 -9
- data/lib/metric_fu/calculate.rb +0 -1
- data/lib/metric_fu/cli/client.rb +6 -6
- data/lib/metric_fu/cli/helper.rb +22 -13
- data/lib/metric_fu/cli/parser.rb +14 -18
- data/lib/metric_fu/configuration.rb +7 -11
- data/lib/metric_fu/constantize.rb +4 -4
- data/lib/metric_fu/data_structures/line_numbers.rb +10 -11
- data/lib/metric_fu/data_structures/location.rb +12 -14
- data/lib/metric_fu/data_structures/sexp_node.rb +31 -13
- data/lib/metric_fu/environment.rb +29 -31
- data/lib/metric_fu/formatter.rb +4 -6
- data/lib/metric_fu/formatter/html.rb +13 -13
- data/lib/metric_fu/formatter/syntax.rb +5 -7
- data/lib/metric_fu/formatter/yaml.rb +1 -1
- data/lib/metric_fu/gem_run.rb +13 -15
- data/lib/metric_fu/gem_version.rb +10 -12
- data/lib/metric_fu/generator.rb +6 -9
- data/lib/metric_fu/io.rb +13 -15
- data/lib/metric_fu/loader.rb +17 -18
- data/lib/metric_fu/logger.rb +15 -18
- data/lib/metric_fu/logging/mf_debugger.rb +4 -4
- data/lib/metric_fu/metric.rb +11 -12
- data/lib/metric_fu/metrics/cane/generator.rb +10 -9
- data/lib/metric_fu/metrics/cane/grapher.rb +5 -7
- data/lib/metric_fu/metrics/cane/metric.rb +6 -8
- data/lib/metric_fu/metrics/cane/report.html.erb +3 -3
- data/lib/metric_fu/metrics/cane/violations.rb +6 -6
- data/lib/metric_fu/metrics/churn/generator.rb +2 -6
- data/lib/metric_fu/metrics/churn/hotspot.rb +1 -3
- data/lib/metric_fu/metrics/churn/metric.rb +5 -7
- data/lib/metric_fu/metrics/flay/generator.rb +7 -11
- data/lib/metric_fu/metrics/flay/grapher.rb +5 -6
- data/lib/metric_fu/metrics/flay/hotspot.rb +5 -7
- data/lib/metric_fu/metrics/flay/metric.rb +5 -7
- data/lib/metric_fu/metrics/flog/generator.rb +35 -24
- data/lib/metric_fu/metrics/flog/grapher.rb +11 -11
- data/lib/metric_fu/metrics/flog/hotspot.rb +3 -5
- data/lib/metric_fu/metrics/flog/metric.rb +3 -5
- data/lib/metric_fu/metrics/hotspots/analysis/analyzed_problems.rb +0 -1
- data/lib/metric_fu/metrics/hotspots/analysis/analyzer_tables.rb +19 -18
- data/lib/metric_fu/metrics/hotspots/analysis/grouping.rb +0 -2
- data/lib/metric_fu/metrics/hotspots/analysis/groupings.rb +1 -3
- data/lib/metric_fu/metrics/hotspots/analysis/problems.rb +4 -6
- data/lib/metric_fu/metrics/hotspots/analysis/ranked_problem_location.rb +14 -17
- data/lib/metric_fu/metrics/hotspots/analysis/ranking.rb +4 -5
- data/lib/metric_fu/metrics/hotspots/analysis/rankings.rb +1 -3
- data/lib/metric_fu/metrics/hotspots/analysis/record.rb +3 -5
- data/lib/metric_fu/metrics/hotspots/analysis/scoring_strategies.rb +0 -2
- data/lib/metric_fu/metrics/hotspots/analysis/table.rb +3 -4
- data/lib/metric_fu/metrics/hotspots/generator.rb +3 -6
- data/lib/metric_fu/metrics/hotspots/hotspot.rb +13 -13
- data/lib/metric_fu/metrics/hotspots/hotspot_analyzer.rb +5 -8
- data/lib/metric_fu/metrics/hotspots/metric.rb +1 -3
- data/lib/metric_fu/metrics/hotspots/report.html.erb +1 -1
- data/lib/metric_fu/metrics/rails_best_practices/generator.rb +14 -12
- data/lib/metric_fu/metrics/rails_best_practices/grapher.rb +5 -6
- data/lib/metric_fu/metrics/rails_best_practices/metric.rb +5 -4
- data/lib/metric_fu/metrics/rcov/external_client.rb +1 -3
- data/lib/metric_fu/metrics/rcov/generator.rb +13 -15
- data/lib/metric_fu/metrics/rcov/grapher.rb +6 -7
- data/lib/metric_fu/metrics/rcov/hotspot.rb +5 -7
- data/lib/metric_fu/metrics/rcov/metric.rb +5 -7
- data/lib/metric_fu/metrics/rcov/rcov_format_coverage.rb +16 -55
- data/lib/metric_fu/metrics/rcov/rcov_line.rb +48 -0
- data/lib/metric_fu/metrics/rcov/report.html.erb +2 -2
- data/lib/metric_fu/metrics/rcov/simplecov_formatter.rb +10 -11
- data/lib/metric_fu/metrics/reek/generator.rb +36 -82
- data/lib/metric_fu/metrics/reek/grapher.rb +5 -6
- data/lib/metric_fu/metrics/reek/hotspot.rb +5 -7
- data/lib/metric_fu/metrics/reek/metric.rb +2 -4
- data/lib/metric_fu/metrics/roodi/generator.rb +9 -10
- data/lib/metric_fu/metrics/roodi/grapher.rb +5 -6
- data/lib/metric_fu/metrics/roodi/hotspot.rb +1 -3
- data/lib/metric_fu/metrics/roodi/metric.rb +2 -4
- data/lib/metric_fu/metrics/saikuro/generator.rb +23 -27
- data/lib/metric_fu/metrics/saikuro/hotspot.rb +1 -3
- data/lib/metric_fu/metrics/saikuro/metric.rb +7 -8
- data/lib/metric_fu/metrics/saikuro/parsing_element.rb +6 -8
- data/lib/metric_fu/metrics/saikuro/report.html.erb +1 -1
- data/lib/metric_fu/metrics/saikuro/scratch_file.rb +24 -29
- data/lib/metric_fu/metrics/stats/generator.rb +9 -12
- data/lib/metric_fu/metrics/stats/grapher.rb +8 -9
- data/lib/metric_fu/metrics/stats/hotspot.rb +1 -3
- data/lib/metric_fu/metrics/stats/metric.rb +3 -5
- data/lib/metric_fu/reporter.rb +1 -1
- data/lib/metric_fu/reporting/graphs/graph.rb +8 -12
- data/lib/metric_fu/reporting/graphs/grapher.rb +7 -9
- data/lib/metric_fu/reporting/result.rb +0 -3
- data/lib/metric_fu/run.rb +12 -3
- data/lib/metric_fu/tasks/metric_fu.rake +8 -8
- data/lib/metric_fu/templates/configuration.rb +2 -5
- data/lib/metric_fu/templates/metrics_template.rb +45 -32
- data/lib/metric_fu/templates/report.rb +5 -8
- data/lib/metric_fu/templates/template.rb +20 -24
- data/lib/metric_fu/utility.rb +15 -8
- data/lib/metric_fu/version.rb +7 -1
- data/metric_fu.gemspec +29 -32
- data/spec/capture_warnings.rb +29 -22
- data/spec/cli/helper_spec.rb +9 -16
- data/spec/dummy/lib/bad_encoding.rb +1 -1
- data/spec/fixtures/coverage-153.rb +2 -2
- data/spec/fixtures/coverage.rb +2 -2
- data/spec/metric_fu/calculate_spec.rb +3 -3
- data/spec/metric_fu/configuration_spec.rb +71 -83
- data/spec/metric_fu/data_structures/line_numbers_spec.rb +3 -5
- data/spec/metric_fu/data_structures/location_spec.rb +13 -31
- data/spec/metric_fu/formatter/configuration_spec.rb +18 -20
- data/spec/metric_fu/formatter/html_spec.rb +21 -28
- data/spec/metric_fu/formatter/yaml_spec.rb +9 -17
- data/spec/metric_fu/formatter_spec.rb +16 -16
- data/spec/metric_fu/gem_version_spec.rb +4 -6
- data/spec/metric_fu/generator_spec.rb +33 -43
- data/spec/metric_fu/loader_spec.rb +5 -4
- data/spec/metric_fu/metric_spec.rb +21 -25
- data/spec/metric_fu/metrics/cane/configuration_spec.rb +14 -14
- data/spec/metric_fu/metrics/cane/generator_spec.rb +26 -29
- data/spec/metric_fu/metrics/churn/configuration_spec.rb +7 -9
- data/spec/metric_fu/metrics/churn/generator_spec.rb +6 -11
- data/spec/metric_fu/metrics/flay/configuration_spec.rb +7 -9
- data/spec/metric_fu/metrics/flay/generator_spec.rb +36 -37
- data/spec/metric_fu/metrics/flay/grapher_spec.rb +2 -2
- data/spec/metric_fu/metrics/flog/configuration_spec.rb +12 -14
- data/spec/metric_fu/metrics/flog/generator_spec.rb +31 -32
- data/spec/metric_fu/metrics/flog/grapher_spec.rb +8 -10
- data/spec/metric_fu/metrics/hotspots/analysis/analyzed_problems_spec.rb +18 -24
- data/spec/metric_fu/metrics/hotspots/analysis/analyzer_tables_spec.rb +12 -17
- data/spec/metric_fu/metrics/hotspots/analysis/ranking_spec.rb +2 -6
- data/spec/metric_fu/metrics/hotspots/analysis/rankings_spec.rb +5 -14
- data/spec/metric_fu/metrics/hotspots/analysis/table_spec.rb +1 -3
- data/spec/metric_fu/metrics/hotspots/generator_spec.rb +6 -8
- data/spec/metric_fu/metrics/hotspots/hotspot_analyzer_spec.rb +1 -3
- data/spec/metric_fu/metrics/hotspots/hotspot_spec.rb +4 -5
- data/spec/metric_fu/metrics/rails_best_practices/configuration_spec.rb +25 -17
- data/spec/metric_fu/metrics/rails_best_practices/generator_spec.rb +2 -3
- data/spec/metric_fu/metrics/rails_best_practices/grapher_spec.rb +3 -3
- data/spec/metric_fu/metrics/rcov/configuration_spec.rb +21 -23
- data/spec/metric_fu/metrics/rcov/generator_spec.rb +6 -10
- data/spec/metric_fu/metrics/rcov/grapher_spec.rb +2 -2
- data/spec/metric_fu/metrics/rcov/hotspot_spec.rb +8 -8
- data/spec/metric_fu/metrics/rcov/rcov_line_spec.rb +89 -0
- data/spec/metric_fu/metrics/rcov/simplecov_formatter_spec.rb +31 -33
- data/spec/metric_fu/metrics/reek/configuration_spec.rb +7 -7
- data/spec/metric_fu/metrics/reek/generator_spec.rb +131 -111
- data/spec/metric_fu/metrics/reek/grapher_spec.rb +4 -4
- data/spec/metric_fu/metrics/roodi/configuration_spec.rb +8 -10
- data/spec/metric_fu/metrics/roodi/generator_spec.rb +3 -3
- data/spec/metric_fu/metrics/roodi/grapher_spec.rb +2 -2
- data/spec/metric_fu/metrics/saikuro/configuration_spec.rb +22 -23
- data/spec/metric_fu/metrics/saikuro/generator_spec.rb +7 -7
- data/spec/metric_fu/metrics/stats/generator_spec.rb +10 -10
- data/spec/metric_fu/metrics/stats/grapher_spec.rb +2 -2
- data/spec/metric_fu/reporter_spec.rb +8 -9
- data/spec/metric_fu/reporting/graphs/graph_spec.rb +1 -4
- data/spec/metric_fu/reporting/graphs/grapher_spec.rb +5 -5
- data/spec/metric_fu/reporting/result_spec.rb +12 -14
- data/spec/metric_fu/run_spec.rb +19 -33
- data/spec/metric_fu/templates/configuration_spec.rb +34 -40
- data/spec/metric_fu/templates/metrics_template_spec.rb +11 -0
- data/spec/metric_fu/templates/report_spec.rb +4 -4
- data/spec/metric_fu/templates/template_spec.rb +78 -64
- data/spec/metric_fu/utility_spec.rb +3 -3
- data/spec/metric_fu_spec.rb +23 -6
- data/spec/quality_spec.rb +43 -15
- data/spec/shared/configured.rb +9 -11
- data/spec/shared/test_coverage.rb +5 -9
- data/spec/spec_helper.rb +13 -31
- data/spec/{dummy → support}/.metrics +0 -0
- data/spec/support/deferred_garbaged_collection.rb +1 -2
- data/spec/support/matcher_create_file.rb +6 -4
- data/spec/support/matcher_create_files.rb +6 -4
- data/spec/support/samples/reek/alfa.rb +1 -0
- data/spec/support/suite.rb +3 -3
- data/spec/support/test_fixtures.rb +5 -7
- data/spec/support/timeout.rb +1 -1
- data/spec/support/usage_test.rb +24 -25
- data/spec/usage_test_spec.rb +30 -32
- metadata +104 -103
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/gemfiles/Gemfile.travis +0 -10
- metadata.gz.sig +0 -0
@@ -1,12 +1,13 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe MetricFu do
|
4
|
-
|
5
4
|
it "loads the .metrics file" do
|
6
5
|
# Global only for testing that this file gets loaded
|
7
6
|
$metric_file_loaded = false
|
8
|
-
MetricFu.
|
7
|
+
MetricFu.with_run_dir "spec/support" do
|
8
|
+
MetricFu.loader.load_user_configuration
|
9
|
+
end
|
10
|
+
|
9
11
|
expect($metric_file_loaded).to be_truthy
|
10
12
|
end
|
11
|
-
|
12
13
|
end
|
@@ -1,47 +1,43 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe MetricFu::Metric do
|
4
4
|
before do
|
5
5
|
@metric = MetricFu::Metric.get_metric(:flog)
|
6
|
-
|
6
|
+
# @original_options = @metric.run_options.dup
|
7
7
|
end
|
8
8
|
|
9
|
-
#it
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
#end
|
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
15
|
|
16
|
-
#it
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
#end
|
21
|
-
|
22
|
-
context 'given a valid configurable option' do
|
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
|
23
21
|
|
22
|
+
context "given a valid configurable option" do
|
24
23
|
before do
|
25
|
-
allow(@metric).to receive(:default_run_options).and_return(
|
24
|
+
allow(@metric).to receive(:default_run_options).and_return(foo: "baz")
|
26
25
|
end
|
27
26
|
|
28
|
-
it
|
29
|
-
@metric.foo =
|
30
|
-
expect(@metric.run_options[:foo]).to eq(
|
27
|
+
it "can be configured as an attribute" do
|
28
|
+
@metric.foo = "qux"
|
29
|
+
expect(@metric.run_options[:foo]).to eq("qux")
|
31
30
|
end
|
32
|
-
|
33
31
|
end
|
34
32
|
|
35
|
-
context
|
36
|
-
|
33
|
+
context "given an invalid configurable option" do
|
37
34
|
before do
|
38
35
|
allow(@metric).to receive(:default_run_options).and_return({})
|
39
36
|
end
|
40
37
|
|
41
|
-
it
|
42
|
-
expect { @metric.foo =
|
38
|
+
it "raises an error" do
|
39
|
+
expect { @metric.foo = "bar" }.to raise_error(RuntimeError, /not a valid configuration option/)
|
43
40
|
end
|
44
|
-
|
45
41
|
end
|
46
42
|
|
47
43
|
after do
|
@@ -1,20 +1,20 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "spec_helper"
|
2
|
+
require "shared/configured"
|
3
3
|
|
4
|
-
describe MetricFu::Configuration,
|
5
|
-
it_behaves_like
|
4
|
+
describe MetricFu::Configuration, "for cane" do
|
5
|
+
it_behaves_like "configured" do
|
6
6
|
if MetricFu.configuration.mri?
|
7
|
-
it
|
8
|
-
|
9
|
-
load_metric
|
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
10
|
expect(MetricFu::Metric.get_metric(:cane).run_options).to eq(
|
11
|
-
|
12
|
-
:
|
13
|
-
:
|
14
|
-
:
|
15
|
-
:
|
16
|
-
:
|
17
|
-
:
|
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
18
|
)
|
19
19
|
end
|
20
20
|
end
|
@@ -1,9 +1,8 @@
|
|
1
|
-
require
|
2
|
-
MetricFu.metrics_require {
|
1
|
+
require "spec_helper"
|
2
|
+
MetricFu.metrics_require { "cane/generator" }
|
3
3
|
|
4
4
|
describe CaneGenerator do
|
5
5
|
describe "emit method" do
|
6
|
-
|
7
6
|
it "should execute cane command" do
|
8
7
|
options = {}
|
9
8
|
@cane = MetricFu::CaneGenerator.new(options)
|
@@ -12,42 +11,42 @@ describe CaneGenerator do
|
|
12
11
|
end
|
13
12
|
|
14
13
|
it "should use abc max option" do
|
15
|
-
options = {abc_max: 20}
|
14
|
+
options = { abc_max: 20 }
|
16
15
|
@cane = MetricFu::CaneGenerator.new(options)
|
17
16
|
expect(@cane).to receive(:run!).with(" --abc-max 20")
|
18
17
|
output = @cane.emit
|
19
18
|
end
|
20
19
|
|
21
20
|
it "should use style max line length option" do
|
22
|
-
options = {line_length: 100}
|
21
|
+
options = { line_length: 100 }
|
23
22
|
@cane = MetricFu::CaneGenerator.new(options)
|
24
23
|
expect(@cane).to receive(:run!).with(" --style-measure 100")
|
25
24
|
output = @cane.emit
|
26
25
|
end
|
27
26
|
|
28
27
|
it "should use no-doc if specified" do
|
29
|
-
options = {no_doc:
|
28
|
+
options = { no_doc: "y" }
|
30
29
|
@cane = MetricFu::CaneGenerator.new(options)
|
31
30
|
expect(@cane).to receive(:run!).with(" --no-doc")
|
32
31
|
output = @cane.emit
|
33
32
|
end
|
34
33
|
|
35
34
|
it "should include doc violations if no_doc != 'y'" do
|
36
|
-
options = {no_doc:
|
35
|
+
options = { no_doc: "n" }
|
37
36
|
@cane = MetricFu::CaneGenerator.new(options)
|
38
37
|
expect(@cane).to receive(:run!).with("")
|
39
38
|
output = @cane.emit
|
40
39
|
end
|
41
40
|
|
42
41
|
it "should use no-readme if specified" do
|
43
|
-
options = {no_readme:
|
42
|
+
options = { no_readme: "y" }
|
44
43
|
@cane = MetricFu::CaneGenerator.new(options)
|
45
44
|
expect(@cane).to receive(:run!).with(" --no-readme")
|
46
45
|
output = @cane.emit
|
47
46
|
end
|
48
47
|
|
49
48
|
it "should include README violations if no_readme != 'y'" do
|
50
|
-
options = {no_readme:
|
49
|
+
options = { no_readme: "n" }
|
51
50
|
@cane = MetricFu::CaneGenerator.new(options)
|
52
51
|
expect(@cane).to receive(:run!).with("")
|
53
52
|
output = @cane.emit
|
@@ -60,11 +59,10 @@ describe CaneGenerator do
|
|
60
59
|
allow(File).to receive(:directory?).and_return(true)
|
61
60
|
options = {}
|
62
61
|
@cane = MetricFu::CaneGenerator.new(options)
|
63
|
-
@cane.instance_variable_set(:@output,
|
62
|
+
@cane.instance_variable_set(:@output, "")
|
64
63
|
end
|
65
64
|
|
66
65
|
describe "analyze method" do
|
67
|
-
|
68
66
|
it "should find total violations" do
|
69
67
|
@cane.analyze
|
70
68
|
expect(@cane.total_violations).to eq(0)
|
@@ -77,12 +75,11 @@ describe CaneGenerator do
|
|
77
75
|
lines = sample_cane_output
|
78
76
|
MetricFu::Configuration.run {}
|
79
77
|
allow(File).to receive(:directory?).and_return(true)
|
80
|
-
@cane = MetricFu::CaneGenerator.new(
|
78
|
+
@cane = MetricFu::CaneGenerator.new("base_dir")
|
81
79
|
@cane.instance_variable_set(:@output, lines)
|
82
80
|
end
|
83
81
|
|
84
82
|
describe "analyze method" do
|
85
|
-
|
86
83
|
it "should find total violations" do
|
87
84
|
@cane.analyze
|
88
85
|
expect(@cane.total_violations).to eq(6)
|
@@ -91,39 +88,39 @@ describe CaneGenerator do
|
|
91
88
|
it "should extract abc complexity violations" do
|
92
89
|
@cane.analyze
|
93
90
|
expect(@cane.violations[:abc_complexity]).to eq([
|
94
|
-
{file:
|
95
|
-
{file:
|
91
|
+
{ file: "lib/abc/foo.rb", method: "Abc::Foo#method", complexity: "11" },
|
92
|
+
{ file: "lib/abc/bar.rb", method: "Abc::Bar#method", complexity: "22" }
|
96
93
|
])
|
97
94
|
end
|
98
95
|
|
99
96
|
it "should extract line style violations" do
|
100
97
|
@cane.analyze
|
101
98
|
expect(@cane.violations[:line_style]).to eq([
|
102
|
-
{line:
|
103
|
-
{line:
|
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" }
|
104
101
|
])
|
105
102
|
end
|
106
103
|
|
107
104
|
it "should extract comment violations" do
|
108
105
|
@cane.analyze
|
109
106
|
expect(@cane.violations[:comment]).to eq([
|
110
|
-
{line:
|
111
|
-
{line:
|
107
|
+
{ line: "lib/comments/foo.rb:1", class_name: "Foo" },
|
108
|
+
{ line: "lib/comments/bar.rb:2", class_name: "Bar" }
|
112
109
|
])
|
113
110
|
end
|
114
111
|
|
115
112
|
it "should extract no readme violations if present" do
|
116
113
|
@cane.analyze
|
117
114
|
expect(@cane.violations[:documentation]).to eq([
|
118
|
-
{description:
|
115
|
+
{ description: "No README found" },
|
119
116
|
])
|
120
117
|
end
|
121
118
|
|
122
119
|
it "should extract unknown violations in others category" do
|
123
120
|
@cane.analyze
|
124
121
|
expect(@cane.violations[:others]).to eq([
|
125
|
-
{description:
|
126
|
-
{description:
|
122
|
+
{ description: "Misc issue 1" },
|
123
|
+
{ description: "Misc issue 2" }
|
127
124
|
])
|
128
125
|
end
|
129
126
|
end
|
@@ -134,19 +131,19 @@ describe CaneGenerator do
|
|
134
131
|
expect(@cane.to_h[:cane][:total_violations]).to eq(6)
|
135
132
|
end
|
136
133
|
|
137
|
-
it
|
134
|
+
it "should have violations by category" do
|
138
135
|
@cane.analyze
|
139
136
|
expect(@cane.to_h[:cane][:violations][:abc_complexity]).to eq([
|
140
|
-
{file:
|
141
|
-
{file:
|
137
|
+
{ file: "lib/abc/foo.rb", method: "Abc::Foo#method", complexity: "11" },
|
138
|
+
{ file: "lib/abc/bar.rb", method: "Abc::Bar#method", complexity: "22" }
|
142
139
|
])
|
143
140
|
expect(@cane.to_h[:cane][:violations][:line_style]).to eq([
|
144
|
-
{line:
|
145
|
-
{line:
|
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" }
|
146
143
|
])
|
147
144
|
expect(@cane.to_h[:cane][:violations][:comment]).to eq([
|
148
|
-
{line:
|
149
|
-
{line:
|
145
|
+
{ line: "lib/comments/foo.rb:1", class_name: "Foo" },
|
146
|
+
{ line: "lib/comments/bar.rb:2", class_name: "Bar" }
|
150
147
|
])
|
151
148
|
end
|
152
149
|
end
|
@@ -1,15 +1,13 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "spec_helper"
|
2
|
+
require "shared/configured"
|
3
3
|
|
4
|
-
describe MetricFu::Configuration,
|
5
|
-
it_behaves_like
|
6
|
-
|
7
|
-
|
8
|
-
load_metric 'churn'
|
4
|
+
describe MetricFu::Configuration, "for churn" do
|
5
|
+
it_behaves_like "configured" do
|
6
|
+
it "should set @churn to {}" do
|
7
|
+
load_metric "churn"
|
9
8
|
expect(MetricFu::Metric.get_metric(:churn).run_options).to eq(
|
10
|
-
|
9
|
+
start_date: '"1 year ago"', minimum_churn_count: 10, ignore_files: [], data_directory: MetricFu::Io::FileSystem.scratch_directory("churn")
|
11
10
|
)
|
12
11
|
end
|
13
|
-
|
14
12
|
end
|
15
13
|
end
|
@@ -1,39 +1,36 @@
|
|
1
1
|
require "spec_helper"
|
2
|
-
MetricFu.metrics_require {
|
2
|
+
MetricFu.metrics_require { "churn/generator" }
|
3
3
|
|
4
4
|
describe MetricFu::ChurnGenerator do
|
5
|
-
|
6
5
|
# TODO extract yaml
|
7
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") }
|
8
7
|
|
9
8
|
let(:config_setup) {
|
10
|
-
ENV[
|
9
|
+
ENV["CC_BUILD_ARTIFACTS"] = nil
|
11
10
|
MetricFu.configure.reset
|
12
11
|
}
|
13
12
|
|
14
13
|
describe "analyze method" do
|
15
14
|
before :each do
|
16
15
|
config_setup
|
17
|
-
@changes = {"lib/generators/flog.rb" => 2, "lib/metric_fu.rb" => 3}
|
16
|
+
@changes = { "lib/generators/flog.rb" => 2, "lib/metric_fu.rb" => 3 }
|
18
17
|
end
|
19
18
|
|
20
19
|
it "should be empty on error no output captured" do
|
21
20
|
churn = MetricFu::ChurnGenerator.new
|
22
21
|
churn.instance_variable_set(:@output, nil)
|
23
22
|
result = churn.analyze
|
24
|
-
expect(result).to eq(
|
23
|
+
expect(result).to eq(churn: {})
|
25
24
|
end
|
26
25
|
|
27
26
|
it "should return yaml results" do
|
28
27
|
churn = MetricFu::ChurnGenerator.new
|
29
28
|
churn.instance_variable_set(:@output, churn_hash)
|
30
29
|
result = churn.analyze
|
31
|
-
expect(result).to eq(
|
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"] })
|
32
31
|
end
|
33
|
-
|
34
32
|
end
|
35
33
|
|
36
|
-
|
37
34
|
describe "to_h method" do
|
38
35
|
before :each do
|
39
36
|
config_setup
|
@@ -41,12 +38,11 @@ describe MetricFu::ChurnGenerator do
|
|
41
38
|
|
42
39
|
it "should put the changes into a hash" do
|
43
40
|
churn = MetricFu::ChurnGenerator.new
|
44
|
-
churn.instance_variable_set(:@churn,
|
41
|
+
churn.instance_variable_set(:@churn, churn: "results")
|
45
42
|
expect(churn.to_h[:churn]).to eq("results")
|
46
43
|
end
|
47
44
|
end
|
48
45
|
|
49
|
-
|
50
46
|
describe "emit method" do
|
51
47
|
before :each do
|
52
48
|
config_setup
|
@@ -66,4 +62,3 @@ describe MetricFu::ChurnGenerator do
|
|
66
62
|
end
|
67
63
|
end
|
68
64
|
end
|
69
|
-
|
@@ -1,15 +1,13 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "spec_helper"
|
2
|
+
require "shared/configured"
|
3
3
|
|
4
|
-
describe MetricFu::Configuration,
|
5
|
-
it_behaves_like
|
6
|
-
|
7
|
-
|
8
|
-
load_metric 'flay'
|
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"
|
9
8
|
expect(MetricFu::Metric.get_metric(:flay).run_options).to eq(
|
10
|
-
|
9
|
+
dirs_to_flay: ["lib"], minimum_score: nil
|
11
10
|
)
|
12
11
|
end
|
13
|
-
|
14
12
|
end
|
15
13
|
end
|
@@ -1,10 +1,10 @@
|
|
1
1
|
require "spec_helper"
|
2
|
-
MetricFu.metrics_require {
|
2
|
+
MetricFu.metrics_require { "flay/generator" }
|
3
3
|
|
4
4
|
describe MetricFu::FlayGenerator do
|
5
5
|
describe "emit method" do
|
6
6
|
it "should look at the dirs" do
|
7
|
-
options = { :
|
7
|
+
options = { dirs_to_flay: ["app", "lib"] }
|
8
8
|
allow(File).to receive(:directory?).and_return(true)
|
9
9
|
@flay = MetricFu::FlayGenerator.new(options)
|
10
10
|
|
@@ -13,7 +13,7 @@ describe MetricFu::FlayGenerator do
|
|
13
13
|
end
|
14
14
|
|
15
15
|
it "should limit flay scores by the minimum_score" do
|
16
|
-
options = { :
|
16
|
+
options = { dirs_to_flay: [], minimum_score: 99 }
|
17
17
|
allow(File).to receive(:directory?).and_return(true)
|
18
18
|
@flay = MetricFu::FlayGenerator.new(options)
|
19
19
|
|
@@ -40,57 +40,56 @@ Total score (lower is better) = 246
|
|
40
40
|
HERE
|
41
41
|
MetricFu::Configuration.run {}
|
42
42
|
allow(File).to receive(:directory?).and_return(true)
|
43
|
-
@flay = MetricFu::FlayGenerator.new(
|
43
|
+
@flay = MetricFu::FlayGenerator.new("base_dir")
|
44
44
|
@flay.instance_variable_set(:@output, lines)
|
45
45
|
end
|
46
46
|
|
47
47
|
it "should analyze and return matches" do
|
48
|
-
expect(@flay.analyze).to eq([
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
48
|
+
expect(@flay.analyze).to eq([["Total score (lower is better) = 246"],
|
49
|
+
["\n1) IDENTICAL code found in :or (mass*2 = 68)",
|
50
|
+
"app/controllers/link_targets_controller.rb:57",
|
51
|
+
"app/controllers/primary_sites_controller.rb:138"],
|
52
|
+
["2) Similar code found in :if (mass = 64)",
|
53
|
+
"app/controllers/primary_sites_controller.rb:75",
|
54
|
+
"app/controllers/primary_sites_controller.rb:76",
|
55
|
+
"app/controllers/primary_sites_controller.rb:88",
|
56
|
+
"app/controllers/primary_sites_controller.rb:89"]])
|
57
57
|
end
|
58
58
|
end
|
59
59
|
|
60
60
|
describe "to_h method" do
|
61
|
-
|
62
61
|
before :each do
|
63
|
-
lines = [
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
62
|
+
lines = [["Total score (lower is better) = 284"],
|
63
|
+
["\n1) IDENTICAL code found in :or (mass*2 = 68)",
|
64
|
+
"app/controllers/link_targets_controller.rb:57",
|
65
|
+
"app/controllers/primary_sites_controller.rb:138"],
|
66
|
+
["2) Similar code found in :if (mass = 64)",
|
67
|
+
"app/controllers/primary_sites_controller.rb:75",
|
68
|
+
"app/controllers/primary_sites_controller.rb:76",
|
69
|
+
"app/controllers/primary_sites_controller.rb:88",
|
70
|
+
"app/controllers/primary_sites_controller.rb:89"],
|
71
|
+
["3) Similar code found in :defn (mass = 40)",
|
72
|
+
"app/controllers/link_targets_controller.rb:40",
|
73
|
+
"app/controllers/primary_sites_controller.rb:98"],
|
74
|
+
["4) Similar code found in :defn (mass = 38)",
|
75
|
+
"app/controllers/link_targets_controller.rb:13",
|
76
|
+
"app/controllers/primary_sites_controller.rb:50"],
|
77
|
+
["5) Similar code found in :defn (mass = 38)",
|
78
|
+
"app/models/primary_site.rb:104",
|
79
|
+
"app/models/primary_site.rb:109"],
|
80
|
+
["6) Similar code found in :call (mass = 36)",
|
81
|
+
"app/controllers/bookmarklet_integration_controller.rb:6",
|
82
|
+
"app/controllers/bookmarklet_integration_controller.rb:17"]]
|
84
83
|
|
85
84
|
MetricFu::Configuration.run {}
|
86
85
|
allow(File).to receive(:directory?).and_return(true)
|
87
|
-
flay = MetricFu::FlayGenerator.new(
|
86
|
+
flay = MetricFu::FlayGenerator.new("base_dir")
|
88
87
|
flay.instance_variable_set(:@matches, lines)
|
89
88
|
@results = flay.to_h
|
90
89
|
end
|
91
90
|
|
92
91
|
it "should find the total_score" do
|
93
|
-
expect(@results[:flay][:total_score]).to eq(
|
92
|
+
expect(@results[:flay][:total_score]).to eq("284")
|
94
93
|
end
|
95
94
|
|
96
95
|
it "should have 6 matches" do
|