metric_fu 4.6.0 → 4.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (97) hide show
  1. data.tar.gz.sig +0 -0
  2. data/.metrics +6 -0
  3. data/.travis.yml +6 -5
  4. data/CONTRIBUTING.md +15 -3
  5. data/Gemfile +3 -8
  6. data/Gemfile.devtools +3 -3
  7. data/HISTORY.md +23 -2
  8. data/README.md +42 -38
  9. data/checksum/metric_fu-4.6.0.gem.sha512 +1 -0
  10. data/gemfiles/Gemfile.travis +7 -0
  11. data/lib/metric_fu/cli/helper.rb +2 -1
  12. data/lib/metric_fu/configuration.rb +0 -2
  13. data/lib/metric_fu/formatter/html.rb +2 -0
  14. data/lib/metric_fu/formatter/syntax.rb +47 -0
  15. data/lib/metric_fu/gem_version.rb +44 -11
  16. data/lib/metric_fu/io.rb +5 -5
  17. data/lib/metric_fu/loader.rb +12 -5
  18. data/lib/metric_fu/metric.rb +10 -0
  19. data/lib/metric_fu/metrics/base_template.rb +2 -2
  20. data/lib/metric_fu/metrics/cane/cane.rb +1 -0
  21. data/lib/metric_fu/metrics/churn/churn.rb +16 -42
  22. data/lib/metric_fu/metrics/churn/init.rb +7 -1
  23. data/lib/metric_fu/metrics/hotspots/analysis/groupings.rb +1 -0
  24. data/lib/metric_fu/metrics/hotspots/analysis/problems.rb +1 -0
  25. data/lib/metric_fu/metrics/hotspots/analysis/ranked_problem_location.rb +2 -0
  26. data/lib/metric_fu/metrics/hotspots/analysis/rankings.rb +5 -0
  27. data/lib/metric_fu/metrics/hotspots/hotspot.rb +3 -0
  28. data/lib/metric_fu/metrics/hotspots/hotspot_analyzer.rb +8 -4
  29. data/lib/metric_fu/metrics/hotspots/hotspots.rb +11 -0
  30. data/lib/metric_fu/metrics/reek/reek.rb +1 -1
  31. data/lib/metric_fu/metrics/reek/reek_hotspot.rb +0 -1
  32. data/lib/metric_fu/metrics/saikuro/saikuro.rb +1 -0
  33. data/lib/metric_fu/reporting/graphs/grapher.rb +0 -1
  34. data/lib/metric_fu/reporting/templates/awesome/awesome_template.rb +8 -59
  35. data/lib/metric_fu/run.rb +1 -1
  36. data/lib/metric_fu/{reporting/templates/awesome → templates}/css/bluff.css +0 -0
  37. data/lib/metric_fu/{reporting/templates/awesome → templates}/css/buttons.css +0 -0
  38. data/lib/metric_fu/{reporting/templates/awesome → templates}/css/default.css +0 -0
  39. data/lib/metric_fu/{reporting/templates/awesome → templates}/css/integrity.css +0 -0
  40. data/lib/metric_fu/{reporting/templates/awesome → templates}/css/rcov.css +0 -0
  41. data/lib/metric_fu/{reporting/templates/awesome → templates}/css/reset.css +0 -0
  42. data/lib/metric_fu/{reporting/templates/awesome → templates}/css/syntax.css +0 -0
  43. data/lib/metric_fu/templates/report.html.erb +32 -0
  44. data/lib/metric_fu/templates/report.rb +36 -0
  45. data/lib/metric_fu/utility.rb +4 -0
  46. data/lib/metric_fu/version.rb +1 -1
  47. data/metric_fu.gemspec +11 -2
  48. data/spec/cli/helper_spec.rb +33 -33
  49. data/spec/metric_fu/configuration_spec.rb +20 -20
  50. data/spec/metric_fu/data_structures/line_numbers_spec.rb +12 -11
  51. data/spec/metric_fu/data_structures/location_spec.rb +27 -26
  52. data/spec/metric_fu/formatter/html_spec.rb +18 -8
  53. data/spec/metric_fu/formatter/yaml_spec.rb +14 -3
  54. data/spec/metric_fu/formatter_spec.rb +5 -5
  55. data/spec/metric_fu/loader_spec.rb +1 -1
  56. data/spec/metric_fu/metric_spec.rb +2 -2
  57. data/spec/metric_fu/metrics/base_template_spec.rb +50 -50
  58. data/spec/metric_fu/metrics/cane/cane_spec.rb +29 -28
  59. data/spec/metric_fu/metrics/churn/churn_spec.rb +10 -33
  60. data/spec/metric_fu/metrics/flay/flay_grapher_spec.rb +9 -8
  61. data/spec/metric_fu/metrics/flay/flay_spec.rb +14 -13
  62. data/spec/metric_fu/metrics/flog/flog_grapher_spec.rb +16 -15
  63. data/spec/metric_fu/metrics/flog/flog_spec.rb +10 -9
  64. data/spec/metric_fu/metrics/generator_spec.rb +19 -19
  65. data/spec/metric_fu/metrics/graph_spec.rb +11 -9
  66. data/spec/metric_fu/metrics/hotspots/analysis/analyzed_problems_spec.rb +5 -0
  67. data/spec/metric_fu/metrics/hotspots/analysis/analyzer_tables_spec.rb +11 -6
  68. data/spec/metric_fu/metrics/hotspots/analysis/ranking_spec.rb +4 -3
  69. data/spec/metric_fu/metrics/hotspots/analysis/rankings_spec.rb +16 -10
  70. data/spec/metric_fu/metrics/hotspots/analysis/table_spec.rb +2 -1
  71. data/spec/metric_fu/metrics/hotspots/hotspot_analyzer_spec.rb +2 -1
  72. data/spec/metric_fu/metrics/hotspots/hotspot_spec.rb +8 -2
  73. data/spec/metric_fu/metrics/hotspots/hotspots_spec.rb +4 -8
  74. data/spec/metric_fu/metrics/rails_best_practices/rails_best_practices_grapher_spec.rb +10 -9
  75. data/spec/metric_fu/metrics/rails_best_practices/rails_best_practices_spec.rb +8 -7
  76. data/spec/metric_fu/metrics/rcov/rcov_grapher_spec.rb +8 -8
  77. data/spec/metric_fu/metrics/rcov/rcov_hotspot_spec.rb +7 -4
  78. data/spec/metric_fu/metrics/rcov/rcov_spec.rb +15 -14
  79. data/spec/metric_fu/metrics/reek/reek_grapher_spec.rb +10 -9
  80. data/spec/metric_fu/metrics/reek/reek_spec.rb +17 -15
  81. data/spec/metric_fu/metrics/roodi/roodi_grapher_spec.rb +9 -8
  82. data/spec/metric_fu/metrics/roodi/roodi_spec.rb +4 -3
  83. data/spec/metric_fu/metrics/saikuro/saikuro_spec.rb +13 -10
  84. data/spec/metric_fu/metrics/stats/stats_grapher_spec.rb +13 -12
  85. data/spec/metric_fu/metrics/stats/stats_spec.rb +16 -14
  86. data/spec/metric_fu/reporter_spec.rb +8 -7
  87. data/spec/metric_fu/reporting/graphs/grapher_spec.rb +1 -1
  88. data/spec/metric_fu/reporting/result_spec.rb +12 -11
  89. data/spec/metric_fu/run_spec.rb +24 -8
  90. data/spec/spec_helper.rb +1 -2
  91. data/spec/support/helper_methods.rb +14 -1
  92. metadata +124 -57
  93. metadata.gz.sig +0 -0
  94. checksums.yaml +0 -7
  95. checksums.yaml.gz.sig +0 -0
  96. data/lib/metric_fu/initial_requires.rb +0 -13
  97. data/lib/metric_fu/load_files.rb +0 -34
