metric_fu 4.11.3 → 4.11.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/.rubocop.yml +15 -0
- data/.rubocop_todo.yml +69 -0
- data/.travis.yml +0 -1
- data/CONTRIBUTORS +1 -1
- data/Gemfile +23 -20
- data/Guardfile +9 -9
- data/HISTORY.md +10 -1
- data/checksum/metric_fu-4.11.3.gem.sha512 +1 -0
- data/config/rubocop.yml +269 -0
- data/gem_tasks/rubocop.rake +10 -0
- data/lib/metric_fu.rb +11 -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 +9 -11
- data/lib/metric_fu/generator.rb +5 -8
- 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 +22 -23
- 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 -9
- 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 +10 -12
- data/lib/metric_fu/metrics/rails_best_practices/grapher.rb +5 -6
- data/lib/metric_fu/metrics/rails_best_practices/metric.rb +1 -3
- 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 +22 -23
- 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 +19 -19
- data/lib/metric_fu/templates/report.rb +5 -8
- data/lib/metric_fu/templates/template.rb +20 -24
- data/lib/metric_fu/utility.rb +7 -8
- data/lib/metric_fu/version.rb +1 -1
- data/metric_fu.gemspec +31 -32
- data/spec/cli/helper_spec.rb +7 -14
- 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 +70 -82
- 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 +11 -13
- 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 +6 -6
- data/spec/metric_fu/gem_version_spec.rb +3 -5
- data/spec/metric_fu/generator_spec.rb +28 -38
- data/spec/metric_fu/loader_spec.rb +1 -3
- data/spec/metric_fu/metric_spec.rb +17 -21
- data/spec/metric_fu/metrics/cane/configuration_spec.rb +8 -8
- data/spec/metric_fu/metrics/cane/generator_spec.rb +26 -29
- data/spec/metric_fu/metrics/churn/configuration_spec.rb +6 -8
- data/spec/metric_fu/metrics/churn/generator_spec.rb +6 -11
- data/spec/metric_fu/metrics/flay/configuration_spec.rb +6 -8
- 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 +11 -13
- data/spec/metric_fu/metrics/flog/generator_spec.rb +29 -31
- 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 +6 -10
- 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 +20 -22
- 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 +6 -6
- data/spec/metric_fu/metrics/reek/generator_spec.rb +19 -20
- data/spec/metric_fu/metrics/reek/grapher_spec.rb +4 -4
- data/spec/metric_fu/metrics/roodi/configuration_spec.rb +7 -9
- 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 +18 -19
- data/spec/metric_fu/metrics/saikuro/generator_spec.rb +7 -7
- data/spec/metric_fu/metrics/stats/generator_spec.rb +9 -9
- data/spec/metric_fu/metrics/stats/grapher_spec.rb +2 -2
- data/spec/metric_fu/reporter_spec.rb +3 -4
- 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 +9 -11
- data/spec/metric_fu/run_spec.rb +18 -32
- data/spec/metric_fu/templates/configuration_spec.rb +28 -34
- 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 +62 -48
- data/spec/metric_fu/utility_spec.rb +2 -2
- data/spec/metric_fu_spec.rb +5 -7
- data/spec/shared/configured.rb +9 -11
- data/spec/shared/test_coverage.rb +5 -9
- data/spec/spec_helper.rb +9 -9
- data/spec/support/deferred_garbaged_collection.rb +1 -2
- data/spec/support/matcher_create_file.rb +2 -4
- data/spec/support/matcher_create_files.rb +2 -4
- 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 +23 -24
- data/spec/usage_test_spec.rb +18 -20
- metadata +12 -2
- metadata.gz.sig +0 -0
@@ -1,53 +1,47 @@
|
|
1
1
|
require "spec_helper"
|
2
|
-
MetricFu.formatter_require {
|
2
|
+
MetricFu.formatter_require { "yaml" }
|
3
3
|
|
4
4
|
describe MetricFu::Formatter::YAML do
|
5
|
-
|
6
5
|
before do
|
7
6
|
setup_fs
|
8
7
|
|
9
8
|
config = MetricFu.configuration
|
10
9
|
|
11
10
|
if config.mri?
|
12
|
-
|
11
|
+
@metric1 = :cane
|
13
12
|
else
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
13
|
+
@metric1 = :stats
|
14
|
+
config.templates_configuration do |c|
|
15
|
+
c.syntax_highlighting = false
|
16
|
+
end
|
18
17
|
end
|
19
|
-
allow(MetricFu::Metric.get_metric(@metric1)).to receive(:run_external).and_return(
|
18
|
+
allow(MetricFu::Metric.get_metric(@metric1)).to receive(:run_external).and_return("")
|
20
19
|
@metric2 = :hotspots
|
21
20
|
MetricFu.result.add(@metric1)
|
22
21
|
MetricFu.result.add(@metric2)
|
23
22
|
end
|
24
23
|
|
25
24
|
context "In general" do
|
26
|
-
|
27
25
|
it "creates a report yaml file" do
|
28
26
|
expect {
|
29
|
-
|
27
|
+
MetricFu::Formatter::YAML.new.finish
|
30
28
|
}.to create_file("#{directory('base_directory')}/report.yml")
|
31
29
|
end
|
32
|
-
|
33
30
|
end
|
34
31
|
|
35
32
|
context "given a custom output file" do
|
36
|
-
|
37
33
|
before do
|
38
34
|
@output = "customreport.yml"
|
39
35
|
end
|
40
36
|
|
41
37
|
it "creates a report yaml file to the custom output path" do
|
42
38
|
expect {
|
43
|
-
|
39
|
+
MetricFu::Formatter::YAML.new(output: @output).finish
|
44
40
|
}.to create_file("#{directory('base_directory')}/customreport.yml")
|
45
41
|
end
|
46
|
-
|
47
42
|
end
|
48
43
|
|
49
44
|
context "given a custom output stream" do
|
50
|
-
|
51
45
|
before do
|
52
46
|
@output = $stdout
|
53
47
|
end
|
@@ -59,11 +53,9 @@ describe MetricFu::Formatter::YAML do
|
|
59
53
|
expect(out).to include ":#{@metric1}:"
|
60
54
|
expect(out).to include ":#{@metric2}:"
|
61
55
|
end
|
62
|
-
|
63
56
|
end
|
64
57
|
|
65
58
|
after do
|
66
59
|
cleanup_fs
|
67
60
|
end
|
68
|
-
|
69
61
|
end
|
@@ -3,7 +3,7 @@ require "spec_helper"
|
|
3
3
|
describe MetricFu::Formatter do
|
4
4
|
describe "formatter class loading" do
|
5
5
|
context "given a built-in formatter (string)" do
|
6
|
-
subject { MetricFu::Formatter.class_for(
|
6
|
+
subject { MetricFu::Formatter.class_for("html") }
|
7
7
|
|
8
8
|
it "returns the formatter class" do
|
9
9
|
expect(subject).to eq(MetricFu::Formatter::HTML)
|
@@ -22,15 +22,15 @@ describe MetricFu::Formatter do
|
|
22
22
|
subject { MetricFu::Formatter.class_for(:unknown) }
|
23
23
|
|
24
24
|
it "raises an error" do
|
25
|
-
expect{ subject }.to raise_error(NameError)
|
25
|
+
expect { subject }.to raise_error(NameError)
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
29
|
context "given a custom formatter that exists" do
|
30
|
-
subject { MetricFu::Formatter.class_for(
|
30
|
+
subject { MetricFu::Formatter.class_for("MyCustomFormatter") }
|
31
31
|
|
32
32
|
before do
|
33
|
-
stub_const(
|
33
|
+
stub_const("MyCustomFormatter", Class.new { def initialize(*); end })
|
34
34
|
end
|
35
35
|
|
36
36
|
it "returns the formatter class" do
|
@@ -39,10 +39,10 @@ describe MetricFu::Formatter do
|
|
39
39
|
end
|
40
40
|
|
41
41
|
context "given a custom formatter that doesnt exist" do
|
42
|
-
subject { MetricFu::Formatter.class_for(
|
42
|
+
subject { MetricFu::Formatter.class_for("MyNonExistentCustomFormatter") }
|
43
43
|
|
44
44
|
it "raises an error" do
|
45
|
-
expect{ subject }.to raise_error(NameError)
|
45
|
+
expect { subject }.to raise_error(NameError)
|
46
46
|
end
|
47
47
|
end
|
48
48
|
end
|
@@ -1,14 +1,12 @@
|
|
1
|
-
require
|
2
|
-
MetricFu.lib_require {
|
1
|
+
require "spec_helper"
|
2
|
+
MetricFu.lib_require { "gem_version" }
|
3
3
|
|
4
4
|
describe MetricFu::GemVersion do
|
5
|
-
|
6
5
|
it "has a list of gem deps" do
|
7
6
|
gem_version = MetricFu::GemVersion.new
|
8
7
|
gem_deps = gem_version.gem_runtime_dependencies.map(&:name)
|
9
|
-
MetricFu::Metric.metrics.reject{|metric| metric.name == :hotspots || metric.name == :stats}.map(&:name).map(&:to_s).each do |metric_name|
|
8
|
+
MetricFu::Metric.metrics.reject { |metric| metric.name == :hotspots || metric.name == :stats }.map(&:name).map(&:to_s).each do |metric_name|
|
10
9
|
expect(gem_deps).to include(metric_name)
|
11
10
|
end
|
12
11
|
end
|
13
|
-
|
14
12
|
end
|
@@ -1,10 +1,8 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
3
|
describe MetricFu::Generator do
|
4
|
-
|
5
4
|
include TestConstruct::Helpers
|
6
5
|
|
7
|
-
|
8
6
|
class ConcreteClass < MetricFu::Generator
|
9
7
|
def self.metric
|
10
8
|
:concrete
|
@@ -21,7 +19,7 @@ describe MetricFu::Generator do
|
|
21
19
|
end
|
22
20
|
|
23
21
|
before(:each) do
|
24
|
-
ENV[
|
22
|
+
ENV["CC_BUILD_ARTIFACTS"] = nil
|
25
23
|
MetricFu.configuration.reset
|
26
24
|
MetricFu.configure
|
27
25
|
@concrete_class = ConcreteClass.new
|
@@ -29,39 +27,38 @@ describe MetricFu::Generator do
|
|
29
27
|
|
30
28
|
describe "ConcreteClass#metric_directory" do
|
31
29
|
it "should be '{artifact_dir}/scratch/concreteclass'" do
|
32
|
-
concrete_metric = double(
|
30
|
+
concrete_metric = double("concrete_metric")
|
33
31
|
expect(MetricFu::Metric).to receive(:get_metric).with(:concrete).and_return(concrete_metric)
|
34
32
|
expect(concrete_metric).to receive(:run_options).and_return({})
|
35
|
-
compare_paths(ConcreteClass.metric_directory, scratch_directory(
|
33
|
+
compare_paths(ConcreteClass.metric_directory, scratch_directory("concrete"))
|
36
34
|
end
|
37
35
|
end
|
38
36
|
|
39
37
|
describe "#metric_directory" do
|
40
38
|
it "should return the results of ConcreteClass#metric_directory" do
|
41
|
-
allow(ConcreteClass).to receive(:metric_directory).and_return(
|
42
|
-
expect(@concrete_class.metric_directory).to eq(
|
39
|
+
allow(ConcreteClass).to receive(:metric_directory).and_return("foo")
|
40
|
+
expect(@concrete_class.metric_directory).to eq("foo")
|
43
41
|
end
|
44
42
|
end
|
45
43
|
|
46
44
|
describe "#generate_result" do
|
47
45
|
it "should raise an error when calling #emit" do
|
48
46
|
@abstract_class = MetricFu::Generator.new
|
49
|
-
expect { @abstract_class.generate_result }.to
|
47
|
+
expect { @abstract_class.generate_result }.to raise_error
|
50
48
|
end
|
51
49
|
|
52
50
|
it "should call #analyze" do
|
53
51
|
@abstract_class = MetricFu::Generator.new
|
54
|
-
expect { @abstract_class.generate_result }.to
|
52
|
+
expect { @abstract_class.generate_result }.to raise_error
|
55
53
|
end
|
56
54
|
|
57
55
|
it "should call #to_h" do
|
58
56
|
@abstract_class = MetricFu::Generator.new
|
59
|
-
expect { @abstract_class.generate_result }.to
|
57
|
+
expect { @abstract_class.generate_result }.to raise_error
|
60
58
|
end
|
61
59
|
end
|
62
60
|
|
63
61
|
describe "#generate_result (in a concrete class)" do
|
64
|
-
|
65
62
|
%w[emit analyze].each do |meth|
|
66
63
|
it "should call ##{meth}" do
|
67
64
|
expect(@concrete_class).to receive("#{meth}")
|
@@ -73,23 +70,20 @@ describe MetricFu::Generator do
|
|
73
70
|
expect(@concrete_class).to receive(:to_h)
|
74
71
|
@concrete_class.generate_result
|
75
72
|
end
|
76
|
-
|
77
73
|
end
|
78
74
|
|
79
75
|
describe "path filter" do
|
80
|
-
|
81
76
|
context "given a list of paths" do
|
82
|
-
|
83
77
|
before do
|
84
78
|
@paths = %w(lib/fake/fake.rb
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
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)
|
93
87
|
@container = create_construct
|
94
88
|
@paths.each do |path|
|
95
89
|
@container.file(path)
|
@@ -109,32 +103,28 @@ describe MetricFu::Generator do
|
|
109
103
|
end
|
110
104
|
|
111
105
|
it "should filter filename at root level" do
|
112
|
-
files = @concrete_class.remove_excluded_files(@paths, [
|
113
|
-
expect(files).not_to include(
|
106
|
+
files = @concrete_class.remove_excluded_files(@paths, ["basic.rb"])
|
107
|
+
expect(files).not_to include("basic.rb")
|
114
108
|
end
|
115
109
|
|
116
110
|
it "should remove files that are two levels deep" do
|
117
|
-
files = @concrete_class.remove_excluded_files(@paths, [
|
118
|
-
expect(files).not_to include(
|
111
|
+
files = @concrete_class.remove_excluded_files(@paths, ["**/fake.rb"])
|
112
|
+
expect(files).not_to include("lib/fake/fake.rb")
|
119
113
|
end
|
120
114
|
|
121
115
|
it "should remove files from an excluded directory" do
|
122
|
-
files = @concrete_class.remove_excluded_files(@paths, [
|
123
|
-
expect(files).not_to include(
|
124
|
-
expect(files).not_to include(
|
125
|
-
expect(files).not_to include(
|
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")
|
126
120
|
end
|
127
121
|
|
128
122
|
it "should support shell alternation globs" do
|
129
|
-
files = @concrete_class.remove_excluded_files(@paths, [
|
130
|
-
expect(files).not_to include(
|
131
|
-
expect(files).not_to include(
|
132
|
-
expect(files).to include(
|
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")
|
133
127
|
end
|
134
|
-
|
135
128
|
end
|
136
|
-
|
137
|
-
|
138
129
|
end
|
139
|
-
|
140
130
|
end
|
@@ -1,12 +1,10 @@
|
|
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
7
|
MetricFu.loader.load_user_configuration
|
9
8
|
expect($metric_file_loaded).to be_truthy
|
10
9
|
end
|
11
|
-
|
12
10
|
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 "can have its run_options over-written" do
|
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 "can have its run_options modified" do
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
#end
|
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
21
|
|
22
22
|
context "given a valid configurable option" do
|
23
|
-
|
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
27
|
it "can be configured as an attribute" do
|
29
|
-
@metric.foo =
|
30
|
-
expect(@metric.run_options[:foo]).to eq(
|
28
|
+
@metric.foo = "qux"
|
29
|
+
expect(@metric.run_options[:foo]).to eq("qux")
|
31
30
|
end
|
32
|
-
|
33
31
|
end
|
34
32
|
|
35
33
|
context "given an invalid configurable option" do
|
36
|
-
|
37
34
|
before do
|
38
35
|
allow(@metric).to receive(:default_run_options).and_return({})
|
39
36
|
end
|
40
37
|
|
41
38
|
it "raises an error" do
|
42
|
-
expect { @metric.foo =
|
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
|
@@ -5,16 +5,16 @@ describe MetricFu::Configuration, "for cane" do
|
|
5
5
|
it_behaves_like "configured" do
|
6
6
|
if MetricFu.configuration.mri?
|
7
7
|
it "should set @cane to " +
|
8
|
-
|
8
|
+
':dirs_to_cane => @code_dirs, :abc_max => 15, :line_length => 80, :no_doc => "n", :no_readme => "y"' do
|
9
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
|