metric_fu 4.10.0 → 4.11.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (152) hide show
  1. checksums.yaml +8 -8
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +2 -2
  4. data/.simplecov +42 -0
  5. data/.travis.yml +7 -6
  6. data/CONTRIBUTING.md +1 -1
  7. data/DEV.md +4 -3
  8. data/Gemfile +29 -7
  9. data/HISTORY.md +29 -3
  10. data/README.md +6 -1
  11. data/Rakefile +33 -11
  12. data/checksum/metric_fu-4.10.0.gem.sha512 +1 -1
  13. data/gem_tasks/usage_test.rake +0 -11
  14. data/lib/metric_fu.rb +12 -0
  15. data/lib/metric_fu/configuration.rb +1 -5
  16. data/lib/metric_fu/environment.rb +3 -3
  17. data/lib/metric_fu/formatter.rb +1 -1
  18. data/lib/metric_fu/formatter/html.rb +9 -9
  19. data/lib/metric_fu/gem_run.rb +2 -2
  20. data/lib/metric_fu/{metrics/generator.rb → generator.rb} +0 -0
  21. data/lib/metric_fu/loader.rb +30 -23
  22. data/lib/metric_fu/logger.rb +65 -0
  23. data/lib/metric_fu/logging/mf_debugger.rb +13 -48
  24. data/lib/metric_fu/metric.rb +3 -3
  25. data/lib/metric_fu/metrics/cane/{cane.rb → generator.rb} +0 -0
  26. data/lib/metric_fu/metrics/cane/{cane_grapher.rb → grapher.rb} +0 -0
  27. data/lib/metric_fu/metrics/cane/{init.rb → metric.rb} +1 -1
  28. data/lib/metric_fu/metrics/cane/{template_awesome/cane.html.erb → report.html.erb} +0 -0
  29. data/lib/metric_fu/metrics/churn/{churn.rb → generator.rb} +0 -0
  30. data/lib/metric_fu/metrics/churn/{churn_hotspot.rb → hotspot.rb} +0 -0
  31. data/lib/metric_fu/metrics/churn/{init.rb → metric.rb} +0 -0
  32. data/lib/metric_fu/metrics/churn/{template_awesome/churn.html.erb → report.html.erb} +0 -0
  33. data/lib/metric_fu/metrics/flay/{flay.rb → generator.rb} +16 -2
  34. data/lib/metric_fu/metrics/flay/{flay_grapher.rb → grapher.rb} +0 -0
  35. data/lib/metric_fu/metrics/flay/{flay_hotspot.rb → hotspot.rb} +0 -0
  36. data/lib/metric_fu/metrics/flay/{init.rb → metric.rb} +1 -1
  37. data/lib/metric_fu/metrics/flay/{template_awesome/flay.html.erb → report.html.erb} +0 -0
  38. data/lib/metric_fu/metrics/flog/{flog.rb → generator.rb} +0 -0
  39. data/lib/metric_fu/metrics/flog/{flog_grapher.rb → grapher.rb} +0 -0
  40. data/lib/metric_fu/metrics/flog/{flog_hotspot.rb → hotspot.rb} +0 -0
  41. data/lib/metric_fu/metrics/flog/{init.rb → metric.rb} +1 -1
  42. data/lib/metric_fu/metrics/flog/{template_awesome/flog.html.erb → report.html.erb} +0 -0
  43. data/lib/metric_fu/metrics/hotspots/{hotspots.rb → generator.rb} +1 -1
  44. data/lib/metric_fu/metrics/hotspots/{init.rb → metric.rb} +0 -0
  45. data/lib/metric_fu/metrics/hotspots/{template_awesome/hotspots.html.erb → report.html.erb} +0 -0
  46. data/lib/metric_fu/metrics/rails_best_practices/{rails_best_practices.rb → generator.rb} +0 -0
  47. data/lib/metric_fu/metrics/rails_best_practices/{rails_best_practices_grapher.rb → grapher.rb} +0 -0
  48. data/lib/metric_fu/metrics/rails_best_practices/{init.rb → metric.rb} +1 -1
  49. data/lib/metric_fu/metrics/rails_best_practices/{template_awesome/rails_best_practices.html.erb → report.html.erb} +0 -0
  50. data/lib/metric_fu/metrics/rcov/{rcov.rb → generator.rb} +0 -0
  51. data/lib/metric_fu/metrics/rcov/{rcov_grapher.rb → grapher.rb} +0 -0
  52. data/lib/metric_fu/metrics/rcov/{rcov_hotspot.rb → hotspot.rb} +0 -0
  53. data/lib/metric_fu/metrics/rcov/{init.rb → metric.rb} +0 -0
  54. data/lib/metric_fu/metrics/rcov/rcov_format_coverage.rb +57 -9
  55. data/lib/metric_fu/metrics/rcov/{template_awesome/rcov.html.erb → report.html.erb} +0 -0
  56. data/lib/metric_fu/metrics/rcov/simplecov_formatter.rb +13 -2
  57. data/lib/metric_fu/metrics/reek/{reek.rb → generator.rb} +0 -0
  58. data/lib/metric_fu/metrics/reek/{reek_grapher.rb → grapher.rb} +0 -0
  59. data/lib/metric_fu/metrics/reek/{reek_hotspot.rb → hotspot.rb} +1 -1
  60. data/lib/metric_fu/metrics/reek/{init.rb → metric.rb} +0 -0
  61. data/lib/metric_fu/metrics/reek/{template_awesome/reek.html.erb → report.html.erb} +0 -0
  62. data/lib/metric_fu/metrics/roodi/{roodi.rb → generator.rb} +0 -0
  63. data/lib/metric_fu/metrics/roodi/{roodi_grapher.rb → grapher.rb} +0 -0
  64. data/lib/metric_fu/metrics/roodi/{roodi_hotspot.rb → hotspot.rb} +0 -0
  65. data/lib/metric_fu/metrics/roodi/{init.rb → metric.rb} +0 -0
  66. data/lib/metric_fu/metrics/roodi/{template_awesome/roodi.html.erb → report.html.erb} +0 -0
  67. data/lib/metric_fu/metrics/saikuro/{saikuro.rb → generator.rb} +0 -0
  68. data/lib/metric_fu/metrics/saikuro/{saikuro_hotspot.rb → hotspot.rb} +0 -0
  69. data/lib/metric_fu/metrics/saikuro/{init.rb → metric.rb} +0 -0
  70. data/lib/metric_fu/metrics/saikuro/{template_awesome/saikuro.html.erb → report.html.erb} +0 -0
  71. data/lib/metric_fu/metrics/stats/{stats.rb → generator.rb} +1 -1
  72. data/lib/metric_fu/metrics/stats/{stats_grapher.rb → grapher.rb} +0 -0
  73. data/lib/metric_fu/metrics/stats/{stats_hotspot.rb → hotspot.rb} +0 -0
  74. data/lib/metric_fu/metrics/stats/{init.rb → metric.rb} +0 -0
  75. data/lib/metric_fu/metrics/stats/{template_awesome/stats.html.erb → report.html.erb} +0 -0
  76. data/lib/metric_fu/{metrics → reporting/graphs}/graph.rb +0 -0
  77. data/lib/metric_fu/{reporting/templates/awesome → templates}/_graph.html.erb +0 -0
  78. data/lib/metric_fu/{reporting/templates/awesome → templates}/_report_footer.html.erb +0 -0
  79. data/lib/metric_fu/templates/configuration.rb +3 -2
  80. data/lib/metric_fu/{reporting/templates/awesome → templates}/index.html.erb +1 -1
  81. data/lib/metric_fu/{reporting/templates → templates}/javascripts/bluff-min.js +0 -0
  82. data/lib/metric_fu/{reporting/templates → templates}/javascripts/bluff_graph.js +0 -0
  83. data/lib/metric_fu/{reporting/templates → templates}/javascripts/excanvas.js +0 -0
  84. data/lib/metric_fu/{reporting/templates → templates}/javascripts/highcharts.js +0 -0
  85. data/lib/metric_fu/{reporting/templates → templates}/javascripts/highcharts_graph.js +0 -0
  86. data/lib/metric_fu/{reporting/templates → templates}/javascripts/js-class.js +0 -0
  87. data/lib/metric_fu/{reporting/templates → templates}/javascripts/standalone-framework.js +0 -0
  88. data/lib/metric_fu/{reporting/templates → templates}/javascripts/utils.js +0 -0
  89. data/lib/metric_fu/{reporting/templates/awesome → templates}/layout.html.erb +1 -1
  90. data/lib/metric_fu/templates/metrics_template.rb +68 -0
  91. data/lib/metric_fu/templates/report.rb +11 -3
  92. data/lib/metric_fu/{metrics/base_template.rb → templates/template.rb} +8 -24
  93. data/lib/metric_fu/utility.rb +25 -0
  94. data/lib/metric_fu/version.rb +1 -1
  95. data/metric_fu.gemspec +2 -0
  96. data/spec/capture_warnings.rb +48 -0
  97. data/spec/dummy/lib/bad_encoding.rb +6 -0
  98. data/spec/fixtures/coverage-153.rb +11 -0
  99. data/spec/fixtures/rcov_output.txt +135 -0
  100. data/spec/metric_fu/configuration_spec.rb +4 -265
  101. data/spec/metric_fu/formatter/configuration_spec.rb +46 -0
  102. data/spec/metric_fu/formatter/html_spec.rb +17 -25
  103. data/spec/metric_fu/formatter/yaml_spec.rb +1 -1
  104. data/spec/metric_fu/{metrics/generator_spec.rb → generator_spec.rb} +0 -0
  105. data/spec/metric_fu/metrics/cane/configuration_spec.rb +22 -0
  106. data/spec/metric_fu/metrics/cane/{cane_spec.rb → generator_spec.rb} +1 -1
  107. data/spec/metric_fu/metrics/churn/configuration_spec.rb +15 -0
  108. data/spec/metric_fu/metrics/churn/{churn_spec.rb → generator_spec.rb} +1 -1
  109. data/spec/metric_fu/metrics/flay/configuration_spec.rb +15 -0
  110. data/spec/metric_fu/metrics/flay/{flay_spec.rb → generator_spec.rb} +2 -2
  111. data/spec/metric_fu/metrics/flay/{flay_grapher_spec.rb → grapher_spec.rb} +1 -1
  112. data/spec/metric_fu/metrics/flog/configuration_spec.rb +20 -0
  113. data/spec/metric_fu/metrics/flog/{flog_spec.rb → generator_spec.rb} +1 -1
  114. data/spec/metric_fu/metrics/flog/{flog_grapher_spec.rb → grapher_spec.rb} +1 -1
  115. data/spec/metric_fu/metrics/hotspots/{hotspots_spec.rb → generator_spec.rb} +1 -1
  116. data/spec/metric_fu/metrics/rails_best_practices/configuration_spec.rb +47 -0
  117. data/spec/metric_fu/metrics/rails_best_practices/{rails_best_practices_spec.rb → generator_spec.rb} +1 -1
  118. data/spec/metric_fu/metrics/rails_best_practices/{rails_best_practices_grapher_spec.rb → grapher_spec.rb} +1 -1
  119. data/spec/metric_fu/metrics/rcov/configuration_spec.rb +30 -0
  120. data/spec/metric_fu/metrics/rcov/generator_spec.rb +26 -0
  121. data/spec/metric_fu/metrics/rcov/{rcov_grapher_spec.rb → grapher_spec.rb} +1 -1
  122. data/spec/metric_fu/metrics/rcov/{rcov_hotspot_spec.rb → hotspot_spec.rb} +2 -2
  123. data/spec/metric_fu/metrics/rcov/simplecov_formatter_spec.rb +40 -12
  124. data/spec/metric_fu/metrics/reek/configuration_spec.rb +13 -0
  125. data/spec/metric_fu/metrics/reek/{reek_spec.rb → generator_spec.rb} +1 -1
  126. data/spec/metric_fu/metrics/reek/{reek_grapher_spec.rb → grapher_spec.rb} +1 -1
  127. data/spec/metric_fu/metrics/roodi/configuration_spec.rb +16 -0
  128. data/spec/metric_fu/metrics/roodi/{roodi_spec.rb → generator_spec.rb} +1 -1
  129. data/spec/metric_fu/metrics/roodi/{roodi_grapher_spec.rb → grapher_spec.rb} +1 -1
  130. data/spec/metric_fu/metrics/saikuro/configuration_spec.rb +26 -0
  131. data/spec/metric_fu/metrics/saikuro/{saikuro_spec.rb → generator_spec.rb} +1 -1
  132. data/spec/metric_fu/metrics/stats/{stats_spec.rb → generator_spec.rb} +1 -1
  133. data/spec/metric_fu/metrics/stats/{stats_grapher_spec.rb → grapher_spec.rb} +1 -1
  134. data/spec/metric_fu/{metrics → reporting/graphs}/graph_spec.rb +1 -1
  135. data/spec/metric_fu/run_spec.rb +1 -1
  136. data/spec/metric_fu/templates/configuration_spec.rb +57 -0
  137. data/spec/metric_fu/templates/report_spec.rb +15 -0
  138. data/spec/metric_fu/{metrics/base_template_spec.rb → templates/template_spec.rb} +0 -0
  139. data/spec/quality_spec.rb +86 -0
  140. data/spec/shared/configured.rb +47 -0
  141. data/spec/shared/test_coverage.rb +99 -0
  142. data/spec/spec_helper.rb +9 -5
  143. data/spec/support/helper_methods.rb +3 -2
  144. data/spec/support/matcher_create_file.rb +2 -2
  145. data/spec/support/matcher_create_files.rb +2 -2
  146. data/spec/support/usage_test.rb +24 -7
  147. data/spec/usage_test_spec.rb +28 -2
  148. metadata +165 -112
  149. metadata.gz.sig +0 -0
  150. data/Gemfile.devtools +0 -39
  151. data/lib/metric_fu/reporting/templates/awesome/awesome_template.rb +0 -62
  152. data/spec/metric_fu/metrics/rcov/rcov_spec.rb +0 -185
