metric_fu 4.3.1 → 4.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (88) hide show
  1. checksums.yaml +7 -0
  2. data/.metrics +55 -26
  3. data/.travis.yml +4 -1
  4. data/AUTHORS +12 -0
  5. data/Gemfile +1 -0
  6. data/HISTORY.md +24 -0
  7. data/README.md +27 -22
  8. data/checksum/metric_fu-4.3.1.gem.sha512 +1 -0
  9. data/checksum/metric_fu-4.4.0.gem.sha512 +1 -0
  10. data/lib/metric_fu.rb +28 -79
  11. data/lib/metric_fu/cli/helper.rb +1 -1
  12. data/lib/metric_fu/cli/parser.rb +1 -1
  13. data/lib/metric_fu/configuration.rb +104 -150
  14. data/lib/metric_fu/environment.rb +88 -0
  15. data/lib/metric_fu/formatter.rb +23 -0
  16. data/lib/metric_fu/formatter/html.rb +12 -9
  17. data/lib/metric_fu/initial_requires.rb +1 -0
  18. data/lib/metric_fu/io.rb +60 -1
  19. data/lib/metric_fu/load_files.rb +4 -2
  20. data/lib/metric_fu/loader.rb +62 -0
  21. data/lib/metric_fu/metric.rb +102 -0
  22. data/lib/metric_fu/metrics/base_template.rb +15 -9
  23. data/lib/metric_fu/metrics/cane/cane.rb +9 -5
  24. data/lib/metric_fu/metrics/cane/init.rb +35 -13
  25. data/lib/metric_fu/metrics/churn/churn.rb +5 -1
  26. data/lib/metric_fu/metrics/churn/init.rb +24 -4
  27. data/lib/metric_fu/metrics/flay/flay.rb +7 -3
  28. data/lib/metric_fu/metrics/flay/init.rb +29 -13
  29. data/lib/metric_fu/metrics/flay/template_awesome/flay.html.erb +1 -1
  30. data/lib/metric_fu/metrics/flog/flog.rb +14 -38
  31. data/lib/metric_fu/metrics/flog/init.rb +30 -7
  32. data/lib/metric_fu/metrics/generator.rb +21 -6
  33. data/lib/metric_fu/metrics/graph.rb +2 -2
  34. data/lib/metric_fu/metrics/hotspots/hotspots.rb +5 -1
  35. data/lib/metric_fu/metrics/hotspots/init.rb +21 -5
  36. data/lib/metric_fu/metrics/rails_best_practices/init.rb +29 -5
  37. data/lib/metric_fu/metrics/rails_best_practices/rails_best_practices.rb +20 -27
  38. data/lib/metric_fu/metrics/rails_best_practices/template_awesome/rails_best_practices.html.erb +1 -1
  39. data/lib/metric_fu/metrics/rcov/init.rb +40 -15
  40. data/lib/metric_fu/metrics/rcov/rcov.rb +15 -10
  41. data/lib/metric_fu/metrics/reek/init.rb +25 -6
  42. data/lib/metric_fu/metrics/reek/reek.rb +52 -31
  43. data/lib/metric_fu/metrics/reek/template_awesome/reek.html.erb +1 -1
  44. data/lib/metric_fu/metrics/roodi/init.rb +25 -6
  45. data/lib/metric_fu/metrics/roodi/roodi.rb +7 -3
  46. data/lib/metric_fu/metrics/saikuro/init.rb +22 -6
  47. data/lib/metric_fu/metrics/saikuro/saikuro.rb +8 -3
  48. data/lib/metric_fu/metrics/stats/init.rb +28 -5
  49. data/lib/metric_fu/metrics/stats/stats.rb +24 -6
  50. data/lib/metric_fu/metrics/stats/template_awesome/stats.html.erb +2 -2
  51. data/lib/metric_fu/parser_ext.rb +15 -0
  52. data/lib/metric_fu/reporting/graphs/engines/gchart.rb +1 -1
  53. data/lib/metric_fu/reporting/graphs/engines/init.rb +18 -4
  54. data/lib/metric_fu/reporting/graphs/grapher.rb +1 -1
  55. data/lib/metric_fu/reporting/result.rb +13 -6
  56. data/lib/metric_fu/reporting/templates/awesome/awesome_template.rb +1 -1
  57. data/lib/metric_fu/run.rb +7 -10
  58. data/lib/metric_fu/sexp_ext.rb +11 -0
  59. data/lib/metric_fu/version.rb +1 -1
  60. data/metric_fu.gemspec +23 -20
  61. data/spec/cli/helper_spec.rb +5 -16
  62. data/spec/metric_fu/configuration_spec.rb +62 -88
  63. data/spec/metric_fu/formatter/html_spec.rb +26 -16
  64. data/spec/metric_fu/formatter/yaml_spec.rb +2 -2
  65. data/spec/metric_fu/metric_spec.rb +50 -0
  66. data/spec/metric_fu/metrics/base_template_spec.rb +9 -7
  67. data/spec/metric_fu/metrics/cane/cane_spec.rb +19 -24
  68. data/spec/metric_fu/metrics/churn/churn_spec.rb +8 -8
  69. data/spec/metric_fu/metrics/flay/flay_spec.rb +7 -13
  70. data/spec/metric_fu/metrics/flog/flog_spec.rb +63 -58
  71. data/spec/metric_fu/metrics/generator_spec.rb +4 -0
  72. data/spec/metric_fu/metrics/hotspots/hotspots_spec.rb +7 -7
  73. data/spec/metric_fu/metrics/rails_best_practices/rails_best_practices_spec.rb +14 -33
  74. data/spec/metric_fu/metrics/rcov/rcov_spec.rb +17 -18
  75. data/spec/metric_fu/metrics/reek/reek_spec.rb +9 -10
  76. data/spec/metric_fu/metrics/roodi/roodi_spec.rb +5 -11
  77. data/spec/metric_fu/metrics/saikuro/saikuro_spec.rb +15 -14
  78. data/spec/metric_fu/metrics/stats/stats_spec.rb +5 -6
  79. data/spec/metric_fu/reporting/graphs/engines/bluff_spec.rb +2 -3
  80. data/spec/metric_fu/reporting/graphs/engines/gchart_spec.rb +12 -9
  81. data/spec/metric_fu/reporting/result_spec.rb +3 -3
  82. data/spec/run_spec.rb +45 -29
  83. data/spec/spec_helper.rb +7 -0
  84. data/spec/support/helper_methods.rb +9 -0
  85. data/spec/support/suite.rb +17 -11
  86. metadata +59 -56
  87. data/bin/mf-rails_best_practices +0 -9
  88. data/bin/mf-stats +0 -7
