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
@@ -2,7 +2,7 @@
2
2
  require 'open3'
3
3
  require 'shellwords'
4
4
  require 'metric_fu'
5
- MetricFu.lib_require { 'logging/mf_debugger' }
5
+ MetricFu.lib_require { 'logger' }
6
6
  MetricFu.lib_require { 'gem_version' }
7
7
  module MetricFu
8
8
  class GemRun
@@ -34,7 +34,7 @@ module MetricFu
34
34
  captured_output << stdout.read.chomp
35
35
  captured_errors << stderr.read.chomp
36
36
  end
37
- STDERR.puts MetricFu::AnalysisError.new(captured_errors) unless captured_errors.empty?
37
+ captured_output << "\nERRORS:\n#{captured_errors}"
38
38
  rescue StandardError => run_error
39
39
  handle_run_error(run_error)
40
40
  rescue SystemExit => system_exit
@@ -38,7 +38,7 @@ module MetricFu
38
38
  define_method("#{dir}_dir") do
39
39
  File.join(lib_dir,dir)
40
40
  end
41
- module_eval(%Q(def #{dir}_require(&block); lib_require('#{dir}', &block); end))
41
+ module_eval(%Q(def #{dir}_require(&block); lib_require('#{dir}', &block); end), __FILE__, __LINE__)
42
42
  end
43
43
  end
44
44
  end
@@ -59,30 +59,11 @@ module MetricFu
59
59
  end
60
60
  end
61
61
 
62
- # Load specified task task only once
63
- # if and only if rake is required and the task is not yet defined
64
- # to prevent the task from being loaded multiple times
65
- # @param tasks_relative_path [String] 'metric_fu.rake' by default
66
- # @param options [Hash] optional task_name to check if loaded
67
- # @option options [String] :task_name The task_name to load, if not yet loaded
68
- def load_tasks(tasks_relative_path, options={task_name: ''})
69
- if defined?(Rake::Task) and not Rake::Task.task_defined?(options[:task_name])
70
- load File.join(@lib_root, 'tasks', *Array(tasks_relative_path))
71
- end
72
- end
73
-
74
62
  def setup
75
- MetricFu.logging_require { 'mf_debugger' }
76
- Object.send :include, MfDebugger
77
- MfDebugger::Logger.debug_on = !!(ENV['MF_DEBUG'] =~ /true/i)
78
-
79
- MetricFu.lib_require { 'configuration' }
80
- MetricFu.lib_require { 'metric' }
63
+ MetricFu.lib_require { 'logger' }
64
+ MetricFu.logger.debug_on = !!(ENV['MF_DEBUG'] =~ /true/i)
81
65
 
82
- Dir.glob(File.join(MetricFu.metrics_dir, '**/init.rb')).each{|init_file|require(init_file)}
83
-
84
- MetricFu.configuration.configure_metrics
85
- load_user_configuration
66
+ load_metric_configuration
86
67
 
87
68
  MetricFu.lib_require { 'reporter' }
88
69
  MetricFu.reporting_require { 'result' }
@@ -90,10 +71,36 @@ module MetricFu
90
71
  MetricFu.load_tasks('metric_fu.rake', task_name: 'metrics:all')
91
72
  end
92
73
 
74
+ def load_metric_configuration
75
+ MetricFu.lib_require { 'configuration' }
76
+ load_installed_metrics
77
+ MetricFu.configuration.configure_metrics
78
+ load_user_configuration
79
+ end
80
+
81
+ def load_installed_metrics
82
+ MetricFu.lib_require { 'metric' }
83
+ Dir.glob(File.join(MetricFu.metrics_dir, '**/metric.rb')).each do |metric_config|
84
+ require metric_config
85
+ end
86
+ end
87
+
93
88
  def load_user_configuration
94
89
  file = File.join(MetricFu.run_dir, '.metrics')
95
90
  load file if File.exist?(file)
96
91
  end
97
92
 
93
+ # Load specified task task only once
94
+ # if and only if rake is required and the task is not yet defined
95
+ # to prevent the task from being loaded multiple times
96
+ # @param tasks_relative_path [String] 'metric_fu.rake' by default
97
+ # @param options [Hash] optional task_name to check if loaded
98
+ # @option options [String] :task_name The task_name to load, if not yet loaded
99
+ def load_tasks(tasks_relative_path, options={task_name: ''})
100
+ if defined?(Rake::Task) and not Rake::Task.task_defined?(options[:task_name])
101
+ load File.join(@lib_root, 'tasks', *Array(tasks_relative_path))
102
+ end
103
+ end
104
+
98
105
  end
99
106
  end
@@ -0,0 +1,65 @@
1
+ require 'logger'
2
+ require 'forwardable'
3
+ module MetricFu
4
+
5
+ def self.logger
6
+ @logger ||= ::MetricFu::Logger.new($stdout)
7
+ end
8
+
9
+ class Logger
10
+ extend Forwardable
11
+ MfLogger = ::Logger
12
+
13
+ def initialize(stdout)
14
+ @logger = MfLogger.new(stdout)
15
+ self.debug_on = false
16
+ self.formatter = ->(severity, time, progname, msg){ "#{msg}\n" }
17
+ self.level = 'info'
18
+ end
19
+
20
+ def debug_on=(bool)
21
+ self.level = bool ? 'debug' : 'info'
22
+ end
23
+
24
+ def debug_on
25
+ @logger.level == MfLogger::DEBUG
26
+ end
27
+
28
+ def_delegators :@logger, :info, :warn, :error, :fatal, :unknown
29
+
30
+ LEVELS = {
31
+ 'debug' => MfLogger::DEBUG,
32
+ 'info' => MfLogger::INFO,
33
+ 'warn' => MfLogger::WARN,
34
+ 'error' => MfLogger::ERROR,
35
+ 'fatal' => MfLogger::FATAL,
36
+ 'unknown' => MfLogger::UNKNOWN,
37
+ }
38
+
39
+ def level=(level)
40
+ @logger.level = LEVELS.fetch(level.to_s.downcase) { level }
41
+ end
42
+
43
+ def formatter=(formatter)
44
+ @logger.formatter = formatter
45
+ end
46
+
47
+ def log(msg)
48
+ @logger.info '*'*5 + msg.to_s
49
+ end
50
+
51
+ def debug(msg)
52
+ @logger.debug '*'*5 + msg.to_s
53
+ end
54
+
55
+ end
56
+
57
+ end
58
+ # For backward compatibility
59
+ def mf_debug(msg,&block)
60
+ MetricFu.logger.debug(msg, &block)
61
+ end
62
+
63
+ def mf_log(msg,&block)
64
+ MetricFu.logger.log(msg, &block)
65
+ end
@@ -1,58 +1,23 @@
1
+ warn "MfDebugger if deprecated. Please use MetricFu.logger"
2
+ MetricFu.lib_require { 'logger' }
1
3
  module MfDebugger
2
4
  extend self
3
-
4
5
  class Logger
5
- class << self
6
- attr_accessor :debug_on
7
- @debug_on = false
6
+ def self.debug_on
7
+ warn "MfDebugger if deprecated. Please use MetricFu.logger"
8
+ MetricFu.logger.debug_on
9
+ end
10
+ def self.debug_on=(bool)
11
+ warn "MfDebugger if deprecated. Please use MetricFu.logger"
12
+ MetricFu.logger.level = bool ? 'debug' : 'info'
8
13
  end
9
14
  def self.log(msg, &block)
10
- if block_given?
11
- block.call
12
- end
13
- STDOUT.puts '*'*5 + msg.to_s
15
+ warn "MfDebugger if deprecated. Please use MetricFu.logger"
16
+ MetricFu.logger.info msg
14
17
  end
15
18
  def self.debug(msg, &block)
16
- if MfDebugger::Logger.debug_on
17
- if block_given?
18
- log(msg,&block)
19
- else
20
- log(msg)
21
- end
22
- end
23
- end
24
- # From episode 029 of Ruby Tapas by Avdi
25
- # https://rubytapas.dpdcart.com/subscriber/post?id=88
26
- def self.capture_output(stream=STDOUT, &block)
27
- old_stdout = stream.clone
28
- pipe_r, pipe_w = IO.pipe
29
- pipe_r.sync = true
30
- output = ""
31
- reader = Thread.new do
32
- begin
33
- loop do
34
- output << pipe_r.readpartial(1024)
35
- end
36
- rescue EOFError
37
- end
38
- end
39
- stream.reopen(pipe_w)
40
- yield
41
- ensure
42
- stream.reopen(old_stdout)
43
- pipe_w.close
44
- reader.join
45
- pipe_r.close
46
- return output
19
+ warn "MfDebugger if deprecated. Please use MetricFu.logger"
20
+ MetricFu.logger.debug msg
47
21
  end
48
22
  end
49
-
50
- def mf_debug(msg,&block)
51
- MfDebugger::Logger.debug(msg, &block)
52
- end
53
-
54
- def mf_log(msg,&block)
55
- MfDebugger::Logger.log(msg, &block)
56
- end
57
-
58
23
  end
@@ -1,6 +1,6 @@
1
1
  require 'set'
2
2
  MetricFu.lib_require { 'gem_run' }
3
- MetricFu.metrics_require { 'generator' }
3
+ MetricFu.lib_require { 'generator' }
4
4
  # Encapsulates the configuration options for each metric
5
5
  module MetricFu
6
6
  class Metric
@@ -124,9 +124,9 @@ module MetricFu
124
124
 
125
125
  def default_metric_library_paths
126
126
  paths = []
127
- paths << generator_path = "#{name}/#{name}"
127
+ paths << generator_path = "#{name}/generator"
128
128
  if has_graph?
129
- paths << grapher_path = "#{name}/#{name}_grapher"
129
+ paths << grapher_path = "#{name}/grapher"
130
130
  end
131
131
  paths
132
132
  end
@@ -24,7 +24,7 @@ module MetricFu
24
24
  if MetricFu.configuration.supports_ripper? && !MetricFu.configuration.ruby18?
25
25
  super
26
26
  else
27
- MetricFu.configuration.mf_debug("Cane is only available in MRI. It requires ripper and 1.9 hash syntax support")
27
+ MetricFu.logger.debug("Cane is only available in MRI. It requires ripper and 1.9 hash syntax support")
28
28
  end
29
29
  end
30
30
 
File without changes
@@ -7,8 +7,7 @@ module MetricFu
7
7
  end
8
8
 
9
9
  def emit
10
- minimum_score_parameter = options[:minimum_score] ? "--mass #{options[:minimum_score]} " : ""
11
- args = "#{minimum_score_parameter} #{options[:dirs_to_flay].join(" ")}"
10
+ args = "#{minimum_duplication_mass} #{dirs_to_flay}"
12
11
  @output = run!(args)
13
12
  end
14
13
 
@@ -29,5 +28,20 @@ module MetricFu
29
28
  end
30
29
  {:flay => {:total_score => total_score, :matches => target.flatten}}
31
30
  end
31
+
32
+ private
33
+
34
+ def minimum_duplication_mass
35
+ flay_mass = options[:minimum_score]
36
+ return "" unless flay_mass
37
+
38
+
39
+ "--mass #{flay_mass} "
40
+ end
41
+
42
+ def dirs_to_flay
43
+ options[:dirs_to_flay].join(" ")
44
+ end
45
+
32
46
  end
33
47
  end
@@ -11,7 +11,7 @@ module MetricFu
11
11
  # a long time. This is a really big number, considering
12
12
  # the default is 16. Setting it to nil to use the Flay default.
13
13
  :minimum_score => nil,
14
- :filetypes => ['rb'] }
14
+ }
15
15
  end
16
16
 
17
17
  def has_graph?
@@ -17,7 +17,7 @@ module MetricFu
17
17
  if MetricFu.configuration.mri?
18
18
  super
19
19
  else
20
- MetricFu.configuration.mf_debug("Flog is only available in MRI due to flog tasks")
20
+ MetricFu.logger.debug("Flog is only available in MRI due to flog tasks")
21
21
  end
22
22
  end
23
23
 
@@ -34,7 +34,7 @@ module MetricFu
34
34
  private
35
35
 
36
36
  def require_hotspot(metric_name)
37
- require "metric_fu/metrics/#{metric_name}/#{metric_name}_hotspot"
37
+ require "metric_fu/metrics/#{metric_name}/hotspot"
38
38
  rescue LoadError
39
39
  mf_debug "*** No hotspot for #{metric_name}"
40
40
  end
@@ -17,7 +17,7 @@ module MetricFu
17
17
  if MetricFu.configuration.supports_ripper?
18
18
  super if MetricFu.configuration.rails?
19
19
  else
20
- MetricFu.configuration.mf_debug("Rails Best Practices is only available in MRI 1.9. It requires ripper")
20
+ MetricFu.logger.debug("Rails Best Practices is only available in MRI 1.9. It requires ripper")
21
21
  end
22
22
  end
23
23
 
File without changes
@@ -18,6 +18,28 @@ module MetricFu
18
18
  def to_h
19
19
  {:content => @content, :was_run => @was_run}
20
20
  end
21
+
22
+ def covered?
23
+ @was_run.one?
24
+ end
25
+ def missed?
26
+ @was_run.zero?
27
+ end
28
+ def ignored?
29
+ @was_run.nil?
30
+ end
31
+ def self.line_coverage(lines)
32
+ lines.map{|line| line[:was_run] }
33
+ end
34
+ def self.covered_lines(line_coverage)
35
+ line_coverage.count(1)
36
+ end
37
+ def self.missed_lines(line_coverage)
38
+ line_coverage.count(0)
39
+ end
40
+ def self.ignored_lines(line_coverage)
41
+ line_coverage.count(nil)
42
+ end
21
43
  end
22
44
 
23
45
  def to_h
@@ -39,7 +61,13 @@ module MetricFu
39
61
  files.each_pair {|fname, content| files[fname] = content.split("\n") }
40
62
  files.each_pair do |fname, content|
41
63
  content.map! do |raw_line|
42
- covered_line = raw_line.match(/^!!/).nil?
64
+ covered_line = if raw_line.start_with?('--')
65
+ nil # simplecov ignores some lines
66
+ elsif raw_line.start_with?('!!')
67
+ 0
68
+ else
69
+ 1
70
+ end
43
71
  Line.new(raw_line[3..-1], covered_line).to_h
44
72
  end
45
73
  content.reject! {|line| line[:content].to_s == '' }
@@ -64,6 +92,26 @@ module MetricFu
64
92
  end
65
93
  end
66
94
 
95
+ def self.floating_percent(numerator, denominator)
96
+ (numerator * 100.0) / denominator.to_f
97
+ end
98
+
99
+ def self.integer_percent(numerator, denominator)
100
+ ::MetricFu::Calculate.integer_percent(numerator, denominator)
101
+ end
102
+
103
+ def self.percent_run(lines)
104
+ line_coverage = Line.line_coverage(lines)
105
+ covered_lines = Line.covered_lines(line_coverage)
106
+ ignored_lines = Line.ignored_lines(line_coverage)
107
+ relevant_lines = lines.count - ignored_lines
108
+ if block_given?
109
+ yield covered_lines, relevant_lines
110
+ else
111
+ floating_percent(covered_lines, relevant_lines)
112
+ end
113
+ end
114
+
67
115
  private
68
116
  # TODO: remove multiple side effects
69
117
  # sets global ivars and
@@ -71,18 +119,18 @@ module MetricFu
71
119
  def add_coverage_percentage(files)
72
120
  files.each_pair do |fname, content|
73
121
  lines = content[:lines]
74
- lines_run = lines.count {|line| line[:was_run] }
75
- total_lines = lines.length
76
- integer_percent = ::MetricFu::Calculate.integer_percent(lines_run, total_lines)
77
-
78
- files[fname][:percent_run] = integer_percent
79
- @global_total_lines_run += lines_run
80
- @global_total_lines += total_lines
122
+ percent_run =
123
+ self.class.percent_run(lines) do |covered, relevant|
124
+ @global_total_lines_run += covered
125
+ @global_total_lines += relevant
126
+ self.class.integer_percent(covered, relevant)
127
+ end
128
+ files[fname][:percent_run] = percent_run
81
129
  end
82
130
  end
83
131
 
84
132
  def add_global_percent_run(test_coverage, total_lines, total_lines_run)
85
- percentage = (total_lines_run.to_f / total_lines.to_f) * 100
133
+ percentage = self.class.floating_percent(total_lines_run, total_lines)
86
134
  test_coverage.update({
87
135
  :global_percent_run => round_to_tenths(percentage)
88
136
  })