metric_fu 4.4.4 → 4.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +14 -6
- checksums.yaml.gz.sig +3 -0
- data.tar.gz.sig +0 -0
- data/.gitignore +1 -0
- data/.metrics +0 -3
- data/.travis.yml +1 -1
- data/.yardopts +0 -1
- data/CONTRIBUTING.md +1 -0
- data/CONTRIBUTORS +61 -2
- data/Gemfile +14 -11
- data/Gemfile.devtools +40 -0
- data/Guardfile +30 -0
- data/HISTORY.md +54 -1
- data/README.md +86 -56
- data/bin/mf-cane +8 -6
- data/bin/mf-churn +8 -7
- data/bin/mf-flay +8 -7
- data/bin/mf-reek +8 -7
- data/bin/mf-roodi +8 -7
- data/bin/mf-saikuro +8 -6
- data/certs/bf4.pem +22 -0
- data/checksum/metric_fu-4.4.4.gem.sha512 +1 -0
- data/checksum/metric_fu-4.5.0.gem.sha512 +1 -0
- data/etc/README.md +16 -0
- data/etc/erd.dot +173 -0
- data/etc/erd.png +0 -0
- data/lib/metric_fu.rb +56 -12
- data/lib/metric_fu/cli/helper.rb +8 -2
- data/lib/metric_fu/cli/parser.rb +86 -50
- data/lib/metric_fu/configuration.rb +4 -31
- data/lib/metric_fu/environment.rb +1 -1
- data/lib/metric_fu/formatter/html.rb +5 -5
- data/lib/metric_fu/gem_run.rb +68 -0
- data/lib/metric_fu/gem_version.rb +57 -0
- data/lib/metric_fu/io.rb +1 -1
- data/lib/metric_fu/load_files.rb +3 -5
- data/lib/metric_fu/loader.rb +31 -2
- data/lib/metric_fu/logging/mf_debugger.rb +1 -0
- data/lib/metric_fu/metric.rb +23 -1
- data/lib/metric_fu/metrics/cane/cane.rb +7 -3
- data/lib/metric_fu/metrics/cane/cane_grapher.rb +19 -0
- data/lib/metric_fu/metrics/cane/template_awesome/cane.html.erb +0 -4
- data/lib/metric_fu/metrics/churn/churn.rb +6 -7
- data/lib/metric_fu/metrics/flay/flay.rb +2 -4
- data/lib/metric_fu/metrics/flay/flay_grapher.rb +19 -0
- data/lib/metric_fu/metrics/flay/template_awesome/flay.html.erb +0 -4
- data/lib/metric_fu/metrics/flog/flog.rb +0 -2
- data/lib/metric_fu/metrics/flog/flog_grapher.rb +19 -0
- data/lib/metric_fu/metrics/flog/template_awesome/flog.html.erb +0 -4
- data/lib/metric_fu/metrics/generator.rb +34 -24
- data/lib/metric_fu/metrics/graph.rb +8 -14
- data/lib/metric_fu/metrics/hotspots/hotspot.rb +7 -5
- data/lib/metric_fu/metrics/hotspots/template_awesome/hotspots.html.erb +4 -6
- data/lib/metric_fu/metrics/rails_best_practices/rails_best_practices.rb +0 -2
- data/lib/metric_fu/metrics/rails_best_practices/rails_best_practices_grapher.rb +19 -0
- data/lib/metric_fu/metrics/rails_best_practices/template_awesome/rails_best_practices.html.erb +0 -4
- data/lib/metric_fu/metrics/rcov/rcov_grapher.rb +19 -0
- data/lib/metric_fu/metrics/rcov/template_awesome/rcov.html.erb +0 -4
- data/lib/metric_fu/metrics/reek/init.rb +1 -1
- data/lib/metric_fu/metrics/reek/reek.rb +12 -8
- data/lib/metric_fu/metrics/reek/reek_grapher.rb +19 -0
- data/lib/metric_fu/metrics/reek/template_awesome/reek.html.erb +0 -4
- data/lib/metric_fu/metrics/roodi/roodi.rb +2 -3
- data/lib/metric_fu/metrics/roodi/roodi_grapher.rb +19 -0
- data/lib/metric_fu/metrics/roodi/template_awesome/roodi.html.erb +0 -4
- data/lib/metric_fu/metrics/saikuro/saikuro.rb +69 -33
- data/lib/metric_fu/metrics/saikuro/scratch_file.rb +8 -9
- data/lib/metric_fu/metrics/stats/stats_grapher.rb +20 -0
- data/lib/metric_fu/metrics/stats/template_awesome/stats.html.erb +0 -4
- data/lib/metric_fu/reporting/graphs/grapher.rb +69 -3
- data/lib/metric_fu/reporting/result.rb +5 -1
- data/lib/metric_fu/reporting/templates/awesome/awesome_template.rb +7 -3
- data/lib/metric_fu/run.rb +13 -7
- data/lib/metric_fu/tasks/metric_fu.rake +50 -3
- data/lib/metric_fu/utility.rb +10 -0
- data/lib/metric_fu/version.rb +1 -1
- data/metric_fu.gemspec +7 -4
- data/spec/dummy/.gitignore +1 -0
- data/spec/dummy/.gitkeep +0 -0
- data/spec/dummy/.metrics +4 -0
- data/spec/dummy/lib/.gitkeep +0 -0
- data/spec/dummy/spec/.gitkeep +0 -0
- data/spec/{resources/yml → fixtures}/20090630.yml +1 -1
- data/spec/{resources/yml → fixtures}/hotspots/flog.yml +0 -0
- data/spec/{resources/yml → fixtures}/hotspots/generator.yml +0 -0
- data/spec/{resources/yml → fixtures}/hotspots/generator_analysis.yml +0 -0
- data/spec/{resources/yml → fixtures}/hotspots/reek.yml +0 -0
- data/spec/{resources/yml → fixtures}/hotspots/roodi.yml +0 -0
- data/spec/{resources/yml → fixtures}/hotspots/saikuro.yml +0 -0
- data/spec/{resources/yml → fixtures}/hotspots/several_metrics.yml +0 -0
- data/spec/{resources/yml → fixtures}/hotspots/stats.yml +0 -0
- data/spec/{resources/yml → fixtures}/hotspots/three_metrics_on_same_file.yml +0 -0
- data/spec/{resources → fixtures}/line_numbers/foo.rb +0 -0
- data/spec/{resources → fixtures}/line_numbers/module.rb +0 -0
- data/spec/{resources → fixtures}/line_numbers/module_surrounds_class.rb +0 -0
- data/spec/{resources → fixtures}/line_numbers/two_classes.rb +0 -0
- data/spec/{resources/yml → fixtures}/metric_missing.yml +0 -0
- data/spec/{resources → fixtures}/saikuro/app/controllers/sessions_controller.rb_cyclo.html +0 -0
- data/spec/{resources → fixtures}/saikuro/app/controllers/users_controller.rb_cyclo.html +0 -0
- data/spec/{resources → fixtures}/saikuro/index_cyclo.html +0 -0
- data/spec/{resources → fixtures}/saikuro_sfiles/thing.rb_cyclo.html +0 -0
- data/spec/metric_fu/configuration_spec.rb +1 -1
- data/spec/metric_fu/data_structures/line_numbers_spec.rb +13 -11
- data/spec/metric_fu/formatter/html_spec.rb +2 -2
- data/spec/metric_fu/gem_version_spec.rb +14 -0
- data/spec/metric_fu/loader_spec.rb +12 -0
- data/spec/metric_fu/metrics/base_template_spec.rb +9 -7
- data/spec/metric_fu/metrics/cane/cane_spec.rb +7 -7
- data/spec/metric_fu/metrics/churn/churn_spec.rb +1 -1
- data/spec/metric_fu/metrics/flay/flay_grapher_spec.rb +2 -2
- data/spec/metric_fu/metrics/flay/flay_spec.rb +2 -2
- data/spec/metric_fu/metrics/flog/flog_grapher_spec.rb +3 -3
- data/spec/metric_fu/metrics/generator_spec.rb +1 -35
- data/spec/metric_fu/metrics/graph_spec.rb +7 -24
- data/spec/metric_fu/metrics/hotspots/analysis/analyzed_problems_spec.rb +2 -2
- data/spec/metric_fu/metrics/hotspots/analysis/analyzer_tables_spec.rb +2 -2
- data/spec/metric_fu/metrics/hotspots/analysis/rankings_spec.rb +5 -5
- data/spec/metric_fu/metrics/hotspots/hotspots_spec.rb +2 -3
- data/spec/metric_fu/metrics/rails_best_practices/rails_best_practices_grapher_spec.rb +2 -2
- data/spec/metric_fu/metrics/rails_best_practices/rails_best_practices_spec.rb +1 -1
- data/spec/metric_fu/metrics/rcov/rcov_grapher_spec.rb +2 -2
- data/spec/metric_fu/metrics/rcov/rcov_spec.rb +1 -4
- data/spec/metric_fu/metrics/reek/reek_grapher_spec.rb +2 -2
- data/spec/metric_fu/metrics/reek/reek_spec.rb +1 -1
- data/spec/metric_fu/metrics/roodi/roodi_grapher_spec.rb +2 -2
- data/spec/metric_fu/metrics/roodi/roodi_spec.rb +3 -3
- data/spec/metric_fu/metrics/saikuro/saikuro_spec.rb +14 -10
- data/spec/metric_fu/metrics/stats/stats_grapher_spec.rb +2 -2
- data/spec/metric_fu/reporting/graphs/{engines/bluff_spec.rb → grapher_spec.rb} +8 -2
- data/spec/{run_spec.rb → metric_fu/run_spec.rb} +8 -13
- data/spec/spec_helper.rb +30 -5
- data/spec/support/deferred_garbaged_collection.rb +34 -0
- data/spec/support/helper_methods.rb +1 -15
- data/spec/support/suite.rb +4 -24
- data/spec/support/test_fixtures.rb +39 -0
- data/spec/support/timeout.rb +7 -0
- metadata +129 -104
- metadata.gz.sig +1 -0
- data/lib/metric_fu/metrics/cane/cane_bluff_grapher.rb +0 -16
- data/lib/metric_fu/metrics/cane/cane_gchart_grapher.rb +0 -25
- data/lib/metric_fu/metrics/flay/flay_bluff_grapher.rb +0 -16
- data/lib/metric_fu/metrics/flay/flay_gchart_grapher.rb +0 -20
- data/lib/metric_fu/metrics/flog/flog_bluff_grapher.rb +0 -17
- data/lib/metric_fu/metrics/flog/flog_gchart_grapher.rb +0 -28
- data/lib/metric_fu/metrics/rails_best_practices/rails_best_practices_bluff_grapher.rb +0 -16
- data/lib/metric_fu/metrics/rails_best_practices/rails_best_practices_gchart_grapher.rb +0 -27
- data/lib/metric_fu/metrics/rcov/rcov_bluff_grapher.rb +0 -16
- data/lib/metric_fu/metrics/rcov/rcov_gchart_grapher.rb +0 -22
- data/lib/metric_fu/metrics/reek/reek_bluff_grapher.rb +0 -16
- data/lib/metric_fu/metrics/reek/reek_gchart_grapher.rb +0 -30
- data/lib/metric_fu/metrics/roodi/roodi_bluff_grapher.rb +0 -16
- data/lib/metric_fu/metrics/roodi/roodi_gchart_grapher.rb +0 -20
- data/lib/metric_fu/metrics/stats/stats_bluff_grapher.rb +0 -17
- data/lib/metric_fu/metrics/stats/stats_gchart_grapher.rb +0 -27
- data/lib/metric_fu/reporting/graphs/engines/bluff.rb +0 -33
- data/lib/metric_fu/reporting/graphs/engines/gchart.rb +0 -72
- data/lib/metric_fu/reporting/graphs/engines/init.rb +0 -19
- data/lib/metric_fu_requires.rb +0 -63
- data/spec/metric_fu/reporting/graphs/engines/gchart_spec.rb +0 -161
@@ -25,7 +25,7 @@ describe RailsBestPracticesGenerator do
|
|
25
25
|
describe "to_h method" do
|
26
26
|
it "should put things into a hash" do
|
27
27
|
MetricFu::Configuration.run {}
|
28
|
-
practices = MetricFu::
|
28
|
+
practices = MetricFu::RailsBestPracticesGenerator.new
|
29
29
|
practices.instance_variable_set(:@rails_best_practices_results, "the_practices")
|
30
30
|
practices.to_h[:rails_best_practices].should == "the_practices"
|
31
31
|
end
|
@@ -21,7 +21,7 @@ describe RcovGrapher do
|
|
21
21
|
describe "responding to #get_metrics" do
|
22
22
|
context "when metrics were not generated" do
|
23
23
|
before(:each) do
|
24
|
-
@metrics =
|
24
|
+
@metrics = FIXTURE.load_metric("metric_missing.yml")
|
25
25
|
@date = "1/2"
|
26
26
|
end
|
27
27
|
|
@@ -38,7 +38,7 @@ describe RcovGrapher do
|
|
38
38
|
|
39
39
|
context "when metrics have been generated" do
|
40
40
|
before(:each) do
|
41
|
-
@metrics =
|
41
|
+
@metrics = FIXTURE.load_metric("20090630.yml")
|
42
42
|
@date = "1/2"
|
43
43
|
end
|
44
44
|
|
@@ -28,8 +28,6 @@ describe MetricFu::RcovGenerator do
|
|
28
28
|
end
|
29
29
|
|
30
30
|
it "should set the RAILS_ENV" do
|
31
|
-
pending "Making this work with FakeFs"
|
32
|
-
next if breaks_when?(MetricFu.configuration.rubinius?)
|
33
31
|
MetricFu::Utility.should_receive(:rm_rf).with(MetricFu::RcovGenerator.metric_directory, :verbose => false)
|
34
32
|
MetricFu::Utility.should_receive(:mkdir_p).with(MetricFu::RcovGenerator.metric_directory)
|
35
33
|
options = {:environment => 'metrics', :external => nil}
|
@@ -39,7 +37,6 @@ describe MetricFu::RcovGenerator do
|
|
39
37
|
end
|
40
38
|
|
41
39
|
describe "with RCOV_OUTPUT fed into" do
|
42
|
-
next if breaks_when?(MetricFu.configuration.rubinius?)
|
43
40
|
before :each do
|
44
41
|
options = {:external => nil}
|
45
42
|
@rcov = MetricFu::RcovGenerator.new(@default_options.merge(options))
|
@@ -118,7 +115,7 @@ lib/templates/awesome/awesome_template.rb
|
|
118
115
|
|
119
116
|
def write
|
120
117
|
!! # Getting rid of the crap before and after the project name from integrity
|
121
|
-
!! @name = File.basename(
|
118
|
+
!! @name = File.basename(MetricFu.run_dir).gsub(/^\w+-|-\w+$/, "")
|
122
119
|
!!
|
123
120
|
!! # Copy Bluff javascripts to output directory
|
124
121
|
!! Dir[File.join(template_directory, '..', 'javascripts', '*')].each do |f|
|
@@ -21,7 +21,7 @@ describe ReekGrapher do
|
|
21
21
|
describe "responding to #get_metrics" do
|
22
22
|
context "when metrics were not generated" do
|
23
23
|
before(:each) do
|
24
|
-
@metrics =
|
24
|
+
@metrics = FIXTURE.load_metric("metric_missing.yml")
|
25
25
|
@date = "1/2"
|
26
26
|
end
|
27
27
|
|
@@ -38,7 +38,7 @@ describe ReekGrapher do
|
|
38
38
|
|
39
39
|
context "when metrics have been generated" do
|
40
40
|
before(:each) do
|
41
|
-
@metrics =
|
41
|
+
@metrics = FIXTURE.load_metric("20090630.yml")
|
42
42
|
@date = "1/2"
|
43
43
|
end
|
44
44
|
|
@@ -7,7 +7,7 @@ describe MetricFu::ReekGenerator do
|
|
7
7
|
reek = MetricFu::ReekGenerator.new(options)
|
8
8
|
files_to_analyze = ['lib/foo.rb','lib/bar.rb']
|
9
9
|
reek.stub(:files_to_analyze).and_return(files_to_analyze)
|
10
|
-
reek.should_receive(
|
10
|
+
reek.should_receive(:run!).with(/--config lib\/config\/\*\.reek lib\/foo.rb lib\/bar.rb/).and_return("")
|
11
11
|
reek.emit
|
12
12
|
end
|
13
13
|
end
|
@@ -21,7 +21,7 @@ describe RoodiGrapher do
|
|
21
21
|
describe "responding to #get_metrics" do
|
22
22
|
context "when metrics were not generated" do
|
23
23
|
before(:each) do
|
24
|
-
@metrics =
|
24
|
+
@metrics = FIXTURE.load_metric("metric_missing.yml")
|
25
25
|
@date = "1/2"
|
26
26
|
end
|
27
27
|
|
@@ -38,7 +38,7 @@ describe RoodiGrapher do
|
|
38
38
|
|
39
39
|
context "when metrics have been generated" do
|
40
40
|
before(:each) do
|
41
|
-
@metrics =
|
41
|
+
@metrics = FIXTURE.load_metric("20090630.yml")
|
42
42
|
@date = "1/2"
|
43
43
|
end
|
44
44
|
|
@@ -5,15 +5,15 @@ describe MetricFu::RoodiGenerator do
|
|
5
5
|
it "should add config options when present" do
|
6
6
|
options = {:roodi_config => 'lib/config/roodi_config.yml', :dirs_to_roodi => []}
|
7
7
|
roodi = MetricFu::RoodiGenerator.new(options)
|
8
|
-
roodi.should_receive(
|
8
|
+
roodi.should_receive(:run!).with(/-config=lib\/config\/roodi_config\.yml/).and_return("")
|
9
9
|
roodi.emit
|
10
10
|
end
|
11
11
|
|
12
12
|
it "should NOT add config options when NOT present" do
|
13
13
|
options = {:dirs_to_roodi => []}
|
14
14
|
roodi = MetricFu::RoodiGenerator.new(options)
|
15
|
-
roodi.stub(
|
16
|
-
roodi.should_receive(
|
15
|
+
roodi.stub(:run!)
|
16
|
+
roodi.should_receive(:run!).with(/-config/).never
|
17
17
|
roodi.emit
|
18
18
|
end
|
19
19
|
end
|
@@ -1,13 +1,19 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
3
|
describe MetricFu::SaikuroGenerator do
|
4
|
+
STUB_TEST_DATA = lambda do |generator|
|
5
|
+
# set test data dir; ensure it doesn't get cleared
|
6
|
+
def generator.metric_directory
|
7
|
+
FIXTURE.fixtures_path.join("saikuro").to_s
|
8
|
+
end
|
9
|
+
generator.stub(:clear_scratch_files!)
|
10
|
+
end
|
4
11
|
describe "to_h method" do
|
5
|
-
before
|
12
|
+
before do
|
6
13
|
options = {}
|
7
14
|
saikuro = MetricFu::SaikuroGenerator.new(options)
|
8
|
-
|
9
|
-
|
10
|
-
end
|
15
|
+
STUB_TEST_DATA[saikuro]
|
16
|
+
|
11
17
|
saikuro.analyze
|
12
18
|
@output = saikuro.to_h
|
13
19
|
end
|
@@ -39,15 +45,13 @@ describe MetricFu::SaikuroGenerator do
|
|
39
45
|
before :all do
|
40
46
|
options = {}
|
41
47
|
@saikuro = MetricFu::SaikuroGenerator.new(options)
|
42
|
-
|
43
|
-
"#{resources_path}/saikuro"
|
44
|
-
end
|
48
|
+
STUB_TEST_DATA[@saikuro]
|
45
49
|
@saikuro.analyze
|
46
50
|
@output = @saikuro.to_h
|
47
51
|
end
|
48
52
|
|
49
53
|
it "doesn't try to get information if the file does not exist" do
|
50
|
-
|
54
|
+
@saikuro.should_receive(:file_not_exists?).at_least(:once).and_return(true)
|
51
55
|
@saikuro.per_file_info('ignore_me')
|
52
56
|
end
|
53
57
|
end
|
@@ -55,8 +59,8 @@ describe MetricFu::SaikuroGenerator do
|
|
55
59
|
describe MetricFu::SaikuroScratchFile do
|
56
60
|
describe "getting elements from a Saikuro result file" do
|
57
61
|
it "should parse nested START/END sections" do
|
58
|
-
path = "
|
59
|
-
|
62
|
+
path = FIXTURE.fixtures_path.join("saikuro_sfiles", "thing.rb_cyclo.html").to_s
|
63
|
+
sfile = MetricFu::SaikuroScratchFile.new path
|
60
64
|
sfile.elements.map { |e| e.complexity }.sort.should eql(["0","0","2"])
|
61
65
|
end
|
62
66
|
end
|
@@ -23,7 +23,7 @@ describe StatsGrapher do
|
|
23
23
|
describe "responding to #get_metrics" do
|
24
24
|
context "when metrics were not generated" do
|
25
25
|
before(:each) do
|
26
|
-
@metrics =
|
26
|
+
@metrics = FIXTURE.load_metric("metric_missing.yml")
|
27
27
|
@date = "01022003"
|
28
28
|
end
|
29
29
|
|
@@ -45,7 +45,7 @@ describe StatsGrapher do
|
|
45
45
|
|
46
46
|
context "when metrics have been generated" do
|
47
47
|
before(:each) do
|
48
|
-
@metrics =
|
48
|
+
@metrics = FIXTURE.load_metric("20090630.yml")
|
49
49
|
@date = "01022003"
|
50
50
|
end
|
51
51
|
|
@@ -1,18 +1,24 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
3
|
describe "Bluff graphers responding to #graph!" do
|
4
|
+
before do
|
5
|
+
setup_fs
|
6
|
+
end
|
7
|
+
after do
|
8
|
+
cleanup_fs
|
9
|
+
end
|
4
10
|
it "should write chart file" do
|
5
11
|
graphs = {}
|
6
12
|
available_graphs = MetricFu::Metric.enabled_metrics.select{|m|m.has_graph?}.map(&:name)
|
7
13
|
available_graphs.each do |graph|
|
8
14
|
grapher_name = graph.to_s.gsub("MetricFu::",'').gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase }
|
9
|
-
grapher_name = grapher_name+"
|
15
|
+
grapher_name = grapher_name+"Grapher"
|
10
16
|
graphs[graph] = MetricFu.const_get(grapher_name).new
|
11
17
|
end
|
12
18
|
graphs.each do |key, val|
|
13
19
|
val.graph!
|
14
20
|
output_dir = File.expand_path(File.join(MetricFu::Io::FileSystem.directory('output_directory')))
|
15
|
-
lambda{ File.
|
21
|
+
lambda{ File.read(File.join(output_dir, "#{key.to_s.downcase}.js")) }.should_not raise_error
|
16
22
|
end
|
17
23
|
end
|
18
24
|
end
|
@@ -4,10 +4,6 @@ require 'metric_fu/cli/client'
|
|
4
4
|
describe MetricFu do
|
5
5
|
let(:helper) { MetricFu::Cli::Helper.new }
|
6
6
|
|
7
|
-
before(:all) do
|
8
|
-
MetricFu.configuration.configure_graph_engine(:bluff)
|
9
|
-
end
|
10
|
-
|
11
7
|
before do
|
12
8
|
setup_fs
|
13
9
|
end
|
@@ -43,13 +39,6 @@ describe MetricFu do
|
|
43
39
|
|
44
40
|
end
|
45
41
|
|
46
|
-
it "loads the .metrics file" do
|
47
|
-
# Global only for testing that this file gets loaded
|
48
|
-
$metric_file_loaded = false
|
49
|
-
metric_fu
|
50
|
-
$metric_file_loaded.should be_true
|
51
|
-
end
|
52
|
-
|
53
42
|
it "creates a report yaml file" do
|
54
43
|
expect { metric_fu }.to create_file("#{base_directory}/report.yml")
|
55
44
|
end
|
@@ -187,14 +176,20 @@ describe MetricFu do
|
|
187
176
|
end
|
188
177
|
|
189
178
|
def metric_fu(options = "--no-open")
|
190
|
-
|
179
|
+
message = ''
|
180
|
+
out = MfDebugger::Logger.capture_output {
|
191
181
|
begin
|
192
182
|
argv = Shellwords.shellwords(options)
|
193
183
|
MetricFu::Cli::Client.new.run(argv)
|
194
|
-
rescue SystemExit
|
195
184
|
# Catch system exit so that it doesn't halt spec.
|
185
|
+
rescue SystemExit => system_exit
|
186
|
+
status = system_exit.success? ? "SUCCESS" : "FAILURE"
|
187
|
+
message << "#{status} with code #{system_exit.status}: " <<
|
188
|
+
"#{system_exist.message} #{system_exit.backtrace}"
|
196
189
|
end
|
197
190
|
}
|
191
|
+
STDERR.puts message if message.start_with?('FAILURE')
|
192
|
+
out
|
198
193
|
end
|
199
194
|
|
200
195
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,17 +1,27 @@
|
|
1
|
+
require 'rspec/autorun'
|
2
|
+
|
1
3
|
if ENV['COVERAGE']
|
2
4
|
require 'simplecov'
|
3
|
-
|
4
|
-
|
5
|
+
formatters = [SimpleCov::Formatter::HTMLFormatter]
|
6
|
+
begin
|
7
|
+
puts '[COVERAGE] Running with SimpleCov HTML Formatter'
|
8
|
+
require 'simplecov-rcov-text'
|
9
|
+
formatters << SimpleCov::Formatter::RcovTextFormatter
|
10
|
+
puts '[COVERAGE] Running with SimpleCov Rcov Formatter'
|
11
|
+
rescue LoadError
|
12
|
+
puts '[COVERAGE] SimpleCov Rcov formatter could not be loaded'
|
13
|
+
end
|
14
|
+
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[ *formatters ]
|
5
15
|
SimpleCov.start
|
6
16
|
end
|
7
17
|
|
8
|
-
require 'rspec/autorun'
|
9
18
|
require 'date'
|
10
19
|
require 'construct'
|
11
20
|
require 'json'
|
21
|
+
require 'pry-nav'
|
12
22
|
|
13
23
|
# add lib to the load path just like rubygems does
|
14
|
-
$:.
|
24
|
+
$:.unshift File.expand_path("../../lib", __FILE__)
|
15
25
|
require 'metric_fu'
|
16
26
|
include MetricFu
|
17
27
|
def mf_log(msg); mf_debug(msg); end
|
@@ -21,11 +31,26 @@ def mf_log(msg); mf_debug(msg); end
|
|
21
31
|
Dir[MetricFu.root_dir + "/spec/support/**/*.rb"].each {|f| require f}
|
22
32
|
|
23
33
|
RSpec.configure do |config|
|
34
|
+
config.mock_with :rspec
|
35
|
+
|
36
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
37
|
+
config.filter_run focus: true
|
38
|
+
config.run_all_when_everything_filtered = true
|
39
|
+
config.filter_run_excluding :slow unless ENV["SLOW_SPECS"]
|
40
|
+
config.fail_fast = ENV.include?('FAIL_FAST')
|
41
|
+
config.order = 'random'
|
42
|
+
|
24
43
|
# :suite after/before all specs
|
25
44
|
# :each every describe block
|
26
45
|
# :all every it block
|
27
46
|
|
28
|
-
|
47
|
+
def run_dir
|
48
|
+
File.expand_path('dummy', File.dirname(__FILE__))
|
49
|
+
end
|
50
|
+
|
51
|
+
config.before(:suite) do
|
52
|
+
MetricFu.run_dir = run_dir
|
53
|
+
end
|
29
54
|
|
30
55
|
config.after(:suite) do
|
31
56
|
cleanup_fs
|
@@ -0,0 +1,34 @@
|
|
1
|
+
class DeferredGarbageCollection
|
2
|
+
|
3
|
+
DEFERRED_GC_THRESHOLD = (ENV['DEFER_GC'] || 15.0).to_f
|
4
|
+
|
5
|
+
@@last_gc_run = Time.now
|
6
|
+
|
7
|
+
def self.start
|
8
|
+
GC.disable if DEFERRED_GC_THRESHOLD > 0
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.reconsider
|
12
|
+
if DEFERRED_GC_THRESHOLD > 0 && Time.now - @@last_gc_run >= DEFERRED_GC_THRESHOLD
|
13
|
+
GC.enable
|
14
|
+
GC.start
|
15
|
+
GC.disable
|
16
|
+
@@last_gc_run = Time.now
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.configure(config)
|
21
|
+
return if defined?(JRUBY_VERSION)
|
22
|
+
config.before(:all) do
|
23
|
+
DeferredGarbageCollection.start
|
24
|
+
end
|
25
|
+
|
26
|
+
config.after(:all) do
|
27
|
+
DeferredGarbageCollection.reconsider
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
RSpec.configure do |config|
|
33
|
+
DeferredGarbageCollection.configure(config)
|
34
|
+
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
def metric_not_activated?(metric_name)
|
2
2
|
MetricFu.configuration.configure_metrics
|
3
|
-
if MetricFu::Metric.get_metric(metric_name.intern).
|
3
|
+
if MetricFu::Metric.get_metric(metric_name.intern).activate
|
4
4
|
false
|
5
5
|
else
|
6
6
|
p "Skipping #{metric_name} tests, not activated"
|
@@ -13,20 +13,6 @@ def breaks_when?(bool)
|
|
13
13
|
bool
|
14
14
|
end
|
15
15
|
|
16
|
-
def read_resource(path_in_resources)
|
17
|
-
File.read("#{resources_path}/#{path_in_resources}")
|
18
|
-
end
|
19
|
-
|
20
|
-
def metric_data(path_in_resources)
|
21
|
-
metric_path = read_resource("yml/#{path_in_resources}")
|
22
|
-
YAML.load( metric_path )
|
23
|
-
end
|
24
|
-
|
25
|
-
def resources_path
|
26
|
-
"#{MetricFu.root_dir}/spec/resources"
|
27
|
-
# directory(name)
|
28
|
-
end
|
29
|
-
|
30
16
|
def compare_paths(path1, path2)
|
31
17
|
File.join(MetricFu.root_dir, path1).should == File.join(MetricFu.root_dir, path2)
|
32
18
|
end
|
data/spec/support/suite.rb
CHANGED
@@ -7,40 +7,20 @@ def scratch_directory(name)
|
|
7
7
|
File.join(MetricFu::Io::FileSystem.artifact_dir, 'scratch', name)
|
8
8
|
end
|
9
9
|
|
10
|
-
# fakefs doesn't seem to work reliably on non-mri rubies
|
11
|
-
def using_fake_filesystem
|
12
|
-
return false unless MetricFu.configuration.mri?
|
13
|
-
require 'fakefs/safe'
|
14
|
-
true
|
15
|
-
rescue NameError, LoadError
|
16
|
-
warn "Fake filesystem not available"
|
17
|
-
false
|
18
|
-
end
|
19
|
-
|
20
10
|
def artifact_test_dir
|
21
11
|
@artficat_test_dir ||= File.join(MetricFu::APP_ROOT, 'tmp','metric_fu','test')
|
22
12
|
end
|
23
13
|
|
14
|
+
# Let's shift the output directories so that we don't interfere with
|
15
|
+
# existing historical metric data.
|
24
16
|
MetricFu::Io::FileSystem.artifact_dir = artifact_test_dir
|
25
17
|
MetricFu::Io::FileSystem.set_directories
|
26
18
|
|
27
19
|
def setup_fs
|
28
|
-
|
29
|
-
# # existing historical metric data.
|
30
|
-
if using_fake_filesystem
|
31
|
-
FakeFS.activate!
|
32
|
-
FakeFS::FileSystem.clone('lib')
|
33
|
-
FakeFS::FileSystem.clone('.metrics')
|
34
|
-
end
|
20
|
+
cleanup_fs
|
35
21
|
MetricFu::Io::FileSystem.set_directories
|
36
22
|
end
|
37
23
|
|
38
24
|
def cleanup_fs
|
39
|
-
|
40
|
-
FakeFS::FileSystem.clear
|
41
|
-
FakeFS.deactivate!
|
42
|
-
else
|
43
|
-
# Not ideal, but workaround for non-mri rubies
|
44
|
-
FileUtils.rm_rf(artifact_test_dir)
|
45
|
-
end
|
25
|
+
FileUtils.rm_rf(artifact_test_dir)
|
46
26
|
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'pathname'
|
2
|
+
class TestFixtures
|
3
|
+
|
4
|
+
attr_reader :fixtures_path
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
@loaded_data = {}
|
8
|
+
@fixtures_path = Pathname(MetricFu.root_dir).join('spec','fixtures')
|
9
|
+
end
|
10
|
+
|
11
|
+
def load_metric(path)
|
12
|
+
retrieve_data(path) do |path|
|
13
|
+
YAML.load_file( fixture_path(path) )
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def load_file(path)
|
18
|
+
retrieve_data(path) do |path|
|
19
|
+
File.read( fixture_path(path) )
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def fixture_path(path)
|
24
|
+
fixtures_path.join(*Array(path))
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def retrieve_data(path)
|
30
|
+
@loaded_data.fetch(path) do
|
31
|
+
@loaded_data[path] = yield(path)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
FIXTURE = TestFixtures.new
|
37
|
+
HOTSPOT_DATA = ->(paths) {
|
38
|
+
FIXTURE.load_metric( ['hotspots'].concat(Array(paths)) )
|
39
|
+
}
|