@@ -1,12 +1,17 @@
1
1
  module MetricFu
2
2
 
3
3
  class Saikuro < Generator
4
+
5
+ def self.metric
6
+ :saikuro
7
+ end
8
+
4
9
  def emit
5
- options_string = MetricFu.saikuro.inject("") do |options, option|
10
+ options_string = options.inject("") do |options, option|
6
11
  option[0] == :input_directory ? options : options + "--#{option.join(' ')} "
7
12
  end
8
13
 
9
- MetricFu.saikuro[:input_directory].each do |input_dir|
14
+ options[:input_directory].each do |input_dir|
10
15
  options_string += "--input_directory #{input_dir} "
11
16
  end
12
17
 
@@ -16,7 +21,7 @@ module MetricFu
16
21
  end
17
22
 
18
23
  def format_directories
19
- dirs = MetricFu.saikuro[:input_directory].join(" | ")
24
+ dirs = options[:input_directory].join(" | ")
20
25
  "\"#{dirs}\""
21
26
  end
22
27
 
@@ -1,7 +1,30 @@
1
- MetricFu::Configuration.run do |config|
2
- if config.rails?
3
- config.add_metric(:stats)
4
- config.add_graph(:stats)
5
- config.configure_metric(:stats,{})
1
+ module MetricFu
2
+ class MetricStats < Metric
3
+
4
+ def name
5
+ :stats
6
+ end
7
+
8
+ def default_run_options
9
+ {
10
+ # returns a list of directories that contains the glob of files that have the file_pattern in the file names
11
+ :additional_test_directories => [{glob_pattern: File.join('.','spec','**','*_spec.rb'), file_pattern: 'spec'}],
12
+ :additional_app_directories => [{glob_pattern: File.join('.','engines','**','*.rb'), file_pattern: ''}],
13
+ }
14
+ end
15
+
16
+ def has_graph?
17
+ true
18
+ end
19
+
20
+ def enable
21
+ super
22
+ end
23
+
24
+ def activate
25
+ activate_library 'code_metrics'
26
+ super
27
+ end
28
+
6
29
  end
7
30
  end
@@ -1,16 +1,20 @@
1
1
  module MetricFu
2
2
 