@@ -1,19 +1,20 @@
1
1
  require "spec_helper"
2
+ MetricFu.metrics_require { 'roodi/roodi' }
2
3
 
3
4
  describe MetricFu::RoodiGenerator do
4
5
  describe "emit" do
5
6
  it "should add config options when present" do
6
7
  options = {:roodi_config => 'lib/config/roodi_config.yml', :dirs_to_roodi => []}
7
8
  roodi = MetricFu::RoodiGenerator.new(options)
8
- roodi.should_receive(:run!).with(/-config=lib\/config\/roodi_config\.yml/).and_return("")
9
+ expect(roodi).to receive(:run!).with(/-config=lib\/config\/roodi_config\.yml/).and_return("")
9
10
  roodi.emit
10
11
  end
11
12
 
12
13
  it "should NOT add config options when NOT present" do
13
14
  options = {:dirs_to_roodi => []}
14
15
  roodi = MetricFu::RoodiGenerator.new(options)
15
- roodi.stub(:run!)
16
- roodi.should_receive(:run!).with(/-config/).never
16
+ allow(roodi).to receive(:run!)
17
+ expect(roodi).to receive(:run!).with(/-config/).never
17
18
  roodi.emit
18
19
  end
19
20
  end
@@ -1,4 +1,5 @@
1
1
  require "spec_helper"
