metric_fu 2.1.4.pre4 → 2.1.4.pre5

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.
data/.metrics ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # For testing that this file gets loaded
4
+ puts "Metrics config loaded"
5
+ # example configuration
6
+ # MetricFu::Configuration.run do |config|
7
+ # config.metrics -= [ :rcov ]
8
+ # end
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,19 @@
1
+ How to contribute:
2
+
3
+ 1. Fork metric_fu on github.
4
+ 2. bundle install
5
+ 3. Run the tests ('bundle exec rake')
6
+ 4. Run metric_fu on itself ('bundle exec metric_fu -r')
7
+ 5. Make the changes you want and back them up with tests.
8
+ 6. Make sure two important rake tests still run ('bundle exec rake' and 'bundle exec rake metrics:all')
9
+ 7. Commit and send me a pull request with details as to what has been changed.
10
+
11
+ Extra Credit:
12
+
13
+ 1. Make sure your changes work in 1.8.7, Ruby Enterprise Edition, and 1.9.3 (Hint use 'rvm' to help install multiple rubies)
14
+ 2. Update the documentation here or the rubyforge web page inside the `'home_page'` folder
15
+ 3. Update the History and give yourself credit.
16
+
17
+ The more of the above steps you do the easier it will be for me to merge in which will greatly increase you chances of getting your changes accepted.
18
+
19
+ Also see [Quick guide to writing good bug reports](https://github.com/metricfu/metric_fu/wiki/Issues:-Quick-guide-to-writing-good-bug-reports)
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
- This is the official repository for metric_fu. The original repository by Jake Scruggs at [https://github.com/jscruggs/metric_fu](https://github.com/jscruggs/metric_fu) [has been deprecated.](http://jakescruggs.blogspot.com/2012/08/why-i-abandoned-metricfu.html).
1
+ # MetricFu [![Gem Version](https://badge.fury.io/rb/metric_fu.png)](http://badge.fury.io/rb/metric_fu) [![Build Status](https://travis-ci.org/metricfu/metric_fu.png?branch=master)](http://travis-ci.org/metricfu/metric_fu) [![Code Climate](https://codeclimate.com/github/metricfu/metric_fu.png)](https://codeclimate.com/github/metricfu/metric_fu) [![Dependency Status](https://gemnasium.com/metricfu/metric_fu.png)](https://gemnasium.com/metricfu/metric_fu)
2
2
 
3
- __Installation__
3
+ ## Installation
4
4
 
5
5
  gem install metric_fu
6
6
 
@@ -8,75 +8,48 @@ If you have trouble installing the gem, try adding metric_fu to your Gemfile. Yo
8
8
 
9
9
  See documentation on the rubyforge page for how to customize your metrics. Otherwise, all current information is either in this repo or on the wiki.
10
10
 
11
+ ## Usage
12
+
11
13
  By default, you can run all metrics from the root of an app with the command `metric_fu -r`
12
14
 
13
- You may also wish to use the `metricfu-metrical` fork, which will probably be merged in at some point.
15
+ See `metric_fu --help` for more options
14
16
 
15
- __Compatibility__
17
+ ## Compatibility
16
18
 
17
19
  It is currently testing on MRI 1.8.7, 1.9.2, and 1.9.3
18
20
 
19
21
  * The `japgolly-Saikuro` fork and `metric_fu-roodi` fork are a part of an attempt to get metric_fu working in a modern Ruby environment, specifically compatibility with Ruby 1.9 and Bundler.
22
+ * rcov may fail in ruby 1.9
23
+ * rails_best_practices is disabled in ruby 1.8
20
24
 
21
- * Until we can upgrade to the latest RubyParser, metric_fu will fail on parsing some 1.9 code, e.g. the new hash syntax, and possibly have issues with encodings
22
-
23
-
24
- _Gem Badge_
25
-
26
- [![Gem Version](https://badge.fury.io/rb/metric_fu.png)](http://badge.fury.io/rb/metric_fu)
27
-
28
-
29
- __CI Build Status__
30
-
31
- [![Build Status](https://secure.travis-ci.org/metricfu/metric_fu.png)](http://travis-ci.org/metricfu/metric_fu)
25
+ ## Documentation
32
26
 
33
- This project runs [travis-ci.org](http://travis-ci.org)
27
+ TBD
34
28
 
35
- __Code Quality__
29
+ ### Configuration
36
30
 
37
- [![Code Climate](https://codeclimate.com/badge.png)](https://codeclimate.com/github/metricfu/metric_fu)
31
+ see the .metrics file
38
32
 
39
- This project runs [https://codeclimate.com/](https://codeclimate.com/)
33
+ ### Historical
40
34
 
41
- __Gem Dependencies__
35
+ There is some useful-but-out-of-date documentation about configuring metric_fu at http://metric-fu.rubyforge.org/ and a change log in the the HISTORY file.
42
36
 
43
- [![Dependency Status](https://gemnasium.com/metricfu/metric_fu.png)](https://gemnasium.com/metricfu/metric_fu)
37
+ ## Contributions
44
38
 
45
- This project runs [https://gemnasium.com/metricfu](https://gemnasium.com/metricfu)
39
+ See the TODO for some ideas
46
40
 
47
- ===============================================================================
41
+ See CONTRIBUTING for how to contribute
48
42
 
49
- For documentation, in addition to this file and the wiki, there is some useful-but-out-of-date documentation about configuring metric_fu at http://metric-fu.rubyforge.org/ and a change log in the the HISTORY file.
43
+ ## Resources:
50
44
 
51
- How to contribute:
52
-
53
- 1. Fork metric_fu on github.
54
- 2. bundle install
55
- 3. Run the tests ('bundle exec rake')
56
- 4. Run metric_fu on itself ('bundle exec metric_fu -r')
57
- 5. Make the changes you want and back them up with tests.
58
- 6. Make sure two important rake tests still run ('bundle exec rake' and 'bundle exec rake metrics:all')
59
- 7. Commit and send me a pull request with details as to what has been changed.
60
-
61
- Extra Credit:
62
-
63
- 1. Make sure your changes work in 1.8.7, Ruby Enterprise Edition, and 1.9.3 (Hint use 'rvm' to help install multiple rubies)
64
- 2. Update the documentation here or the rubyforge web page inside the `'home_page'` folder
65
- 3. Update the History and give yourself credit.
66
-
67
-
68
- The more of the above steps you do the easier it will be for me to merge in which will greatly increase you chances of getting your changes accepted.
69
-
70
- Also see [Quick guide to writing good bug reports](https://github.com/metricfu/metric_fu/wiki/Issues:-Quick-guide-to-writing-good-bug-reports)
71
-
72
- Resources:
45
+ This is the official repository for metric_fu. The original repository by Jake Scruggs at [https://github.com/jscruggs/metric_fu](https://github.com/jscruggs/metric_fu) [has been deprecated.](http://jakescruggs.blogspot.com/2012/08/why-i-abandoned-metricfu.html).
73
46
 
74
47
  * Github: http://github.com/metricfu/metric_fu
75
48
  * Issue Tracker: http://github.com/metricfu/metric_fu/issues
76
49
  * Google Group: http://groups.google.com/group/metric_fu
77
50
  * Historical Homepage: http://metric-fu.rubyforge.org/
78
51
 
79
- Original Resources:
52
+ ### Original Resources:
80
53
 
81
54
  * Github: http://github.com/jscruggs/metric_fu
82
55
  * Issue Tracker: http://github.com/jscruggs/metric_fu/issues
data/bin/metric_fu CHANGED
@@ -1,134 +1,9 @@
1
1
  #!/usr/bin/env ruby
2
2
  require 'metric_fu'
3
- require 'optparse'
3
+ require 'metric_fu/cli/client'
4
4
 
5
- # see https://github.com/grosser/pru/blob/master/bin/pru
6
- module MetricFu
7
- class CLIHelper
8
- def initialize
9
- @metric_fu = MetricFu::Run.new
10
- end
11
- def run
12
- @metric_fu.run
13
- complete
14
- end
15
- def version
16
- MetricFu::VERSION
17
- end
18
- def shutdown
19
- out "\nShuting down. Bye"
20
- exit(1)
21
- end
22
- def banner
23
- "MetricFu: A Fistful of code metrics"
24
- end
25
- def usage
26
- <<-EOS
27
- #{banner}
28
- Use --help for help
29
- EOS
30
-
31
- end
32
- def executable_name
33
- 'metric_fu'
34
- end
35
- private
36
- def out(text)
37
- STDOUT.puts text
38
- end
39
- def error(text)
40
- STDERR.puts text
41
- end
42
- def complete
43
- out "all done"
44
- exit(0)
45
- end
46
- end
47
- end
48
- cli = MetricFu::CLIHelper.new
5
+ cli = MetricFu::Cli::Client.new
49
6
  # see http://obtiva.com/blog/185-fun-with-ruby-it-s-a-trap
50
7
  trap("INT") { cli.shutdown }
51
8
 
52
- require 'optparse'
53
- # see https://github.com/florianpilz/CLI-Option-Parser-Examples
54
- # https://raw.github.com/florianpilz/micro-optparse/master/lib/micro-optparse/parser.rb
55
- module MicroOptParse
56
- class Parser
57
- attr_accessor :banner, :version
58
- def initialize
59
- @options = []
60
- @used_short = []
61
- @default_values = nil
62
- yield self if block_given?
63
- end
64
-
65
- def option(name, desc, settings = {})
66
- @options << [name, desc, settings]
67
- end
68
-
69
- def short_from(name)
70
- name.to_s.chars.each do |c|
71
- next if @used_short.include?(c) || c == "_"
72
- return c # returns from short_from method
73
- end
74
- end
75
-
76
- def validate(options) # remove this method if you want fewer lines of code and don't need validations
77
- options.each_pair do |key, value|
78
- opt = @options.find_all{ |o| o[0] == key }.first
79
- key = "--" << key.to_s.gsub("_", "-")
80
- unless opt[2][:value_in_set].nil? || opt[2][:value_in_set].include?(value)
81
- puts "Parameter for #{key} must be in [" << opt[2][:value_in_set].join(", ") << "]" ; exit(1)
82
- end
83
- unless opt[2][:value_matches].nil? || opt[2][:value_matches] =~ value
84
- puts "Parameter for #{key} must match /" << opt[2][:value_matches].source << "/" ; exit(1)
85
- end
86
- unless opt[2][:value_satisfies].nil? || opt[2][:value_satisfies].call(value)
87
- puts "Parameter for #{key} must satisfy given conditions (see description)" ; exit(1)
88
- end
89
- end
90
- end
91
-
92
- def process!(arguments = ARGV)
93
- @result = (@default_values || {}).clone # reset or new
94
- @optionparser ||= OptionParser.new do |p| # prepare only once
95
- @options.each do |o|
96
- @used_short << short = o[2][:short] || short_from(o[0])
97
- @result[o[0]] = o[2][:default] || false # set default
98
- klass = o[2][:default].class == Fixnum ? Integer : o[2][:default].class
99
-
100
- if [TrueClass, FalseClass, NilClass].include?(klass) # boolean switch
101
- p.on("-" << short, "--[no-]" << o[0].to_s.gsub("_", "-"), o[1]) {|x| @result[o[0]] = x}
102
- else # argument with parameter
103
- p.on("-" << short, "--" << o[0].to_s.gsub("_", "-") << " " << o[2][:default].to_s, klass, o[1]) {|x| @result[o[0]] = x}
104
- end
105
- end
106
-
107
- p.banner = @banner unless @banner.nil?
108
- p.on_tail("-h", "--help", "Show this message") {puts p ; exit}
109
- short = @used_short.include?("v") ? "-V" : "-v"
110
- p.on_tail(short, "--version", "Print version") {puts @version ; exit} unless @version.nil?
111
- @default_values = @result.clone # save default values to reset @result in subsequent calls
112
- end
113
-
114
- begin
115
- @optionparser.parse!(arguments)
116
- rescue OptionParser::ParseError => e
117
- puts e.message ; exit(1)
118
- end
119
-
120
- validate(@result) if self.respond_to?("validate")
121
- @result
122
- end
123
- end
124
- end
125
- options = MicroOptParse::Parser.new do |p|
126
- p.banner = cli.banner
127
- p.version = cli.version
128
- p.option :run, "Run all metrics with defaults"
129
- end.process!
130
- if options[:run]
131
- cli.run
132
- else
133
- STDOUT.puts cli.usage
134
- end
9
+ cli.run
data/bin/mf-stats CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby_noexec_wrapper
2
2
  require 'rubygems'
3
3
  begin
4
- puts File.exists?('Gemfile') && `bundle && bundle exec rake stats`
4
+ puts File.exists?('Gemfile') && `bundle check && bundle exec rake stats || rake stats`
5
5
  rescue StandardError, LoadError => e
6
6
  puts `rake stats`
7
7
  end
@@ -0,0 +1,26 @@
1
+ require 'metric_fu'
2
+ require 'metric_fu/cli/helper'
3
+ require 'metric_fu/cli/parser'
4
+ module MetricFu
5
+ module Cli
6
+ class Client
7
+
8
+ def initialize
9
+ @helper = MetricFu::Cli::Helper.new
10
+ end
11
+ def shutdown
12
+ @helper.shutdown
13
+ end
14
+ def run
15
+ options = @helper.process_options
16
+ mf_debug "Got options #{options.inspect}"
17
+ if options[:run]
18
+ @helper.run(options)
19
+ else
20
+ STDOUT.puts @helper.usage
21
+ end
22
+ end
23
+
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,62 @@
1
+ require 'metric_fu'
2
+ require 'metric_fu/cli/parser'
3
+ # see https://github.com/grosser/pru/blob/master/bin/pru
4
+ module MetricFu
5
+ module Cli
6
+ class Helper
7
+ def run(options={})
8
+ @metric_fu = MetricFu::Run.new(options)
9
+ @metric_fu.run
10
+ complete
11
+ end
12
+ def version
13
+ MetricFu::VERSION
14
+ end
15
+ def shutdown
16
+ out "\nShuting down. Bye"
17
+ exit(1)
18
+ end
19
+ def banner
20
+ "MetricFu: A Fistful of code metrics"
21
+ end
22
+ def usage
23
+ <<-EOS
24
+ #{banner}
25
+ Use --help for help
26
+ EOS
27
+ end
28
+ def executable_name
29
+ 'metric_fu'
30
+ end
31
+
32
+ def metrics
33
+ MetricFu.configuration.metrics.sort_by(&:to_s)
34
+ end
35
+
36
+ def process_options(argv=ARGV.dup)
37
+ options = MetricFu::Cli::MicroOptParse::Parser.new do |p|
38
+ p.banner = self.banner
39
+ p.version = self.version
40
+ p.option :run, "Run all metrics with defaults", :default => false
41
+ metrics.each do |metric|
42
+ p.option metric.to_sym, "Enables or disables #{metric.to_s.titleize}", :default => true #, :value_in_set => [true, false]
43
+ end
44
+ p.option :open, "Open report in browser", :default => true
45
+ end.process!(argv)
46
+ options
47
+ end
48
+
49
+ private
50
+ def out(text)
51
+ STDOUT.puts text
52
+ end
53
+ def error(text)
54
+ STDERR.puts text
55
+ end
56
+ def complete
57
+ out "all done"
58
+ exit(0)
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,78 @@
1
+ require 'optparse'
2
+ module MetricFu
3
+ module Cli
4
+ # see https://github.com/florianpilz/CLI-Option-Parser-Examples
5
+ # https://raw.github.com/florianpilz/micro-optparse/master/lib/micro-optparse/parser.rb
6
+ module MicroOptParse
7
+ class Parser
8
+ attr_accessor :banner, :version
9
+ def initialize
10
+ @options = []
11
+ @used_short = []
12
+ @default_values = nil
13
+ yield self if block_given?
14
+ end
15
+
16
+ def option(name, desc, settings = {})
17
+ @options << [name, desc, settings]
18
+ end
19
+
20
+ def short_from(name)
21
+ name.to_s.chars.each do |c|
22
+ next if @used_short.include?(c) || c == "_"
23
+ return c # returns from short_from method
24
+ end
25
+ end
26
+
27
+ def validate(options) # remove this method if you want fewer lines of code and don't need validations
28
+ options.each_pair do |key, value|
29
+ opt = @options.find_all{ |o| o[0] == key }.first
30
+ key = "--" << key.to_s.gsub("_", "-")
31
+ unless opt[2][:value_in_set].nil? || opt[2][:value_in_set].include?(value)
32
+ puts "Parameter for #{key} must be in [" << opt[2][:value_in_set].join(", ") << "]" ; exit(1)
33
+ end
34
+ unless opt[2][:value_matches].nil? || opt[2][:value_matches] =~ value
35
+ puts "Parameter for #{key} must match /" << opt[2][:value_matches].source << "/" ; exit(1)
36
+ end
37
+ unless opt[2][:value_satisfies].nil? || opt[2][:value_satisfies].call(value)
38
+ puts "Parameter for #{key} must satisfy given conditions (see description)" ; exit(1)
39
+ end
40
+ end
41
+ end
42
+
43
+ def process!(arguments = ARGV)
44
+ @result = (@default_values || {}).clone # reset or new
45
+ @optionparser ||= OptionParser.new do |p| # prepare only once
46
+ @options.each do |o|
47
+ @used_short << short = o[2][:short] || short_from(o[0])
48
+ @result[o[0]] = o[2][:default] || false # set default
49
+ klass = o[2][:default].class == Fixnum ? Integer : o[2][:default].class
50
+
51
+ if [TrueClass, FalseClass, NilClass].include?(klass) # boolean switch
52
+ p.on("-" << short, "--[no-]" << o[0].to_s.gsub("_", "-"), o[1]) {|x| @result[o[0]] = x}
53
+ else # argument with parameter
54
+ p.on("-" << short, "--" << o[0].to_s.gsub("_", "-") << " " << o[2][:default].to_s, klass, o[1]) {|x| @result[o[0]] = x}
55
+ end
56
+ end
57
+
58
+ p.banner = @banner unless @banner.nil?
59
+ p.on_tail("-h", "--help", "Show this message") {puts p ; exit}
60
+ short = @used_short.include?("v") ? "-V" : "-v"
61
+ p.on_tail(short, "--version", "Print version") {puts @version ; exit} unless @version.nil?
62
+ @default_values = @result.clone # save default values to reset @result in subsequent calls
63
+ end
64
+
65
+ begin
66
+ @optionparser.parse!(arguments)
67
+ rescue OptionParser::ParseError => e
68
+ puts e.message ; exit(1)
69
+ end
70
+
71
+ validate(@result) if self.respond_to?("validate")
72
+ @result
73
+ end
74
+ end
75
+ end
76
+
77
+ end
78
+ end
@@ -1,5 +1,7 @@
1
1
  require 'fileutils'
2
+ require 'rbconfig'
2
3
  MetricFu.reporting_require { 'templates/awesome/awesome_template' }
4
+ MetricFu.logging_require { 'mf_debugger' }
3
5
  module MetricFu
4
6
 
5
7
 
@@ -49,6 +51,10 @@ module MetricFu
49
51
  MfDebugger::Logger.debug_on = toggle
50
52
  end
51
53
 
54
+ def mf_debug(msg)
55
+ MfDebugger.mf_debug msg
56
+ end
57
+
52
58
  # TODO review if these code is functionally duplicated in the
53
59
  # base generator initialize
54
60
  def reset
@@ -113,11 +119,13 @@ module MetricFu
113
119
  end
114
120
 
115
121
  def platform #:nodoc:
122
+ # TODO, change
123
+ # RbConfig::CONFIG['ruby_install_name'].dup
116
124
  return RUBY_PLATFORM
117
125
  end
118
126
 
119
127
  def self.ruby_strangely_makes_accessors_private?
120
- !!(RUBY_VERSION =~ /1.9.2/)
128
+ !!(RUBY_VERSION =~ /1.9.2/) || defined?(JRUBY_VERSION)
121
129
  end
122
130
  protected unless ruby_strangely_makes_accessors_private?
123
131
 
@@ -1,5 +1,6 @@
1
1
  require 'pathname'
2
2
  require 'optparse'
3
+ require 'rbconfig'
3
4
  require 'flog'
4
5
  class RubyParser
5
6
  alias_method :original_process, :process
@@ -33,7 +34,7 @@ module MetricFu
33
34
  @flogger.flog files
34
35
 
35
36
  rescue LoadError
36
- if RUBY_PLATFORM =~ /java/
37
+ if defined?(JRUBY_VERSION)
37
38
  puts 'running in jruby - flog tasks not available'
38
39
  end
39
40
  end
@@ -1,18 +1,20 @@
1
1
  MetricFu::Configuration.run do |config|
2
2
  config.add_metric(:rcov)
3
3
  config.add_graph(:rcov)
4
+ rcov_opts = [
5
+ "--sort coverage",
6
+ "--no-html",
7
+ "--text-coverage",
8
+ "--no-color",
9
+ "--profile",
10
+ "--exclude-only '.*'",
11
+ '--include-file "\Aapp,\Alib"'
12
+ ]
13
+ rcov_opts << "-Ispec" if File.exist?("spec")
4
14
  config.configure_metric(:rcov,
5
15
  { :environment => 'test',
6
- :test_files => ['test/**/*_test.rb',
7
- 'spec/spec_helper.rb', # NOTE: ensure it is loaded before the specs
8
- 'spec/**/*_spec.rb'],
9
- :rcov_opts => ["--sort coverage",
10
- "--no-html",
11
- "--text-coverage",
12
- "--no-color",
13
- "--profile",
14
- "--rails",
15
- "--exclude /gems/,/Library/,/usr/,spec"],
16
+ :test_files => Dir['{spec,test}/**/*_{spec,test}.rb'],
17
+ :rcov_opts => rcov_opts,
16
18
  :external => nil
17
19
  })
18
20
  end
data/lib/metric_fu/run.rb CHANGED
@@ -1,8 +1,10 @@
1
1
  MetricFu.configure
2
2
  module MetricFu
3
3
  class Run
4
- def initialize
4
+ def initialize(options={})
5
5
  STDOUT.sync = true
6
+ load_user_configuration
7
+ disable_metrics(options)
6
8
  end
7
9
  def run
8
10
  run_reports
@@ -13,8 +15,9 @@ module MetricFu
13
15
 
14
16
  # ensure :hotspots runs last
15
17
  def report_metrics(metrics=MetricFu.metrics)
16
- hotspots = metrics.delete(:hotspots)
17
- MetricFu.metrics.push(:hotspots)
18
+ MetricFu.configuration.metrics -= [ :hotspots ]
19
+ MetricFu.configuration.metrics += [ :hotspots ]
20
+ MetricFu.configuration.metrics
18
21
  end
19
22
  def run_reports
20
23
  report_metrics.each {|metric|
@@ -50,6 +53,22 @@ module MetricFu
50
53
  MetricFu.report.show_in_browser(MetricFu.output_directory)
51
54
  end
52
55
  end
56
+ private
57
+ def load_user_configuration
58
+ file = File.join(Dir.pwd, '.metrics')
59
+ load file if File.exist?(file)
60
+ end
61
+ def disable_metrics(options)
62
+ report_metrics.each do |metric|
63
+ if options[metric.to_sym]
64
+ mf_debug "using metric #{metric}"
65
+ else
66
+ mf_debug "disabling metric #{metric}"
67
+ MetricFu.configuration.metrics -= [ metric ]
68
+ MetricFu.configuration.graphs -= [ metric ]
69
+ mf_debug "active metrics are #{MetricFu.configuration.metrics.inspect}"
70
+ end
71
+ end
72
+ end
53
73
  end
54
74
  end
55
-
@@ -1,3 +1,3 @@
1
1
  module MetricFu
2
- VERSION = "2.1.4.pre4"
2
+ VERSION = "2.1.4.pre5"
3
3
  end
@@ -0,0 +1,146 @@
1
+ require 'spec_helper'
2
+ require 'metric_fu/cli/helper'
3
+
4
+ describe MetricFu::Cli::Helper do
5
+
6
+ describe "defaults" do
7
+
8
+ let(:helper) { MetricFu::Cli::Helper.new }
9
+ let(:defaults) { helper.process_options }
10
+
11
+ context "on every Ruby version" do
12
+
13
+ it "opens the report in a browser" do
14
+ defaults[:open].should be_true
15
+ end
16
+
17
+ it "enables Flog" do
18
+ defaults[:flog].should be_true
19
+ end
20
+
21
+ it "enables Flay" do
22
+ defaults[:flay].should be_true
23
+ end
24
+
25
+ it "enables Reek" do
26
+ defaults[:reek].should be_true
27
+ end
28
+
29
+ it "enables Hotspots" do
30
+ defaults[:hotspots].should be_true
31
+ end
32
+
33
+ it "enables Churn" do
34
+ defaults[:churn].should be_true
35
+ end
36
+
37
+ it "enables Saikuro" do
38
+ defaults[:saikuro].should be_true
39
+ end
40
+
41
+ it "enables RCov" do
42
+ defaults[:rcov].should be_true
43
+ end
44
+
45
+ end
46
+
47
+ context "on Ruby 1.8.7" do
48
+
49
+ before { helper.stub(:ruby).and_return("1.8.7") }
50
+
51
+ it "disables rails_best_practices" do
52
+ defaults[:rails_best_practices].should be_false
53
+ end
54
+
55
+ end
56
+
57
+ context "on Ruby 1.9" do
58
+
59
+ before { helper.stub(:ruby).and_return("1.9.3") }
60
+
61
+ xit "enables Rails Best Practices" do
62
+ defaults[:rails_best_practices].should be_true
63
+ end
64
+
65
+ end
66
+
67
+ end
68
+
69
+ describe ".parse" do
70
+ let(:helper) { MetricFu::Cli::Helper.new }
71
+
72
+ it "turns open in browser off" do
73
+ helper.process_options(["--no-open"])[:open].should be_false
74
+ end
75
+
76
+ it "turns open in browser on" do
77
+ helper.process_options(["--open"])[:open].should be_true
78
+ end
79
+
80
+ it "turns saikuro off" do
81
+ helper.process_options(["--no-saikuro"])[:saikuro].should be_false
82
+ end
83
+
84
+ it "turns saikuro on" do
85
+ helper.process_options(["--saikuro"])[:saikuro].should be_true
86
+ end
87
+
88
+ it "turns churn off" do
89
+ helper.process_options(["--no-churn"])[:churn].should be_false
90
+ end
91
+
92
+ it "turns churn on" do
93
+ helper.process_options(["--churn"])[:churn].should be_true
94
+ end
95
+
96
+ it "turns flay off" do
97
+ helper.process_options(["--no-flay"])[:flay].should be_false
98
+ end
99
+
100
+ it "turns flay on" do
101
+ helper.process_options(["--flay"])[:flay].should be_true
102
+ end
103
+
104
+ it "turns flog off" do
105
+ helper.process_options(["--no-flog"])[:flog].should be_false
106
+ end
107
+
108
+ it "turns flog on" do
109
+ helper.process_options(["--flog"])[:flog].should be_true
110
+ end
111
+
112
+ it "turns hotspots off" do
113
+ helper.process_options(["--no-hotspots"])[:hotspots].should be_false
114
+ end
115
+
116
+ it "turns hotspots on" do
117
+ helper.process_options(["--hotspots"])[:hotspots].should be_true
118
+ end
119
+
120
+ it "turns rcov off" do
121
+ helper.process_options(["--no-rcov"])[:rcov].should be_false
122
+ end
123
+
124
+ it "turns rcov on" do
125
+ helper.process_options(["--rcov"])[:rcov].should be_true
126
+ end
127
+
128
+ it "turns reek off" do
129
+ helper.process_options(["--no-reek"])[:reek].should be_false
130
+ end
131
+
132
+ it "turns reek on" do
133
+ helper.process_options(["--reek"])[:reek].should be_true
134
+ end
135
+
136
+ it "turns roodi off" do
137
+ helper.process_options(["--no-roodi"])[:roodi].should be_false
138
+ end
139
+
140
+ it "turns roodi on" do
141
+ helper.process_options(["--roodi"])[:roodi].should be_true
142
+ end
143
+
144
+ end
145
+
146
+ end
@@ -12,27 +12,27 @@ describe MetricFu::Configuration do
12
12
  end
13
13
 
14
14
  def base_directory
15
- @config.instance_variable_get(:@base_directory)
15
+ @config.send(:base_directory)
16
16
  end
17
17
 
18
18
  def output_directory
19
- @config.instance_variable_get(:@output_directory)
19
+ @config.send(:output_directory)
20
20
  end
21
21
 
22
22
  def scratch_directory
23
- @config.instance_variable_get(:@scratch_directory)
23
+ @config.send(:scratch_directory)
24
24
  end
25
25
 
26
26
  def template_directory
27
- @config.instance_variable_get(:@template_directory)
27
+ @config.send(:template_directory)
28
28
  end
29
29
 
30
30
  def template_class
31
- @config.instance_variable_get(:@template_class)
31
+ @config.send(:template_class)
32
32
  end
33
33
 
34
34
  def metric_fu_root
35
- @config.instance_variable_get(:@metric_fu_root_directory)
35
+ @config.send(:metric_fu_root_directory)
36
36
  end
37
37
  def load_metric(metric)
38
38
  load File.join(MetricFu.metrics_dir, metric, 'init.rb')
@@ -96,58 +96,62 @@ describe MetricFu::Configuration do
96
96
 
97
97
  it 'should set @flay to {:dirs_to_flay => @code_dirs}' do
98
98
  load_metric 'flay'
99
- @config.instance_variable_get(:@flay).
99
+ @config.send(:flay).
100
100
  should == {:dirs_to_flay => ['lib'], :filetypes=>["rb"], :minimum_score => 100}
101
101
  end
102
102
 
103
103
  it 'should set @flog to {:dirs_to_flog => @code_dirs}' do
104
104
  load_metric 'flog'
105
- @config.instance_variable_get(:@flog).
105
+ @config.send(:flog).
106
106
  should == {:dirs_to_flog => ['lib']}
107
107
  end
108
108
 
109
109
  it 'should set @reek to {:dirs_to_reek => @code_dirs}' do
110
110
  load_metric 'reek'
111
- @config.instance_variable_get(:@reek).
111
+ @config.send(:reek).
112
112
  should == {:config_file_pattern=>nil, :dirs_to_reek => ['lib']}
113
113
  end
114
114
 
115
115
  it 'should set @roodi to {:dirs_to_roodi => @code_dirs}' do
116
116
  load_metric 'roodi'
117
- @config.instance_variable_get(:@roodi).
117
+ @config.send(:roodi).
118
118
  should == { :dirs_to_roodi => MetricFu.code_dirs,
119
119
  :roodi_config => "#{MetricFu.root_dir}/config/roodi_config.yml"}
120
120
  end
121
121
 
122
122
  it 'should set @churn to {}' do
123
123
  load_metric 'churn'
124
- @config.instance_variable_get(:@churn).
124
+ @config.send(:churn).
125
125
  should == { :start_date => %q("1 year ago"), :minimum_churn_count => 10}
126
126
  end
127
127
 
128
128
 
129
- it 'should set @rcov to { :test_files => ["test/**/*_test.rb",
130
- "spec/**/*_spec.rb"]
131
- :rcov_opts => ["--sort coverage",
132
- "--no-html",
133
- "--text-coverage",
134
- "--no-color",
135
- "--profile",
136
- "--rails",
137
- "--exclude /gems/,/Library/,/usr/,spec"]}' do
129
+ it 'should set @rcov to ' +
130
+ %q(:test_files => Dir['{spec,test}/**/*_{spec,test}.rb'],
131
+ :rcov_opts => [
132
+ "--sort coverage",
133
+ "--no-html",
134
+ "--text-coverage",
135
+ "--no-color",
136
+ "--profile",
137
+ "--exclude-only '.*'",
138
+ '--include-file "\Aapp,\Alib"',
139
+ "-Ispec"
140
+ ]) do
138
141
  load_metric 'rcov'
139
- @config.instance_variable_get(:@rcov).
142
+ @config.send(:rcov).
140
143
  should == { :environment => 'test',
141
- :test_files => ['test/**/*_test.rb',
142
- 'spec/spec_helper.rb',
143
- 'spec/**/*_spec.rb'],
144
- :rcov_opts => ["--sort coverage",
145
- "--no-html",
146
- "--text-coverage",
147
- "--no-color",
148
- "--profile",
149
- "--rails",
150
- "--exclude /gems/,/Library/,/usr/,spec"],
144
+ :test_files => Dir['{spec,test}/**/*_{spec,test}.rb'],
145
+ :rcov_opts => [
146
+ "--sort coverage",
147
+ "--no-html",
148
+ "--text-coverage",
149
+ "--no-color",
150
+ "--profile",
151
+ "--exclude-only '.*'",
152
+ '--include-file "\Aapp,\Alib"',
153
+ "-Ispec"
154
+ ],
151
155
  :external => nil}
152
156
  end
153
157
 
@@ -159,7 +163,7 @@ describe MetricFu::Configuration do
159
163
  :error_cyclo => "7",
160
164
  :formater => "text" }' do
161
165
  load_metric 'saikuro'
162
- @config.instance_variable_get(:@saikuro).
166
+ @config.send(:saikuro).
163
167
  should == { :output_directory => "#{scratch_directory}/saikuro",
164
168
  :input_directory => ['lib'],
165
169
  :cyclo => "",
@@ -189,27 +193,35 @@ describe MetricFu::Configuration do
189
193
  end
190
194
 
191
195
  describe '#set_graphs ' do
192
- it 'should set the graphs to include rails_best_practices' do
193
- @config.graphs.should include(:rails_best_practices)
196
+ if RUBY_VERSION < '1.9'
197
+ it 'should not set the graphs to include rails_best_practices for ruby 1.8' do
198
+ @config.graphs.should_not include(:rails_best_practices)
199
+ end
200
+ else
201
+ it 'should set the graphs to include rails_best_practices' do
202
+ @config.graphs.should include(:rails_best_practices)
203
+ end
194
204
  end
195
205
  end
196
206
 
197
207
  describe '#set_code_dirs ' do
198
208
  it 'should set the @code_dirs instance var to ["app", "lib"]' do
199
- @config.instance_variable_get(:@code_dirs).
209
+ @config.send(:code_dirs).
200
210
  should == ['app','lib']
201
211
  end
202
212
  end
203
213
  it 'should set @stats to {}' do
204
214
  load_metric 'stats'
205
- @config.instance_variable_get(:@stats).
215
+ @config.send(:stats).
206
216
  should == {}
207
217
  end
208
218
 
209
- it 'should set @rails_best_practices to {}' do
210
- load_metric 'rails_best_practices'
211
- @config.instance_variable_get(:@rails_best_practices).
212
- should == {}
219
+ unless RUBY_VERSION < '1.9'
220
+ it 'should set @rails_best_practices to {}' do
221
+ load_metric 'rails_best_practices'
222
+ @config.send(:rails_best_practices).
223
+ should == {}
224
+ end
213
225
  end
214
226
  end
215
227
 
@@ -227,7 +239,7 @@ describe MetricFu::Configuration do
227
239
  end
228
240
 
229
241
  it 'should set the @code_dirs instance var to ["lib"]' do
230
- @config.instance_variable_get(:@code_dirs).should == ['lib']
242
+ @config.send(:code_dirs).should == ['lib']
231
243
  end
232
244
  end
233
245
  end
@@ -238,11 +250,15 @@ describe MetricFu::Configuration do
238
250
 
239
251
  [:churn, :flog, :flay, :reek, :roodi, :rcov, :hotspots, :saikuro].each do |metric|
240
252
  it "should have a reader for #{metric}" do
241
- @config.respond_to?(metric).should be_true
253
+ expect {
254
+ @config.send(metric.to_sym)
255
+ }.to_not raise_error
242
256
  end
243
257
 
244
258
  it "should have a writer for #{metric}=" do
245
- @config.respond_to?((metric.to_s + '=').to_sym).should be_true
259
+ expect {
260
+ @config.send((metric.to_s + '=').to_sym, '')
261
+ }.to_not raise_error
246
262
  end
247
263
  end
248
264
  end
@@ -3,7 +3,10 @@ require "spec_helper"
3
3
  describe Flay do
4
4
  describe "emit method" do
5
5
  it "should look at the dirs" do
6
- MetricFu::Configuration.run {|config| config.flay = { :dirs_to_flay => ['app', 'lib'], :filetypes => ['rb'] } }
6
+ MetricFu::Configuration.run {|config|
7
+ config.add_metric(:flay)
8
+ config.configure_metric(:flay, { :dirs_to_flay => ['app', 'lib'], :filetypes => ['rb'] })
9
+ }
7
10
  File.stub!(:directory?).and_return(true)
8
11
  @flay = MetricFu::Flay.new('base_dir')
9
12
 
@@ -12,7 +15,10 @@ describe Flay do
12
15
  end
13
16
 
14
17
  it "should limit flay scores by the minimum_score" do
15
- MetricFu::Configuration.run {|config| config.flay = { :dirs_to_flay => [], :minimum_score => 99 } }
18
+ MetricFu::Configuration.run {|config|
19
+ config.add_metric(:flay)
20
+ config.configure_metric(:flay, { :dirs_to_flay => [], :minimum_score => 99 })
21
+ }
16
22
  File.stub!(:directory?).and_return(true)
17
23
  @flay = MetricFu::Flay.new('base_dir')
18
24
 
@@ -4,7 +4,8 @@ describe Reek do
4
4
  describe "emit" do
5
5
  it "should include config parameters" do
6
6
  MetricFu::Configuration.run do |config|
7
- config.reek = {:config_file_pattern => 'lib/config/*.reek', :dirs_to_reek => []}
7
+ config.add_metric(:reek)
8
+ config.configure_metric(:reek,{:config_file_pattern => 'lib/config/*.reek', :dirs_to_reek => []})
8
9
  end
9
10
  reek = MetricFu::Reek.new
10
11
  reek.should_receive(:`).with(/--config lib\/config\/\*\.reek/).and_return("")
@@ -4,7 +4,8 @@ describe Roodi do
4
4
  describe "emit" do
5
5
  it "should add config options when present" do
6
6
  MetricFu::Configuration.run do |config|
7
- config.roodi = {:roodi_config => 'lib/config/roodi_config.yml', :dirs_to_roodi => []}
7
+ config.add_metric(:roodi)
8
+ config.configure_metric(:roodi,{:roodi_config => 'lib/config/roodi_config.yml', :dirs_to_roodi => []})
8
9
  end
9
10
  roodi = MetricFu::Roodi.new
10
11
  roodi.should_receive(:`).with(/-config=lib\/config\/roodi_config\.yml/).and_return("")
@@ -13,7 +14,8 @@ describe Roodi do
13
14
 
14
15
  it "should NOT add config options when NOT present" do
15
16
  MetricFu::Configuration.run do |config|
16
- config.roodi = {:dirs_to_roodi => []}
17
+ config.add_metric(:roodi)
18
+ config.configure_metric(:roodi,{:dirs_to_roodi => []})
17
19
  end
18
20
  roodi = MetricFu::Roodi.new
19
21
  roodi.stub(:`)
@@ -21,4 +23,4 @@ describe Roodi do
21
23
  roodi.emit
22
24
  end
23
25
  end
24
- end
26
+ end
data/spec/run_spec.rb ADDED
@@ -0,0 +1,53 @@
1
+ require 'spec_helper'
2
+ require 'metric_fu/cli/helper'
3
+
4
+ describe MetricFu, "running" do
5
+
6
+ let(:helper) { MetricFu::Cli::Helper.new }
7
+
8
+ before do
9
+ FileUtils.rm_rf("tmp/metric_fu")
10
+ end
11
+
12
+ it "all these tests should not rely on shelling out to the command line" do
13
+ pending("shelling to bundler is very slow")
14
+ end
15
+
16
+ xit "has a clean start" do
17
+ File.should_not exist("tmp/metric_fu")
18
+ end
19
+
20
+ xit "loads the .metrics file" do
21
+ out = metric_fu
22
+ out.should include "Metrics config loaded"
23
+ end
24
+
25
+ xit "creates a report yaml file" do
26
+ expect { metric_fu }.to create_file("tmp/metric_fu/report.yml")
27
+ end
28
+
29
+ xit "creates a report html file" do
30
+ expect { metric_fu }.to create_file("tmp/metric_fu/output/index.html")
31
+ end
32
+
33
+ xit "displays help" do
34
+ out = metric_fu("bundle exec metric_fu --help")
35
+ out.should include helper.banner
36
+ end
37
+
38
+ xit "displays version" do
39
+ out = metric_fu("bundle exec metric_fu --version")
40
+ out.should == "#{MetricFu::VERSION}"
41
+ end
42
+
43
+ xit "errors on unknown flags" do
44
+ expect { metric_fu "--asdasdasda" }.to raise_error
45
+ end
46
+
47
+ def metric_fu(command = "--no-open")
48
+ results = `metric_fu #{command} 2>&1`
49
+ $?.to_i.should eq(0), "The command 'metric_fu #{command}' failed!\n\n#{results}"
50
+ results.strip
51
+ end
52
+
53
+ end
@@ -0,0 +1,30 @@
1
+ RSpec::Matchers.define :create_file do |expected|
2
+
3
+ match do |block|
4
+ @before = File.exist?(expected)
5
+ block.call
6
+ @after = File.exist?(expected)
7
+ !@before && @after
8
+ end
9
+
10
+ failure_message_for_should do |block|
11
+ existed_before_message expected do
12
+ "The file #{expected.inspect} was not created"
13
+ end
14
+ end
15
+
16
+ failure_message_for_should_not do |block|
17
+ existed_before_message expected do
18
+ "The file #{expected.inspect} was created"
19
+ end
20
+ end
21
+
22
+ def existed_before_message(expected)
23
+ if @before
24
+ "The file #{expected.inspect} existed before, so this test doesn't work"
25
+ else
26
+ yield
27
+ end
28
+ end
29
+
30
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: metric_fu
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.4.pre4
4
+ version: 2.1.4.pre5
5
5
  prerelease: 6
6
6
  platform: ruby
7
7
  authors:
@@ -19,7 +19,7 @@ authors:
19
19
  autorequire:
20
20
  bindir: bin
21
21
  cert_chain: []
22
- date: 2013-02-03 00:00:00.000000000 Z
22
+ date: 2013-02-04 00:00:00.000000000 Z
23
23
  dependencies:
24
24
  - !ruby/object:Gem::Dependency
25
25
  name: rails_best_practices
@@ -330,8 +330,10 @@ extensions: []
330
330
  extra_rdoc_files: []
331
331
  files:
332
332
  - .gitignore
333
+ - .metrics
333
334
  - .rspec
334
335
  - .travis.yml
336
+ - CONTRIBUTING.md
335
337
  - Gemfile
336
338
  - HISTORY.md
337
339
  - MIT-LICENSE
@@ -365,6 +367,9 @@ files:
365
367
  - home_page/title.gif
366
368
  - home_page/title_back.gif
367
369
  - lib/metric_fu.rb
370
+ - lib/metric_fu/cli/client.rb
371
+ - lib/metric_fu/cli/helper.rb
372
+ - lib/metric_fu/cli/parser.rb
368
373
  - lib/metric_fu/configuration.rb
369
374
  - lib/metric_fu/data_structures/careful_array.rb
370
375
  - lib/metric_fu/data_structures/line_numbers.rb
@@ -462,6 +467,7 @@ files:
462
467
  - lib/metric_fu/version.rb
463
468
  - lib/metric_fu_requires.rb
464
469
  - metric_fu.gemspec
470
+ - spec/cli/helper_spec.rb
465
471
  - spec/metric_fu/configuration_spec.rb
466
472
  - spec/metric_fu/data_structures/line_numbers_spec.rb
467
473
  - spec/metric_fu/data_structures/location_spec.rb
@@ -501,7 +507,9 @@ files:
501
507
  - spec/resources/saikuro_sfiles/thing.rb_cyclo.html
502
508
  - spec/resources/yml/20090630.yml
503
509
  - spec/resources/yml/metric_missing.yml
510
+ - spec/run_spec.rb
504
511
  - spec/spec_helper.rb
512
+ - spec/support/matcher_create_file.rb
505
513
  - spec/support/suite.rb
506
514
  homepage: http://github.com/metricfu/metric_fu
507
515
  licenses:
@@ -524,11 +532,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
524
532
  version: 1.3.6
525
533
  requirements: []
526
534
  rubyforge_project: metric_fu
527
- rubygems_version: 1.8.25
535
+ rubygems_version: 1.8.24
528
536
  signing_key:
529
537
  specification_version: 3
530
538
  summary: A fistful of code metrics, with awesome templates and graphs
531
539
  test_files:
540
+ - spec/cli/helper_spec.rb
532
541
  - spec/metric_fu/configuration_spec.rb
533
542
  - spec/metric_fu/data_structures/line_numbers_spec.rb
534
543
  - spec/metric_fu/data_structures/location_spec.rb
@@ -568,5 +577,7 @@ test_files:
568
577
  - spec/resources/saikuro_sfiles/thing.rb_cyclo.html
569
578
  - spec/resources/yml/20090630.yml
570
579
  - spec/resources/yml/metric_missing.yml
580
+ - spec/run_spec.rb
571
581
  - spec/spec_helper.rb
582
+ - spec/support/matcher_create_file.rb
572
583
  - spec/support/suite.rb