3
- class Stats < Generator
3
+ class StatsGenerator < Generator
4
+
5
+ def self.metric
6
+ :stats
7
+ end
4
8
 
5
9
  def emit
6
- command = %Q(mf-stats > #{metric_directory + '/stats.txt'})
7
- mf_debug "** #{command}"
8
- @output = `#{command}`
10
+ require 'code_metrics/statistics'
11
+ @output = MfDebugger::Logger.capture_output do
12
+ CodeMetrics::Statistics.new(*dirs).to_s
13
+ end
9
14
  end
10
15
 
11
16
  def analyze
12
- output = File.open(metric_directory + '/stats.txt').read
13
- lines = remove_noise(output).compact
17
+ lines = remove_noise(@output).compact
14
18
 
15
19
  @stats = {}
16
20
 
@@ -57,5 +61,19 @@ module MetricFu
57
61
  end
58
62
  end
59
63
 
64
+ # @return [Array<[ 'Acceptance specs', 'spec/acceptance' ]>]
65
+ def dirs
66
+ require 'code_metrics/stats_directories'
67
+ require 'code_metrics/statistics'
68
+ stats_dirs = CodeMetrics::StatsDirectories.new
69
+ options.fetch(:additional_test_directories).each do |option|
70
+ stats_dirs.add_test_directories(option.fetch(:glob_pattern), option.fetch(:file_pattern))
71
+ end
72
+ options.fetch(:additional_app_directories).each do |option|
73
+ stats_dirs.add_directories(option.fetch(:glob_pattern), option.fetch(:file_pattern))
74
+ end
75
+ stats_dirs.directories
76
+ end
77
+
60
78
  end
61
79
  end
@@ -1,4 +1,4 @@
1
- <h3>Rake Stats Results</h3>
1
+ <h3>Lines of Code/Tests Metric Results</h3>
2
2
 
3
3
  <% graph_name = 'stats' %>
4
4
  <% if MetricFu.configuration.graph_engine == :gchart %>
@@ -9,7 +9,7 @@
9
9
  <% end %>
10
10
 
11
11
 
12
- <p>Rails rake stats results.</p>
12
+ <p>Lines of Code/Tests Metrics Results</p>
13
13
  <table>
14
14
  <tr>
15
15
  <th>Lines of Code</th>
@@ -0,0 +1,15 @@
1
+ # For Flog
2
+ # TODO: Do we still need this?
3
+ require 'ruby_parser'
4
+ class RubyParser
5
+ alias_method :original_process, :process
6
+ def process(s,f,t)
7
+ original_process(s,f,t)
8
+ rescue => e
9
+ if e.message =~ /wrong number of arguments/
10
+ original_process(s,f)
11
+ else
12
+ raise
13
+ end
14
+ end
15
+ end
@@ -58,7 +58,7 @@ module MetricFu
58
58
  class Grapher
59
59
 
60
60
  def self.require_graphing_gem
61
- if MetricFu.graph_engine == :gchart
61
+ if MetricFu.configuration.graph_engine == :gchart
62
62
  require 'gchart'
63
63
  include MetricFu::GchartGrapher
64
64
  end
@@ -1,5 +1,19 @@
1
- MetricFu::Configuration.run do |config|
2
- config.add_graph_engine(:bluff)
3
- config.add_graph_engine(:gchart)
4
- config.configure_graph_engine(:bluff) # can be :bluff or :gchart
1
+ module MetricFu
2
+ class GraphEngine
3
+
4
+ attr_accessor :graph_engines, :graph_engine
5
+ def initialize
6
+ @graph_engines = [:bluff, :gchart]
7
+ @graph_engine = :bluff
8
+ end
9
+
10
+ def add_graph_engine(graph_engine)
11
+ self.graph_engines = (graph_engines << graph_engine).uniq
12
+ end
13
+
14
+ def configure_graph_engine(graph_engine)
15
+ self.graph_engine = graph_engine
16
+ end
17
+
18
+ end
5
19
  end
@@ -8,7 +8,7 @@ module MetricFu
8
8
  end
9
9
 
10
10
  def output_directory
11
- @output_directory || MetricFu.output_directory
11
+ @output_directory || MetricFu::Io::FileSystem.directory('output_directory')
12
12
  end
13
13
 
14
14
  def self.require_graphing_gem
@@ -38,14 +38,21 @@ module MetricFu
38
38
  # The hash to add to the aggregate result_hash
39
39
  def add(result_type)
40
40
  mf_debug "result requested #{result_type}"
41
- clazz = MetricFu.const_get(result_type.to_s.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase })
42
- mf_debug "result class found #{clazz}"
43
- metric_options = MetricFu.send(result_type)
44
- inst = clazz.new(metric_options)
41
+ metric_options = metric_options_for_result_type(result_type)
42
+ generator_class = MetricFu::Generator.get_generator(result_type)
43
+ mf_debug "result class found #{generator_class}"
44
+ generator = generator_class.new(metric_options)
45
45
 