2
+ MetricFu.metrics_require { 'saikuro/saikuro' }
2
3
 
3
4
  describe MetricFu::SaikuroGenerator do
4
5
  STUB_TEST_DATA = lambda do |generator|
@@ -6,7 +7,9 @@ describe MetricFu::SaikuroGenerator do
6
7
  def generator.metric_directory
7
8
  FIXTURE.fixtures_path.join("saikuro").to_s
8
9
  end
9
- generator.stub(:clear_scratch_files!)
10
+ def generator.clear_scratch_files!
11
+ # no-op
12
+ end
10
13
  end
11
14
  describe "to_h method" do
12
15
  before do
@@ -19,25 +22,25 @@ describe MetricFu::SaikuroGenerator do
19
22
  end
20
23
 
21
24
  it "should find the filename of a file" do
22
- @output[:saikuro][:files].first[:filename].should == 'app/controllers/users_controller.rb'
25
+ expect(@output[:saikuro][:files].first[:filename]).to eq('app/controllers/users_controller.rb')
23
26
  end
24
27
 
25
28
  it "should find the name of the classes" do
26
- @output[:saikuro][:classes].first[:name].should == "UsersController"
27
- @output[:saikuro][:classes][1][:name].should == "SessionsController"
29
+ expect(@output[:saikuro][:classes].first[:name]).to eq("UsersController")
30
+ expect(@output[:saikuro][:classes][1][:name]).to eq("SessionsController")
28
31
  end
29
32
 
30
33
  it "should put the most complex method first" do
31
- @output[:saikuro][:methods].first[:name].should == "UsersController#create"
32
- @output[:saikuro][:methods].first[:complexity].should == 4
34
+ expect(@output[:saikuro][:methods].first[:name]).to eq("UsersController#create")
35
+ expect(@output[:saikuro][:methods].first[:complexity]).to eq(4)
33
36
  end
34
37
 
35
38
  it "should find the complexity of a method" do
36
- @output[:saikuro][:methods].first[:complexity].should == 4
39
+ expect(@output[:saikuro][:methods].first[:complexity]).to eq(4)
37
40
  end
38
41
 
39
42
  it "should find the lines of a method" do
40
- @output[:saikuro][:methods].first[:lines].should == 15
43
+ expect(@output[:saikuro][:methods].first[:lines]).to eq(15)
41
44
  end
42
45
  end
43
46
 
@@ -51,7 +54,7 @@ describe MetricFu::SaikuroGenerator do
51
54
  end
52
55
 
53
56
  it "doesn't try to get information if the file does not exist" do
54
- @saikuro.should_receive(:file_not_exists?).at_least(:once).and_return(true)
57
+ expect(@saikuro).to receive(:file_not_exists?).at_least(:once).and_return(true)
55
58
  @saikuro.per_file_info('ignore_me')
56
59
  end
57
60
  end
@@ -61,7 +64,7 @@ describe MetricFu::SaikuroGenerator do
61
64
  it "should parse nested START/END sections" do
62
65
  path = FIXTURE.fixtures_path.join("saikuro_sfiles", "thing.rb_cyclo.html").to_s
63
66
  sfile = MetricFu::SaikuroScratchFile.new path
64
- sfile.elements.map { |e| e.complexity }.sort.should eql(["0","0","2"])
67
+ expect(sfile.elements.map { |e| e.complexity }.sort).to eql(["0","0","2"])
65
68
  end
66
69
  end