@@ -1,5 +1,5 @@
1
1
  require "spec_helper"
2
- MetricFu.metrics_require { 'reek/reek' }
2
+ MetricFu.metrics_require { 'reek/generator' }
3
3
 
4
4
  describe MetricFu::ReekGenerator do
5
5
  describe "emit" do
@@ -1,5 +1,5 @@
1
1
  require "spec_helper"
2
- MetricFu.metrics_require { 'reek/reek_grapher' }
2
+ MetricFu.metrics_require { 'reek/grapher' }
3
3
 
4
4
  describe ReekGrapher do
5
5
  before :each do
@@ -0,0 +1,16 @@
1
+ require 'spec_helper'
2
+ require 'shared/configured'
3
+
4
+ describe MetricFu::Configuration, 'for roodi' do
5
+ it_behaves_like 'configured' do
6
+
7
+ it 'should set @roodi to {:dirs_to_roodi => @code_dirs}' do
8
+ load_metric 'roodi'
9
+ expect(MetricFu::Metric.get_metric(:roodi).run_options).to eq(
10
+ { :dirs_to_roodi => directory('code_dirs'),
11
+ :roodi_config => "#{directory('root_directory')}/config/roodi_config.yml"}
12
+ )
13
+ end
14
+
15
+ end
16
+ end
@@ -1,5 +1,5 @@
1
1
  require "spec_helper"