46
- result_hash.merge!(inst.generate_result)
46
+ result_hash.merge!(generator.generate_result)
47
47
 
48
- inst.per_file_info(per_file_data) if inst.respond_to?(:per_file_info)
48
+ generator.per_file_info(per_file_data) if generator.respond_to?(:per_file_info)
49
49
  end
50
+
51
+ private
52
+
53
+ def metric_options_for_result_type(result_type)
54
+ MetricFu::Metric.get_metric(result_type).run_options
55
+ end
56
+
50
57
  end
51
58
  end
@@ -91,7 +91,7 @@ class AwesomeTemplate < MetricFu::Template
91
91
  out << "&nbsp;"
92
92
  end
93
93
  out << "</td>"
94
- if MetricFu.configuration.syntax_highlighting
94
+ if MetricFu::Formatter::Templates.option('syntax_highlighting')
95
95
  line_for_display = convert_ruby_to_html(line, line_number)
96
96
  else
97
97
  line_for_display = "<a name='n#{line_number}' href='n#{line_number}'>#{line_number}</a>#{line}"
data/lib/metric_fu/run.rb CHANGED
@@ -11,10 +11,8 @@ module MetricFu
11
11
  display_results if options[:open]
12
12
  end
13
13
 
14
- # ensure :hotspots runs last
15
- def report_metrics(metrics=MetricFu.metrics)
16
- MetricFu.configuration.metrics.sort_by! {|x| x == :hotspots ? 1 : 0 }
17
- MetricFu.configuration.metrics
14
+ def report_metrics(metrics=MetricFu::Metric.enabled_metrics)
15
+ metrics.map(&:name)
18
16
  end
19
17
  def measure
20
18
  reporter.start
@@ -45,24 +43,23 @@ module MetricFu
45
43
  mf_debug "using metric #{metric}"
46
44
  else
47
45
  mf_debug "disabling metric #{metric}"
48
- MetricFu.configuration.metrics -= [ metric ]
49
- MetricFu.configuration.graphs -= [ metric ]
50
- mf_debug "active metrics are #{MetricFu.configuration.metrics.inspect}"
46
+ MetricFu::Metric.get_metric(metric).enabled = false
47
+ mf_debug "active metrics are #{MetricFu::Metric.enabled_metrics.inspect}"
51
48
  end
52
49
  end
53
50
  end
54
51
  def configure_formatters(options)
55
52
  # Configure from command line if any.
56
53
  if options[:format]
57
- MetricFu.formatters.clear # Command-line format takes precedence.
54
+ MetricFu.configuration.formatters.clear # Command-line format takes precedence.
58
55
  Array(options[:format]).each do |format, o|
59
- MetricFu.configuration.add_formatter(format, o)
56
+ MetricFu.configuration.configure_formatter(format, o)
60
57
  end
61
58
  end
62
59
  # If no formatters specified, use defaults.
63
60
  if MetricFu.configuration.formatters.empty?
64
61
  Array(MetricFu::Formatter::DEFAULT).each do |format, o|
65
- MetricFu.configuration.add_formatter(format, o)
62
+ MetricFu.configuration.configure_formatter(format, o)
66
63
  end
67
64
  end
68
65
  end
@@ -0,0 +1,11 @@
1
+ # until https://github.com/flyerhzm/code_analyzer/pull/4 is merged and released
2
+ # see https://github.com/metricfu/metric_fu/issues/123
3
+ require 'code_analyzer'
4
+ class Sexp
5
+ begin
6
+ alias_method :block_type, :block
7
+ undef :block
8
+ rescue NameError
9
+ # we're a-okay
10
+ end
11
+ end
@@ -1,3 +1,3 @@
1
1
  module MetricFu
2
- VERSION = "4.3.1"
2
+ VERSION = "4.4.0"
3
3
  end
data/metric_fu.gemspec CHANGED
@@ -1,39 +1,42 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  $:.push File.expand_path("../lib", __FILE__)
3
3
  require 'metric_fu/version'
4
- require 'metric_fu_requires'
5
4
 
6
5
  Gem::Specification.new do |s|