67
70
  end
@@ -1,4 +1,5 @@
1
1
  require "spec_helper"
2
+ MetricFu.metrics_require { 'stats/stats_grapher' }
2
3
 
3
4
  describe StatsGrapher do
4
5
  before :each do
@@ -7,16 +8,16 @@ describe StatsGrapher do
7
8
  end
8
9
 
9
10
  it "should respond to loc_counts and lot_counts and labels" do
10
- @stats_grapher.should respond_to(:loc_counts)
11
- @stats_grapher.should respond_to(:lot_counts)
12
- @stats_grapher.should respond_to(:labels)
11
+ expect(@stats_grapher).to respond_to(:loc_counts)
12
+ expect(@stats_grapher).to respond_to(:lot_counts)
13
+ expect(@stats_grapher).to respond_to(:labels)
13
14
  end
14
15
 
15
16
  describe "responding to #initialize" do
16
17
  it "should initialise loc_counts and lot_counts and labels" do
17
- @stats_grapher.loc_counts.should == []
18
- @stats_grapher.lot_counts.should == []
19
- @stats_grapher.labels.should == {}
18
+ expect(@stats_grapher.loc_counts).to eq([])
19
+ expect(@stats_grapher.lot_counts).to eq([])
20
+ expect(@stats_grapher.labels).to eq({})
20
21
  end
21
22
  end
22
23
 
@@ -28,17 +29,17 @@ describe StatsGrapher do
28
29
  end
29
30
 
30
31
  it "should not push to loc_counts" do
31
- @stats_grapher.loc_counts.should_not_receive(:push)
32
+ expect(@stats_grapher.loc_counts).not_to receive(:push)
32
33
  @stats_grapher.get_metrics(@metrics, @date)
33
34
  end
34
35
 
35
36
  it "should not push to lot_counts" do
36
- @stats_grapher.lot_counts.should_not_receive(:push)
37
+ expect(@stats_grapher.lot_counts).not_to receive(:push)
37
38
  @stats_grapher.get_metrics(@metrics, @date)
38
39
  end
39
40
 
40
41
  it "should not update labels with the date" do
41
- @stats_grapher.labels.should_not_receive(:update)
42
+ expect(@stats_grapher.labels).not_to receive(:update)
42
43
  @stats_grapher.get_metrics(@metrics, @date)
43
44
  end
44
45
  end
@@ -50,17 +51,17 @@ describe StatsGrapher do
50
51
  end
51
52
 
52
53
  it "should push to loc_counts" do
53
- @stats_grapher.loc_counts.should_receive(:push).with(15935)
54
+ expect(@stats_grapher.loc_counts).to receive(:push).with(15935)
54
55
  @stats_grapher.get_metrics(@metrics, @date)
55
56
  end
56
57
 
57
58
  it "should push to lot_counts" do
58
- @stats_grapher.lot_counts.should_receive(:push).with(7438)
59
+ expect(@stats_grapher.lot_counts).to receive(:push).with(7438)
59
60
  @stats_grapher.get_metrics(@metrics, @date)
60
61
  end
61
62
 
62
63
  it "should update labels with the date" do
63
- @stats_grapher.labels.should_receive(:update).with({ 0 => "01022003" })
64
+ expect(@stats_grapher.labels).to receive(:update).with({ 0 => "01022003" })
64
65
  @stats_grapher.get_metrics(@metrics, @date)
65
66
  end
66
67
  end
@@ -1,16 +1,18 @@
1
1
  require "spec_helper"
2
+ MetricFu.metrics_require { 'stats/stats' }
2
3
 
3
4
  describe StatsGenerator do
4
5
  describe "emit method" do
5
6
  it "should gather the raw data" do
6
7
  ENV['CC_BUILD_ARTIFACTS'] = nil
7
8
  MetricFu.configure.reset
8
- File.stub(:directory?).and_return(true)
9
+ allow(File).to receive(:directory?).and_return(true)
9
10
  stats = MetricFu::StatsGenerator.new
10
11
  stats.emit
11
12
  end
12
13
  end
13
14
 
15
+ #TODO review tested output
14
16
  describe "analyze method" do
15
17
  before :each do
16
18
  @lines = <<-HERE.gsub(/^\s*/, "")