2
- MetricFu.metrics_require { 'roodi/roodi' }
2
+ MetricFu.metrics_require { 'roodi/generator' }
3
3
 
4
4
  describe MetricFu::RoodiGenerator do
5
5
  describe "emit" do
@@ -1,5 +1,5 @@
1
1
  require "spec_helper"
2
- MetricFu.metrics_require { 'roodi/roodi_grapher' }
2
+ MetricFu.metrics_require { 'roodi/grapher' }
3
3
 
4
4
  describe RoodiGrapher do
5
5
  before :each do
@@ -0,0 +1,26 @@
1
+ require 'spec_helper'
2
+ require 'shared/configured'
3
+
4
+ describe MetricFu::Configuration, 'for saikuro' do
5
+ it_behaves_like 'configured' do
6
+
7
+ it 'should set @saikuro to { :output_directory => @scratch_directory + "/saikuro",
8
+ :input_directory => @code_dirs,
9
+ :cyclo => "",
10
+ :filter_cyclo => "0",
11
+ :warn_cyclo => "5",
12
+ :error_cyclo => "7",
13
+ :formater => "text" }' do
14
+ load_metric 'saikuro'
15
+ expect(MetricFu::Metric.get_metric(:saikuro).run_options).to eq(
16
+ { :output_directory => "#{scratch_directory}/saikuro",
17
+ :input_directory => ['lib'],
18
+ :cyclo => "",
19
+ :filter_cyclo => "0",
20
+ :warn_cyclo => "5",
21
+ :error_cyclo => "7",
22
+ :formater => "text"}
23
+ )
24
+ end
25
+ end
26
+ end
@@ -1,5 +1,5 @@
1
1
  require "spec_helper"