7
6
  s.name = "metric_fu"
8
- s.platform = Gem::Platform::RUBY
9
- s.version = MetricFu::VERSION
7
+ s.homepage = "https://github.com/metricfu/metric_fu"
10
8
  s.summary = "A fistful of code metrics, with awesome templates and graphs"
9
+ s.description = "Code metrics from Flog, Flay, Saikuro, Churn, Reek, Roodi, Code Statistics, and Rails Best Practices. (and optionally RCov)"
11
10
  s.email = "github@benjaminfleischer.com"
12
- s.homepage = "https://github.com/metricfu/metric_fu"
13
- s.description = "Code metrics from Flog, Flay, Saikuro, Churn, Reek, Roodi, Rails' stats task and Rails Best Practices, and optionally RCov"
14
- s.authors = ["Jake Scruggs", "Sean Soper", "Andre Arko", "Petrik de Heus", "Grant McInnes", "Nick Quaranto", "Édouard Brière", "Carl Youngblood", "Richard Huang", "Dan Mayer", "Benjamin Fleischer"]
15
- s.rubyforge_project = 'metric_fu'
16
- s.required_ruby_version = ">= 1.8.7"
17
- s.required_rubygems_version = ">= 1.3.6"
18
- s.files = `git ls-files`.split($\)
19
- s.test_files = s.files.grep(%r{^(test|spec|features)/})
20
- s.default_executable = %q{metric_fu}
21
- s.executables = s.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
22
- s.require_paths = ["lib"]
23
- s.license = 'MIT'
24
- s.has_rdoc = true
25
- s.extra_rdoc_files = ["HISTORY.md", "CONTRIBUTING.md", "TODO.md", "MIT-LICENSE"]
26
- s.rdoc_options = ["--main", "README.md"]
11
+ s.authors = File.readlines('AUTHORS').map(&:strip)
12
+
13
+ s.rubyforge_project = 'metric_fu'
14
+ s.license = 'MIT'
15
+ s.platform = Gem::Platform::RUBY
16
+ s.version = MetricFu::VERSION
17
+ s.required_ruby_version = ">= 1.9.0"
18
+ s.required_rubygems_version = ">= 1.3.6"
19
+
20
+ s.files = `git ls-files`.split($\)
21
+ s.test_files = s.files.grep(%r{^(test|spec|features)/})
22
+ s.default_executable = %q{metric_fu}
23
+ s.executables = s.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
24
+ s.require_paths = ["lib"]
25
+
26
+ s.has_rdoc = true
27
+ s.extra_rdoc_files = ["HISTORY.md", "CONTRIBUTING.md", "TODO.md", "MIT-LICENSE"]
28
+ s.rdoc_options = ["--main", "README.md"]
27
29
 
28
30
  # metric dependencies
29
31
  s.add_runtime_dependency 'flay', ['~> 2.0.1']
30
32
  s.add_runtime_dependency 'churn', ['~> 0.0.28']
31
- s.add_runtime_dependency 'flog', ['~> 3.2.2']
33
+ s.add_runtime_dependency 'flog', ['~> 4.1.1']
32
34
  s.add_runtime_dependency 'reek', ['~> 1.3.1']
33
35
  s.add_runtime_dependency 'cane', ['~> 2.5.2']
34
- s.add_runtime_dependency 'rails_best_practices', ['~> 1.13.2']
36
+ s.add_runtime_dependency 'rails_best_practices', ['>= 1.14.1', '~> 1.14']
35
37
  s.add_runtime_dependency 'metric_fu-Saikuro', ['>= 1.1.1.0']
36
38
  s.add_runtime_dependency 'metric_fu-roodi', ['>= 2.2.1']
39
+ s.add_runtime_dependency 'code_metrics', ['~> 0.1']
37
40
 
38
41
  # other dependencies
39
42
  # ruby version identification
@@ -1,6 +1,9 @@
1
1
  require 'spec_helper'
2
2
  require 'metric_fu/cli/helper'
3
- MetricFu.run_rcov
3
+ MetricFu.configuration.configure_metric(:rcov) do |rcov|
4
+ rcov.enabled = true
5
+ end
6
+ MetricFu.configure
4
7
 
5
8
  describe MetricFu::Cli::Helper do
6
9
 
@@ -55,25 +58,11 @@ describe MetricFu::Cli::Helper do
55
58
  end
56
59
 
57
60
  if MetricFu.configuration.mri?
58
- context "on Ruby 1.8.7" do
59
-
60
- before { helper.stub(:ruby).and_return("1.8.7") }
61
61
 