@@ -34,32 +36,32 @@ describe StatsGenerator do
34
36
  HERE
35
37
  ENV['CC_BUILD_ARTIFACTS'] = nil
36
38
  MetricFu.configure.reset
37
- File.stub(:directory?).and_return(true)
39
+ allow(File).to receive(:directory?).and_return(true)
38
40
  stats = MetricFu::StatsGenerator.new
39
41
  stats.instance_variable_set('@output', @lines)
40
42
  @results = stats.analyze
41
43
  end
42
44
 
43
45
  it "should get code Lines Of Code" do
44
- @results[:codeLOC].should == 915
46
+ expect(@results[:codeLOC]).to eq(915)
45
47
  end
46
48
 
47
49
  it "should get test Lines Of Code" do
48
- @results[:testLOC].should == 2226
50
+ expect(@results[:testLOC]).to eq(2226)
49
51
  end
50
52
 
51
53
  it "should get code to test ratio" do
52
- @results[:code_to_test_ratio].should == 2.4
54
+ expect(@results[:code_to_test_ratio]).to eq(2.4)
53
55
  end
54
56
 
55
57
  it "should get data on models" do
56
58
  model_data = @results[:lines].find {|line| line[:name] == "Models"}
57
- model_data[:classes].should == 9
58
- model_data[:methods].should == 31
59
- model_data[:loc].should == 285
60
- model_data[:lines].should == 351
61
- model_data[:methods_per_class].should == 3
62
- model_data[:loc_per_method].should == 7
59
+ expect(model_data[:classes]).to eq(9)
60
+ expect(model_data[:methods]).to eq(31)
61
+ expect(model_data[:loc]).to eq(285)
62
+ expect(model_data[:lines]).to eq(351)
63
+ expect(model_data[:methods_per_class]).to eq(3)
64
+ expect(model_data[:loc_per_method]).to eq(7)
63
65
  end
64
66
 
65
67
  it 'handles code to test ratio is ratio is 1:NaN' do
@@ -73,7 +75,7 @@ describe StatsGenerator do
73
75
  HERE
74
76
  ENV['CC_BUILD_ARTIFACTS'] = nil
75
77
  MetricFu.configure.reset
76
- File.stub(:directory?).and_return(true)
78
+ allow(File).to receive(:directory?).and_return(true)
77
79
  stats = MetricFu::StatsGenerator.new(MetricFu::Metric.get_metric(:stats).run_options)
78
80
  stats.instance_variable_set('@output', lines)
79
81
  @results = stats.analyze
@@ -85,10 +87,10 @@ describe StatsGenerator do
85
87
  it "should put things into a hash" do
86
88
  ENV['CC_BUILD_ARTIFACTS'] = nil
87
89
  MetricFu.configure.reset
88
- File.stub(:directory?).and_return(true)
90
+ allow(File).to receive(:directory?).and_return(true)
89
91
  stats = MetricFu::StatsGenerator.new
90
92
  stats.instance_variable_set(:@stats, "the_stats")
91
- stats.to_h[:stats].should == "the_stats"
93
+ expect(stats.to_h[:stats]).to eq("the_stats")
92
94
  end
93
95
  end
94
96
  end
@@ -1,24 +1,25 @@
1
1
  require "spec_helper"
2
+ MetricFu.lib_require { 'reporter' }
2
3
 
3
4
  describe MetricFu::Reporter do
4
5
 
5
6
  context 'given a single formatter' do
6
7
  before do
7
8
  @formatter = double('formatter')
8
- @formatter.stub(:to_a).and_return([@formatter])
9
+ allow(@formatter).to receive(:to_a).and_return([@formatter])
9
10
  @reporter = Reporter.new(@formatter)
10
11
  end
11
12
 
12
13
  it 'notifies the formatter' do
13
- @formatter.should_receive(:start)
14
- @formatter.should_receive(:finish)
14
+ expect(@formatter).to receive(:start)
15
+ expect(@formatter).to receive(:finish)
15
16
  @reporter.start
16
17
  @reporter.finish
17
18
  end
18
19
 
19
20
  it 'only sends notifications when supported by formatter' do