2
- MetricFu.metrics_require { 'saikuro/saikuro' }
2
+ MetricFu.metrics_require { 'saikuro/generator' }
3
3
 
4
4
  describe MetricFu::SaikuroGenerator do
5
5
  STUB_TEST_DATA = lambda do |generator|
@@ -1,5 +1,5 @@
1
1
  require "spec_helper"
2
- MetricFu.metrics_require { 'stats/stats' }
2
+ MetricFu.metrics_require { 'stats/generator' }
3
3
 
4
4
  describe StatsGenerator do
5
5
  describe "emit method" do
@@ -1,5 +1,5 @@
1
1
  require "spec_helper"
2
- MetricFu.metrics_require { 'stats/stats_grapher' }
2
+ MetricFu.metrics_require { 'stats/grapher' }
3
3
 
4
4
  describe StatsGrapher do
5
5
  before :each do
@@ -1,5 +1,5 @@
1
1
  require "spec_helper"
2
- MetricFu.metrics_require { 'graph' }
2
+ MetricFu.reporting_require { 'graphs/graph' }
3
3
 
4
4
  describe MetricFu do
5
5
 
@@ -191,7 +191,7 @@ describe MetricFu do
191
191
 
192
192
  def metric_fu(options = "--no-open")
193
193
  message = ''