62
- it "disables rails_best_practices" do
63
- defaults[:rails_best_practices].should be_false
64
- end
65
-
66
- end
67
-
68
- context "on Ruby 1.9" do
69
-
70
- before { helper.stub(:ruby).and_return("1.9.3") }
71
-
72
- xit "enables Rails Best Practices" do
62
+ it "enables Rails Best Practices" do
73
63
  defaults[:rails_best_practices].should be_true
74
64
  end
75
65
 
76
- end
77
66
  end
78
67
 
79
68
  end
@@ -6,34 +6,42 @@ describe MetricFu::Configuration do
6
6
  ENV['CC_BUILD_ARTIFACTS'] = nil
7
7
  @config = MetricFu.configuration
8
8
  @config.reset
9
+ MetricFu.configuration.configure_metric(:rcov) do |rcov|
10
+ rcov.enabled = true
11
+ end
9
12
  MetricFu.configure
10
- MetricFu.run_rcov
11
- @config.stub :create_directories # no need to create directories for the tests
13
+ mri_only_metrics = MetricFu.mri_only_metrics.reject {|metric| MetricFu::Metric.get_metric(metric).enabled }
14
+ MetricFu.stub(:mri_only_metrics).and_return(mri_only_metrics)
15
+ MetricFu::Io::FileSystem.stub(:create_directories) # no need to create directories for the tests
12
16
  @config
13
17
  end
14
18
 
19
+ def directory(name)
20
+ MetricFu::Io::FileSystem.directory(name)
21
+ end
22
+
15
23
  def base_directory
16
- @config.send(:base_directory)
24
+ directory('base_directory')
17
25
  end
18
26
 
19
27
  def output_directory
20
- @config.send(:output_directory)
28
+ directory('output_directory')
21
29
  end
22
30
 
23
31
  def scratch_directory
24
- @config.send(:scratch_directory)
32
+ directory('scratch_directory')
25
33
  end
26
34
 
27
35
  def template_directory
28
- @config.send(:template_directory)
36
+ directory('template_directory')
29
37
  end
30
38
 
31
39
  def template_class
32
- @config.send(:template_class)
40
+ MetricFu::Formatter::Templates.option('template_class')
33
41
  end
34
42
 
35
43
  def metric_fu_root
36
- @config.send(:metric_fu_root_directory)
44
+ directory('root_directory')
37
45
  end
38
46
  def load_metric(metric)
39
47
  load File.join(MetricFu.metrics_dir, metric, 'init.rb')
@@ -97,27 +105,31 @@ describe MetricFu::Configuration do
97
105
 
98
106
  it 'should set @flay to {:dirs_to_flay => @code_dirs}' do
99
107
  load_metric 'flay'
100
- @config.send(:flay).
101
- should == {:dirs_to_flay => ['lib'], :filetypes=>["rb"]}
108
+ expect(MetricFu::Metric.get_metric(:flay).run_options).to eq(
109
+ {:dirs_to_flay => ['lib'], :filetypes=>["rb"], :minimum_score=>nil}
110
+ )
102
111
  end
103
112
 
104
113
  it 'should set @reek to {:dirs_to_reek => @code_dirs}' do
105
114
  load_metric 'reek'
106
- @config.send(:reek).
107
- should == {:config_file_pattern=>nil, :dirs_to_reek => ['lib']}
115
+ expect(MetricFu::Metric.get_metric(:reek).run_options).to eq(
116
+ {:config_file_pattern=>nil, :dirs_to_reek => ['lib']}
117
+ )
108
118
  end
109
119
 
110
120
  it 'should set @roodi to {:dirs_to_roodi => @code_dirs}' do
111
121
  load_metric 'roodi'
112
- @config.send(:roodi).
113
- should == { :dirs_to_roodi => MetricFu.code_dirs,
114
- :roodi_config => "#{MetricFu.root_dir}/config/roodi_config.yml"}
122
+ expect(MetricFu::Metric.get_metric(:roodi).run_options).to eq(
123
+ { :dirs_to_roodi => directory('code_dirs'),
124
+ :roodi_config => "#{directory('root_directory')}/config/roodi_config.yml"}
125
+ )
115
126
  end
116
127
 
117
128
  it 'should set @churn to {}' do
118
129
  load_metric 'churn'