20
- @formatter.stub(:respond_to?).with(:display_results).and_return(false)
21
- @formatter.should_not_receive(:display_results)
21
+ allow(@formatter).to receive(:respond_to?).with(:display_results).and_return(false)
22
+ expect(@formatter).not_to receive(:display_results)
22
23
  @reporter.display_results
23
24
  end
24
25
  end
@@ -31,8 +32,8 @@ describe MetricFu::Reporter do
31
32
 
32
33
  it 'notifies all formatters' do
33
34
  @formatters.each do |formatter|
34
- formatter.should_receive(:start)
35
- formatter.should_receive(:finish)
35
+ expect(formatter).to receive(:start)
36
+ expect(formatter).to receive(:finish)
36
37
  end
37
38
  @reporter.start
38
39
  @reporter.finish
@@ -18,7 +18,7 @@ describe "Bluff graphers responding to #graph!" do
18
18
  graphs.each do |key, val|
19
19
  val.graph!
20
20
  output_dir = File.expand_path(File.join(MetricFu::Io::FileSystem.directory('output_directory')))
21
- lambda{ File.read(File.join(output_dir, "#{key.to_s.downcase}.js")) }.should_not raise_error
21
+ expect{ File.read(File.join(output_dir, "#{key.to_s.downcase}.js")) }.not_to raise_error
22
22
  end
23
23
  end
24
24
  end
@@ -1,10 +1,11 @@
1
1
  require "spec_helper"
2
+ MetricFu.reporting_require { 'result' }
2
3
 
3
4
  describe MetricFu do
4
5
 
5
6
  describe "#result" do
6
7
  it 'should return an instance of Result' do
7
- MetricFu.result.instance_of?(Result).should be(true)
8
+ expect(MetricFu.result.instance_of?(Result)).to be(true)
8
9
  end
9
10
  end
10
11
  end
@@ -18,9 +19,9 @@ describe MetricFu::Result do
18
19
  describe "#as_yaml" do
19
20
  it 'should call #result_hash' do
20
21
  result_hash = double('result_hash')
21
- result_hash.should_receive(:to_yaml)
22
+ expect(result_hash).to receive(:to_yaml)
22
23
 
23
- @result.should_receive(:result_hash).and_return(result_hash)
24
+ expect(@result).to receive(:result_hash).and_return(result_hash)
24
25
  @result.as_yaml
25
26
  end
26
27
  end
@@ -31,20 +32,20 @@ describe MetricFu::Result do
31
32
  describe "#add" do
32
33
  it 'should add a passed hash to the result_hash instance variable' do
33
34
  result_type = double('result_type')
34
- result_type.stub(:to_s).and_return('type')
35
+ allow(result_type).to receive(:to_s).and_return('type')
35
36
 
36
37
  result_inst = double('result_inst')
37
- result_type.should_receive(:new).and_return(result_inst)
38
+ expect(result_type).to receive(:new).and_return(result_inst)
38
39
 
39
- result_inst.should_receive(:generate_result).and_return({:a => 'b'})
40
- result_inst.should_receive(:respond_to?).and_return(false)
40
+ expect(result_inst).to receive(:generate_result).and_return({:a => 'b'})
41
+ expect(result_inst).to receive(:respond_to?).and_return(false)
41
42
 
42
- MetricFu::Generator.should_receive(:get_generator).
43
+ expect(MetricFu::Generator).to receive(:get_generator).
43
44
  with(result_type).and_return(result_type)
44
45
  result_hash = double('result_hash')
45
- result_hash.should_receive(:merge!).with({:a => 'b'})
46
- @result.should_receive(:result_hash).and_return(result_hash)
47
- @result.should_receive(:metric_options_for_result_type).with(result_type)
46
+ expect(result_hash).to receive(:merge!).with({:a => 'b'})
47
+ expect(@result).to receive(:result_hash).and_return(result_hash)
48
+ expect(@result).to receive(:metric_options_for_result_type).with(result_type)
48
49
  @result.add(result_type)
49
50
  end
50
51
  end
@@ -29,9 +29,18 @@ describe MetricFu do
29
29
  # limited set, so we can test the basic functionality
30
30
  # without significantly slowing down the specs.
31
31
  MetricFu.configuration.configure_metrics do |metric|
32
- if metric.name == :churn
32
+ if metric.name == :reek
33
33
  metric.enable