194
- out = MfDebugger::Logger.capture_output {
194
+ out = MetricFu::Utility.capture_output {
195
195
  begin
196
196
  argv = Shellwords.shellwords(options)
197
197
  MetricFu::Cli::Client.new.run(argv)
@@ -0,0 +1,57 @@
1
+ require 'spec_helper'
2
+ require 'shared/configured'
3
+
4
+ describe MetricFu::Configuration, 'for templates' do
5
+ it_behaves_like 'configured' do
6
+ describe 'when there is no CC_BUILD_ARTIFACTS environment variable' do
7
+
8
+ before(:each) do
9
+ ENV['CC_BUILD_ARTIFACTS'] = nil
10
+ get_new_config
11
+ end
12
+
13
+ it 'should set @template_directory to the lib/templates relative '+
14
+ 'to @metric_fu_root_directory' do
15
+ expected_template_dir = MetricFu.root.join('lib','templates').to_s
16
+ expect(template_directory).to eq(expected_template_dir)
17
+ end
18
+
19
+
20
+ it 'should set @template_class to MetricFu::Templates::MetricsTemplate by default' do
21
+ expect(template_class).to eq(MetricFu::Templates::MetricsTemplate)
22
+ end
23
+
24
+ describe 'when a templates configuration is given' do
25
+
26
+ before do
27
+ class DummyTemplate;end
28
+
29
+ @config.templates_configuration do |config|
30
+ config.template_class = DummyTemplate
31
+ config.link_prefix = 'http:/'
32
+ config.syntax_highlighting = false
33
+ config.darwin_txmt_protocol_no_thanks = false
34
+ end
35
+ end
36
+
37
+ it 'should set given template_class' do
38
+ expect(template_class).to eq(DummyTemplate)
39
+ end
40
+
41
+ it 'should set given link_prefix' do
42
+ expect(MetricFu::Formatter::Templates.option('link_prefix')).to eq('http:/')
43
+ end
44
+
45
+ it 'should set given darwin_txmt_protocol_no_thanks' do
46
+ expect(MetricFu::Formatter::Templates.option('darwin_txmt_protocol_no_thanks')).to be_falsey
47
+ end
48
+
49
+ it 'should set given syntax_highlighting' do
50
+ expect(MetricFu::Formatter::Templates.option('syntax_highlighting')).to be_falsey
51
+ end
52
+
53
+ end
54
+
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,15 @@
1
+ require 'spec_helper'
2
+ MetricFu.lib_require { 'templates/report' }
3
+
4
+ describe MetricFu::Templates::Report do
5
+ # TODO: This test only shows how the code works and that it doesn't blow up.
6
+ # Perhaps it should test something more specific?
7
+ it "Reads in a source file, and produces an annotated HTML report" do
8
+ lines = {"2"=>[{:type=>:reek, :description=>"Bad Param Names"}]}
9
+ source_file = File.join(MetricFu.root_dir, 'spec','dummy','lib','bad_encoding.rb')
10
+ report = MetricFu::Templates::Report.new(source_file, lines)
11
+ expect {
12
+ rendered_report = report.render
13
+ }.not_to raise_error
14
+ end
15
+ end
@@ -0,0 +1,86 @@
1
+ # coding: utf-8
2
+ # from https://github.com/vcr/vcr/blob/master/spec/quality_spec.rb
3
+ # from https://raw.githubusercontent.com/bundler/bundler/master/spec/quality_spec.rb
4
+ require "spec_helper"
5
+
6
+ if defined?(Encoding) && Encoding.default_external != "UTF-8"
7
+ Encoding.default_external = "UTF-8"
8
+ end
9
+
10
+ describe "The library itself" do
11
+
12
+ def check_for_spec_defs_with_single_quotes(filename)
13
+ failing_lines = []
14
+
15
+ File.readlines(filename).each_with_index do |line,number|
16
+ failing_lines << number + 1 if line =~ /^ *(describe|it|context) {1}'{1}/
17
+ end
18
+
19
+ unless failing_lines.empty?
20
+ "#{filename} uses inconsistent single quotes on lines #{failing_lines.join(', ')}"
21
+ end
22
+ end
23
+
24
+ def check_for_tab_characters(filename)
25
+ failing_lines = []
26
+ File.readlines(filename).each_with_index do |line,number|
27
+ failing_lines << number + 1 if line =~ /\t/
28
+ end
29
+
30
+ unless failing_lines.empty?
31
+ "#{filename} has tab characters on lines #{failing_lines.join(', ')}"
32
+ end
33
+ end
34
+
35
+ def check_for_extra_spaces(filename)
36
+ failing_lines = []
37
+ File.readlines(filename).each_with_index do |line,number|
38
+ next if line =~ /^\s+#.*\s+\n$/
39
+ failing_lines << number + 1 if line =~ /\s+\n$/
40
+ end
41
+
42
+ unless failing_lines.empty?
43
+ "#{filename} has spaces on the EOL on lines #{failing_lines.join(', ')}"
44
+ end
45
+ end
46
+
47
+ RSpec::Matchers.define :be_well_formed do
48
+ failure_message do |actual|
49
+ actual.join("\n")
50
+ end
51
+
52
+ match do |actual|
53
+ actual.empty?
54
+ end
55
+ end
56
+
57
+ it "has no malformed whitespace" do
58
+ exempt = /\.gitmodules|\.marshal|fixtures|vendor|ssl_certs|LICENSE|etc/
59
+ error_messages = []
60
+ Dir.chdir(File.expand_path("../..", __FILE__)) do
61
+ `git ls-files -z`.split("\x0").each do |filename|
62
+ next if filename =~ exempt
63
+ error_messages << check_for_tab_characters(filename)
64
+ error_messages << check_for_extra_spaces(filename)
65
+ end
66
+ end
67
+ expect(error_messages.compact).to be_well_formed
68
+ end
69
+
70
+ it "uses double-quotes consistently in specs" do
71
+ included = /spec/
72
+ error_messages = []
73
+ Dir.chdir(File.expand_path("../", __FILE__)) do
74
+ `git ls-files -z`.split("\x0").each do |filename|
75
+ next unless filename =~ included
76
+ error_messages << check_for_spec_defs_with_single_quotes(filename)
77
+ end
78
+ end
79
+ error_messages.compact.each do |error_message|
80
+ warn error_message
81
+ end
82
+ # TODO: fail build once this spec emits no warnings
83
+ # expect(error_messages.compact).to be_well_formed
84
+ end
85
+
86
+ end
@@ -0,0 +1,47 @@
1
+ shared_examples 'configured' do
2
+
3
+ def get_new_config
4
+ ENV['CC_BUILD_ARTIFACTS'] = nil
5
+ @config = MetricFu.configuration
6
+ @config.reset
7
+ MetricFu.configuration.configure_metric(:rcov) do |rcov|
8
+ rcov.enabled = true
9
+ end
10
+ MetricFu.configure
11
+ allow(MetricFu::Io::FileSystem).to receive(:create_directories) # no need to create directories for the tests
12
+ @config
13
+ end
14
+
15
+ def directory(name)
16
+ MetricFu::Io::FileSystem.directory(name)
17
+ end
18
+
19
+ def base_directory
20
+ directory('base_directory')
21
+ end
22
+
23
+ def output_directory
24
+ directory('output_directory')
25
+ end
26
+
27
+ def scratch_directory
28
+ directory('scratch_directory')
29
+ end
30
+
31
+ def template_directory
32
+ directory('template_directory')
33
+ end
34
+
35
+ def template_class
36
+ MetricFu::Formatter::Templates.option('template_class')
37
+ end
38
+
39
+ def metric_fu_root
40
+ directory('root_directory')
41
+ end
42
+
43
+ def load_metric(metric)
44
+ load File.join(MetricFu.metrics_dir, metric, 'metric.rb')
45
+ end
46
+
47
+ end
@@ -0,0 +1,99 @@
1
+ shared_examples "rcov test coverage generator" do |metric_name|
2
+
3
+ before do
4
+ setup_fs
5
+ MetricFu::Configuration.run do |config|
6
+ config.configure_metric(metric_name) do |rcov|
7
+ rcov.enabled = true
8
+ end
9
+ end
10
+ end
11
+
12
+ before :each do
13
+ @default_options = MetricFu::Metric.get_metric(metric_name).run_options
14
+ end
15
+
16
+ describe "emit" do
17
+ before :each do
18
+ options = {:external => nil}
19
+ @rcov = MetricFu::RcovGenerator.new(@default_options.merge(options))
20
+ end
21
+
22
+ # TODO: should this be true of this metric?
23
+ it "should clear out previous output and make output folder" do
24
+ expect(MetricFu::Utility).to receive(:rm_rf).with(MetricFu::RcovGenerator.metric_directory, :verbose => false)
25
+ expect(MetricFu::Utility).to receive(:mkdir_p).with(MetricFu::RcovGenerator.metric_directory)
26
+ @rcov.reset_output_location
27
+ end
28
+
29
+ end
30
+
31
+ def rcov_output
32
+ FIXTURE.load_file('rcov_output.txt')
33
+ end
34
+
35
+ describe "with rcov_output fed into" do
36
+ before :each do
37
+ options = {:external => nil}
38
+ @rcov = MetricFu::RcovGenerator.new(@default_options.merge(options))
39
+ expect(@rcov).to receive(:load_output).and_return(rcov_output)
40
+ @files = @rcov.analyze
41
+ end
42
+
43
+ describe "analyze" do
44
+ it "should compute percent of lines run" do
45
+ expect(@files["./lib/metric_fu/metrics/hotspots/analysis/record.rb"][:percent_run]).to eq(94)
46
+ expect(@files["./lib/metric_fu/metrics/hotspots/analysis/table.rb"][:percent_run]).to eq(93)
47
+ end
48
+
49
+ it "should know which lines were run" do
50
+ expect(@files["./lib/metric_fu/metrics/hotspots/analysis/record.rb"][:lines].any? {|line|
51
+ line[:content].strip == "@data[key]" &&
52
+ line[:was_run] == 1
53
+ }).to be_truthy
54
+ end
55
+
56
+ it "should know which lines NOT were run" do
57
+ expect(@files["./lib/metric_fu/metrics/hotspots/analysis/record.rb"][:lines].any? {|line|
58
+ line[:content].strip == "super(name, *args, &block)" &&
59
+ line[:was_run] == 0
60
+ }).to be_truthy
61
+ end
62
+
63
+ it "should know which lines were ignored" do
64
+ expect(@files["./lib/metric_fu/metrics/hotspots/analysis/record.rb"][:lines].any? {|line|
65
+ line[:content].strip == "end" &&
66
+ line[:was_run] == nil
67
+ }).to be_truthy
68
+ end
69
+ end
70
+
71
+ describe "to_h" do
72
+ it "should calculate total percentage for all files" do
73
+ expect(@rcov.to_h[:rcov][:global_percent_run]).to eq(93.3)
74
+ end
75
+ end
76
+ end
77
+ describe "with external configuration option set" do
78
+ before :each do
79
+ options = {:external => 'coverage/rcov.txt'}
80
+ @rcov = MetricFu::RcovGenerator.new(@default_options.merge(options))
81
+ end
82
+
83
+ it "should emit nothing if external configuration option is set" do
84
+ expect(MetricFu::Utility).not_to receive(:rm_rf)
85
+ @rcov.emit
86
+ end
87
+
88
+ it "should open the external rcov analysis file" do
89
+ expect(@rcov).to receive(:load_output).and_return(rcov_output)
90
+ @files = @rcov.analyze
91
+ end
92
+
93
+ end
94
+
95
+ after do
96
+ cleanup_fs
97
+ end
98
+
99
+ end
data/spec/spec_helper.rb CHANGED
@@ -3,6 +3,7 @@ $:.unshift File.expand_path("../../lib", __FILE__)
3
3
  if ENV['COVERAGE']
4
4
  require 'simplecov'
5
5
  formatters = [SimpleCov::Formatter::HTMLFormatter]
6
+ SimpleCov.start 'metric_fu'
6
7
  begin
7
8
  puts '[COVERAGE] Running with SimpleCov HTML Formatter'
8
9
  require 'metric_fu/metrics/rcov/simplecov_formatter'
@@ -12,10 +13,8 @@ if ENV['COVERAGE']
12
13
  puts '[COVERAGE] SimpleCov MetricFu formatter could not be loaded'
13
14
  end
14
15
  SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[ *formatters ]
15
- SimpleCov.start
16
16
  end
17
17
 
18
- require 'rspec/autorun'
19
18
  require 'date'
20
19
  require 'test_construct'
21
20
  require 'json'
@@ -30,13 +29,18 @@ def mf_log(msg); mf_debug(msg); end
30
29
  Dir[MetricFu.root_dir + "/spec/support/**/*.rb"].each {|f| require f}
31
30
 
32
31
  RSpec.configure do |config|
33
- config.mock_with :rspec
34
-
35
32
  config.filter_run focus: true
36
33
  config.run_all_when_everything_filtered = true
37
34
  config.filter_run_excluding :slow unless ENV["SLOW_SPECS"]
38
35
  config.fail_fast = ENV.include?('FAIL_FAST')
39
- config.order = 'random'
36
+ config.order = :rand
37
+ config.color_enabled = true
38
+ config.expect_with :rspec do |expectations|
39
+ expectations.syntax = :expect
40
+ end
41
+ config.mock_with :rspec do |mocks|
42
+ mocks.syntax = :expect
43
+ end
40
44
 
41
45
  # :suite after/before all specs
42
46
  # :each every describe block