119
- @config.send(:churn).
120
- should == { :start_date => %q("1 year ago"), :minimum_churn_count => 10}
130
+ expect(MetricFu::Metric.get_metric(:churn).run_options).to eq(
131
+ { :start_date => %q("1 year ago"), :minimum_churn_count => 10}
132
+ )
121
133
  end
122
134
 
123
135
 
@@ -134,8 +146,8 @@ describe MetricFu::Configuration do
134
146
  "-Ispec"
135
147
  ]) do
136
148
  load_metric 'rcov'
137
- @config.send(:rcov).
138
- should == { :environment => 'test',
149
+ expect(MetricFu::Metric.get_metric(:rcov).run_options).to eq(
150
+ { :environment => 'test',
139
151
  :test_files => Dir['{spec,test}/**/*_{spec,test}.rb'],
140
152
  :rcov_opts => [
141
153
  "--sort coverage",
@@ -148,6 +160,7 @@ describe MetricFu::Configuration do
148
160
  "-Ispec"
149
161
  ],
150
162
  :external => nil}
163
+ )
151
164
  end
152
165
 
153
166
  it 'should set @saikuro to { :output_directory => @scratch_directory + "/saikuro",
@@ -158,33 +171,39 @@ describe MetricFu::Configuration do
158
171
  :error_cyclo => "7",
159
172
  :formater => "text" }' do
160
173
  load_metric 'saikuro'