34
34
  metric.activated = true
35
+ # so this doesn't seem to always be true
36
+ # @bf4 adding that line you thought I didn't need made tests pass for me
37
+ # but they failed on one of the travis builds.
38
+ # swapping this line all seem to pass every run
39
+ # I don't understand what is happening in run_external well enough
40
+ # need some help debugging
41
+ # but tests seem more stable without it.
42
+ # metric.should_receive(:run_external).and_return('')
43
+ allow(metric).to receive(:run_external).and_return('')
35
44
  else
36
45
  metric.enabled = false
37
46
  end
@@ -156,17 +165,22 @@ describe MetricFu do
156
165
 
157
166
  it "displays help" do
158
167
  out = metric_fu "--help"
159
- out.should include helper.banner
168
+ expect(out).to include helper.banner
160
169
  end
161
170
 
162
171
  it "displays version" do
163
172
  out = metric_fu "--version"
164
- out.should include "#{MetricFu::VERSION}"
173
+ expect(out).to include "#{MetricFu::VERSION}"
165
174
  end
166
175
 
167
176
  it "errors on unknown flags" do
168
- out = metric_fu "--asdasdasda"
169
- out.should include 'invalid option'
177
+ failure = false
178
+ out = metric_fu "--asdasdasda" do |message|
179
+ # swallow the error message
180
+ failure = true
181
+ end
182
+ expect(out).to include 'invalid option'
183
+ expect(failure).to be_truthy
170
184
  end
171
185
 
172
186
  end
@@ -184,11 +198,13 @@ describe MetricFu do
184
198
  # Catch system exit so that it doesn't halt spec.
185
199
  rescue SystemExit => system_exit
186
200
  status = system_exit.success? ? "SUCCESS" : "FAILURE"
187
- message << "#{status} with code #{system_exit.status}: " <<
188
- "#{system_exist.message} #{system_exit.backtrace}"
201
+ message << "#{status} with code #{system_exit.status}: "
202
+ message << "#{system_exit.message} #{system_exit.backtrace}"
189
203
  end
190
204
  }
191
- STDERR.puts message if message.start_with?('FAILURE')
205
+ if message.start_with?('FAILURE')
206
+ block_given? ? yield(message) : STDERR.puts(message)
207
+ end
192
208
  out
193
209
  end
194
210
 
data/spec/spec_helper.rb CHANGED
@@ -16,7 +16,7 @@ if ENV['COVERAGE']
16
16
  end
17
17
 
18
18
  require 'date'
19
- require 'construct'
19
+ require 'test_construct'
20
20
  require 'json'
21
21
  require 'pry-nav'
22
22
 
@@ -33,7 +33,6 @@ Dir[MetricFu.root_dir + "/spec/support/**/*.rb"].each {|f| require f}
33
33
  RSpec.configure do |config|
34
34
  config.mock_with :rspec
35
35
 
36
- config.treat_symbols_as_metadata_keys_with_true_values = true
37
36
  config.filter_run focus: true
38
37
  config.run_all_when_everything_filtered = true
39
38
  config.filter_run_excluding :slow unless ENV["SLOW_SPECS"]
@@ -1,3 +1,16 @@
1
+ def enable_hotspots
2
+ MetricFu.configure
3
+ hotspot_metrics = MetricFu::Metric.metrics.map(&:name)
4
+ hotspot_metrics.each do |metric_name|
5
+ path = "#{metric_name}/#{metric_name}_hotspot"
6
+ begin
7
+ MetricFu.metrics_require { path }
8
+ rescue LoadError
9
+ # No hotspot, but that's ok
10
+ end
11
+ end
12
+ end
13
+
1
14
  def metric_not_activated?(metric_name)
2
15
  MetricFu.configuration.configure_metrics
3
16
  if MetricFu::Metric.get_metric(metric_name.intern).activate
@@ -14,5 +27,5 @@ def breaks_when?(bool)
14
27
  end
15
28
 
16
29
  def compare_paths(path1, path2)
17
- File.join(MetricFu.root_dir, path1).should == File.join(MetricFu.root_dir, path2)
30
+ expect(File.join(MetricFu.root_dir, path1)).to eq(File.join(MetricFu.root_dir, path2))
18
31
  end