161
- @config.send(:saikuro).
162
- should == { :output_directory => "#{scratch_directory}/saikuro",
174
+ expect(MetricFu::Metric.get_metric(:saikuro).run_options).to eq(
175
+ { :output_directory => "#{scratch_directory}/saikuro",
163
176
  :input_directory => ['lib'],
164
177
  :cyclo => "",
165
178
  :filter_cyclo => "0",
166
179
  :warn_cyclo => "5",
167
180
  :error_cyclo => "7",
168
181
  :formater => "text"}
182
+ )
169
183
  end
170
184
 
171
185
  if MetricFu.configuration.mri?
172
186
  it 'should set @flog to {:dirs_to_flog => @code_dirs}' do
173
187
  load_metric 'flog'
174
- @config.send(:flog).
175
- should == {:dirs_to_flog => ['lib']}
188
+ expect(MetricFu::Metric.get_metric(:flog).run_options).to eq({
189
+ :all => true,
190
+ :continue => true,
191
+ :dirs_to_flog => ["lib"],
192
+ :quiet => true
193
+ })
176
194
  end
177
195
  it 'should set @cane to ' +
178
196
  %q(:dirs_to_cane => @code_dirs, :abc_max => 15, :line_length => 80, :no_doc => 'n', :no_readme => 'y') do
179
197
  load_metric 'cane'
180
- @config.send(:cane).
181
- should == {
182
- :dirs_to_cane => MetricFu.code_dirs,
198
+ expect(MetricFu::Metric.get_metric(:cane).run_options).to eq(
199
+ {
200
+ :dirs_to_cane => directory('code_dirs'),
183
201
  :filetypes => ["rb"],
184
202
  :abc_max => 15,
185
203
  :line_length => 80,
186
204
  :no_doc => "n",
187
205
  :no_readme => "n"}
206
+ )
188
207
  end
189
208
  end
190
209
 
@@ -204,32 +223,33 @@ describe MetricFu::Configuration do
204
223
 
205
224
  describe '#set_metrics ' do
206
225
  it 'should set the metrics to include stats' do
207
- @config.metrics.should include(:stats)
226
+ MetricFu::Metric.enabled_metrics.map(&:name).should include(:stats)
208
227
  end
209
228
  end
210
229
 
211
230
  describe '#set_graphs ' do
212
231
  it 'should set the graphs to include rails_best_practices' do
213
- @config.graphs.should include(:rails_best_practices)
232
+ expect(MetricFu::Metric.get_metric(:rails_best_practices).has_graph?).to be_true
214
233
  end
215
234
  end
216
235
 
217
236
  describe '#set_code_dirs ' do
218
237
  it 'should set the @code_dirs instance var to ["app", "lib"]' do
219
- @config.send(:code_dirs).
238
+ directory('code_dirs').
220
239
  should == ['app','lib']
221
240
  end
222
241
  end
223
242
  it 'should set @stats to {}' do
224
243
  load_metric 'stats'
225
- @config.send(:stats).
226
- should == {}
244
+ expect(MetricFu::Metric.get_metric(:stats).run_options).to eq({
245
+ :additional_test_directories=>[{:glob_pattern=>"./spec/**/*_spec.rb", :file_pattern=>"spec"}],
246
+ :additional_app_directories=>[{:glob_pattern=>"./engines/**/*.rb", :file_pattern=>""}]
247
+ })
227
248
  end
228
249
 
229
250
  it 'should set @rails_best_practices to {}' do
230
251
  load_metric 'rails_best_practices'
231
- @config.send(:rails_best_practices).
232
- should == {}
252
+ expect(MetricFu::Metric.get_metric(:rails_best_practices).run_options).to eql({})
233
253
  end
234
254
  end
235
255
 
@@ -243,57 +263,11 @@ describe MetricFu::Configuration do
243
263
  end
244
264
 
245
265
  it 'should set the available metrics' do
246
- @config.metrics.should =~ [:churn, :flog, :flay, :reek, :roodi, :rcov, :hotspots, :saikuro, :cane] - MetricFu.mri_only_metrics
247
- end
248
-
249
- it 'should set the @code_dirs instance var to ["lib"]' do
250
- @config.send(:code_dirs).should == ['lib']
251
- end
252
- end
253
- end
254
-
255
- describe '#add_attr_accessors_to_self' do
256
-
257
- before(:each) { get_new_config }
258
-
259
- (
260
- [:churn, :flog, :flay, :reek, :roodi, :rcov, :hotspots, :saikuro] -
261
- MetricFu.mri_only_metrics
262
- ).each do |metric|
263
- it "should have a reader for #{metric}" do
264
- expect {
265
- @config.send(metric.to_sym)
266
- }.to_not raise_error
266
+ MetricFu::Metric.enabled_metrics.map(&:name).should =~ [:churn, :flog, :flay, :reek, :roodi, :rcov, :hotspots, :saikuro, :cane, :stats] - MetricFu.mri_only_metrics
267
267
  end
268
268
 
269
- it "should have a writer for #{metric}=" do
270
- expect {
271
- @config.send((metric.to_s + '=').to_sym, '')
272
- }.to_not raise_error
273
- end
274
- end
275
- end
276
-
277
- describe '#add_class_methods_to_metric_fu' do
278
-
279
- before(:each) { get_new_config }
280
-
281
- (
282
- [:churn, :flog, :flay, :reek, :roodi, :rcov, :hotspots, :saikuro, :cane] -
283
- MetricFu.mri_only_metrics
284
-
285
- ).each do |metric|
286
- it "should add a #{metric} class method to the MetricFu module " do
287
- MetricFu.should respond_to(metric)
288
- end
289
- end
290
-
291
- (
292
- [:churn, :flog, :flay, :reek, :roodi, :rcov, :hotspots, :saikuro, :cane] -
293
- MetricFu.mri_only_metrics
294
- ).each do |graph|
295
- it "should add a #{graph} class metrhod to the MetricFu module" do
296
- MetricFu.should respond_to(graph)
269
+ it 'should set the registered code_dirs to ["lib"]' do
270
+ directory('code_dirs').should == ['lib']
297
271
  end
298
272
  end
299
273
  end
@@ -330,12 +304,12 @@ describe MetricFu::Configuration do
330
304
  end
331
305
  end
332
306
 
333
- describe '#add_formatter' do
307
+ describe '#configure_formatter' do
334
308
  before(:each) { get_new_config }
335
309
 
336
310
  context 'given a built-in formatter' do
337
311
  before do
338
- @config.add_formatter('html')
312
+ @config.configure_formatter('html')
339
313
  end
340
314
 
341
315
  it 'adds to the list of formatters' do
@@ -346,7 +320,7 @@ describe MetricFu::Configuration do
346
320
  context 'given a custom formatter by class name' do
347
321
  before do
348
322
  stub_const('MyCustomFormatter', Class.new() { def initialize(*); end })
349
- @config.add_formatter('MyCustomFormatter')
323
+ @config.configure_formatter('MyCustomFormatter')
350
324
  end
351
325
 
352
326
  it 'adds to the list of formatters' do
@@ -357,9 +331,9 @@ describe MetricFu::Configuration do
357
331
  context 'given multiple formatters' do
358
332
  before do
359
333
  stub_const('MyCustomFormatter', Class.new() { def initialize(*); end })
360
- @config.add_formatter('html')
361
- @config.add_formatter('yaml')
362
- @config.add_formatter('MyCustomFormatter')
334
+ @config.configure_formatter('html')
335
+ @config.configure_formatter('yaml')
336
+ @config.configure_formatter('MyCustomFormatter')
363
337
  end
364
338
 
365
339
  it 'adds each to the list of formatters' do