metric_fu-metrical 0.1.1

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.
@@ -0,0 +1,6 @@
1
+ *.gem
2
+ .bundle
3
+ pkg/*
4
+ .rvmrc
5
+ tmp/
6
+ Gemfile.lock
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # For testing that this file gets loaded
4
+ puts "Metrics config loaded"
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ --format documentation
3
+ --order rand
@@ -0,0 +1,7 @@
1
+ language: ruby
2
+ script: rspec
3
+ rvm:
4
+ - 1.9.2
5
+ - 1.9.3
6
+ - 1.8.7
7
+ - ree
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in metrical.gemspec
4
+ gemspec
@@ -0,0 +1,121 @@
1
+ ## Warning: This gem is not being maintained anymore!
2
+
3
+ I work exclusively with Ruby 1.9, and most tools included don't (fully) support it.
4
+ If you want to take over the project, fork the project, and open an issue stating your intentions.
5
+
6
+ ---
7
+
8
+ # Metrical
9
+
10
+ [![Build Status](https://secure.travis-ci.org/iain/metrical.png)](http://travis-ci.org/iain/metrical)
11
+
12
+ MetricFu is awesome! Metrical strives to make it a little bit easier to get working.
13
+
14
+ ## Features
15
+
16
+ ### Cleverer defaults
17
+
18
+ Normally, RCov would work on a black-listing basis. This means that your coverage reports would
19
+ occasionally be flooded with code outside your project. No longer, because the default is now to
20
+ exclude everything and only include your `lib` and `app` directories. It also fixes some issues with
21
+ loading RSpec.
22
+
23
+ ## Usage
24
+
25
+ You're advised to install it with Bundler, because of dependency issues. Add this to your `Gemfile`:
26
+
27
+ gem 'metrical', :require => false
28
+
29
+ Then run:
30
+
31
+ bundle install
32
+
33
+ And run it:
34
+
35
+ bundle exec metrical
36
+
37
+ ## Configuration
38
+
39
+ You can configure MetricFu in a `.metrics` file in the root of your project.
40
+
41
+ MetricFu::Configuration.run do |config|
42
+ config.metrics -= [ :rcov ]
43
+ end
44
+
45
+ For more information on configuring your metrics, please visit the
46
+ [MetricFu homepage](http://metric-fu.rubyforge.org/).
47
+
48
+ You can also turn off metrics when running, for instance:
49
+
50
+ bundle exec metrical --no-rcov
51
+
52
+ The metrics you can turn on and off depend on the type of project you are in.
53
+ For instance, Rails projects also have `rails_best_practices` and `stats` as
54
+ options.
55
+
56
+ Also, Metrical tries to be smart about your Ruby version. Some metrics are not
57
+ available on Ruby 1.9 and are disabled automatically.
58
+
59
+ To see which metrics are available, run:
60
+
61
+ bundle exec metrical --help
62
+
63
+ And that's all there is too it. If you have any suggestions, ideas or bug fixes,
64
+ please drop me a line, or make a github issue.
65
+
66
+ ## Known issues
67
+
68
+ ### General lack of support of Ruby 1.9
69
+
70
+ Most tools don't handle Ruby 1.9 new syntax properly. It doesn't look like this is going to change any time soon.
71
+
72
+ ### RCov and Ruby 1.9
73
+
74
+ RCov doesn't work at all with Ruby 1.9. You should use something like
75
+ [SimpleCov](https://github.com/colszowka/simplecov). Unfortunately, it hasn't been included into
76
+ MetricFu yet. Until then, Metrical automatically disables RCov under Ruby 1.9.
77
+
78
+ ### New syntax in Ruby 1.9
79
+
80
+ Most metrics can't cope with the new syntax in Ruby 1.9. There is nothing I can do about that, or
81
+ the creator of these metrics, because the root lie in the code parser they use. Either don't use the
82
+ new syntax or exclude these metrics in your `.metrics` file.
83
+
84
+ ### Roodi vs. Psych
85
+
86
+ If you're running Ruby 1.9 with Psych as your default YAML parser (possible in 1.9.2, and the
87
+ default in 1.9.3), you might get an error message. [Read this issue](https://github.com/iain/metrical/issues/15).
88
+
89
+ ### Gem dependency issues
90
+
91
+ Metrical depends on a lot of other gems. This means that sometimes, when a new version of a gem is released,
92
+ Rubygems will load the wrong version of the gem, that might be incompatible.
93
+
94
+ If you get a message like `can't activate X, already activated Y`, or something similar, use Bundler.
95
+
96
+
97
+ ## Development
98
+
99
+ Install dependencies:
100
+
101
+ gem install bundler && bundle install
102
+
103
+ Run the specs:
104
+
105
+ rspec
106
+
107
+
108
+ ## Changelog
109
+
110
+ Version 0.1.0:
111
+
112
+ * Finally added tests and added metrical to Travis
113
+ * Add option `--no-open` to stop it from opening in the browser
114
+ * Automatically turn off RCov in Ruby 1.9.x
115
+ * Depend on RCov 0.9, so installation will work under Ruby 1.9
116
+ * Remove other dependencies, it looks like MetricFu has that covered now.
117
+ * Automatically turn off Saikuro on Ruby 1.9.x
118
+ * Add switches for every metric (run `metrical --help` to see them all)
119
+
120
+ ---
121
+ Copyright 2010-2011, [Iain Hecker](http://iain.nl) - Released under the MIT License.
@@ -0,0 +1,8 @@
1
+ require "bundler/gem_tasks"
2
+
3
+
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:test)
7
+
8
+ task :default => :test
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "metrical"
4
+ Metrical.run(ARGV.dup)
@@ -0,0 +1,78 @@
1
+ require "metrical/version"
2
+ require "metrical/options"
3
+
4
+ require 'rubygems'
5
+ require 'json'
6
+ require 'metric_fu'
7
+
8
+ # Required for RCOV
9
+ require 'active_support'
10
+ require 'active_support/core_ext'
11
+
12
+ module Metrical
13
+ extend self
14
+
15
+ def run(argv)
16
+ options = Options.parse(argv)
17
+ load_defaults
18
+ set_new_rcov_defaults
19
+ load_user_configuration
20
+ disable_metrics(options)
21
+ run_metric_fu
22
+ open_in_browser if options[:open]
23
+ end
24
+
25
+ private
26
+
27
+ def disable_metrics(options)
28
+ options[:metrics].each do |metric, chosen|
29
+ unless chosen
30
+ MetricFu.configuration.metrics -= [ metric ]
31
+ MetricFu.configuration.graphs -= [ metric ]
32
+ end
33
+ end
34
+ end
35
+
36
+ def load_defaults
37
+ MetricFu::Configuration.run {}
38
+ end
39
+
40
+ def set_new_rcov_defaults
41
+ test_files = Dir['{spec,test}/**/*_{spec,test}.rb']
42
+ MetricFu::Configuration.run do |config|
43
+ config.rcov[:test_files] = test_files
44
+ config.rcov[:rcov_opts] = [
45
+ "--sort coverage",
46
+ "--no-html",
47
+ "--text-coverage",
48
+ "--no-color",
49
+ "--profile",
50
+ "--exclude-only '.*'",
51
+ '--include-file "\Aapp,\Alib"'
52
+ ]
53
+ config.rcov[:rcov_opts] << "-Ispec" if File.exist?("spec")
54
+ end
55
+ end
56
+
57
+ def load_user_configuration
58
+ file = File.join(Dir.pwd, '.metrics')
59
+ load file if File.exist?(file)
60
+ end
61
+
62
+ def run_metric_fu
63
+ MetricFu.metrics.each {|metric| MetricFu.report.add(metric) }
64
+ MetricFu.report.save_output(MetricFu.report.to_yaml, MetricFu.base_directory, "report.yml")
65
+ MetricFu.report.save_output(MetricFu.report.to_yaml, MetricFu.data_directory, "#{Time.now.strftime("%Y%m%d")}.yml")
66
+ MetricFu.report.save_templatized_report
67
+
68
+ MetricFu.graphs.each {|graph| MetricFu.graph.add(graph, MetricFu.graph_engine) }
69
+ MetricFu.graph.generate
70
+ end
71
+
72
+ def open_in_browser
73
+ if MetricFu.report.open_in_browser?
74
+ MetricFu.report.show_in_browser(MetricFu.output_directory)
75
+ end
76
+ end
77
+
78
+ end
@@ -0,0 +1,61 @@
1
+ require 'optparse'
2
+
3
+ module Metrical
4
+ module Options
5
+
6
+ def self.defaults
7
+
8
+ defaults = {
9
+ :open => true,
10
+ :metrics => Hash.new(true)
11
+ }
12
+ defaults[:metrics][:saikuro] = version(ruby) < version("1.9")
13
+ defaults[:metrics][:rcov] = version(ruby) < version("1.9")
14
+ defaults
15
+ end
16
+
17
+ def self.version(version)
18
+ Gem::Version.new(version)
19
+ end
20
+
21
+ def self.ruby
22
+ RUBY_VERSION.dup
23
+ end
24
+
25
+ def self.metrics
26
+ MetricFu.configuration.metrics.sort_by(&:to_s)
27
+ end
28
+
29
+ def self.parse(argv)
30
+ options = defaults.dup
31
+
32
+ opts = OptionParser.new do |opts|
33
+
34
+ opts.version = Metrical::VERSION
35
+
36
+ metrics.each do |metric|
37
+
38
+ opts.on "--[no-]#{metric}", "Enables or disables #{metric.to_s.titleize} (default: #{options[:metrics][metric]})" do |option|
39
+ options[:metrics][metric] = option
40
+ end
41
+
42
+ end
43
+
44
+ opts.on "--[no-]open", "Open report in browser" do |open|
45
+ options[:open] = open
46
+ end
47
+
48
+ end
49
+
50
+ begin
51
+ opts.parse!(argv)
52
+ rescue OptionParser::InvalidOption => error
53
+ puts error.message
54
+ puts opts
55
+ exit 1
56
+ end
57
+ options
58
+ end
59
+
60
+ end
61
+ end
@@ -0,0 +1,3 @@
1
+ module Metrical
2
+ VERSION = "0.1.1"
3
+ end
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "metrical/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "metric_fu-metrical"
7
+ s.version = Metrical::VERSION
8
+ s.authors = ["iain"]
9
+ s.email = ["iain@iain.nl"]
10
+ s.homepage = "https://github.com/iain/metrical"
11
+ s.summary = %q{Run metric_fu without making it a project dependency}
12
+ s.description = %q{MetricFu is awesome! The only problem is that it's kinda obtrusive. Metrical provides a executable so you can run metric fu on any project without making changes to the project.}
13
+
14
+ s.rubyforge_project = "metrical"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ s.add_runtime_dependency "metric_fu", "> 2.1.3.6"
22
+ s.add_runtime_dependency "rcov", "~> 0.9"
23
+ s.add_development_dependency "rspec", "~> 2.8"
24
+ end
@@ -0,0 +1,181 @@
1
+ require 'spec_helper'
2
+
3
+ describe Metrical::Options do
4
+
5
+ describe ".defaults" do
6
+
7
+ let(:defaults) { Metrical::Options.defaults }
8
+
9
+ context "on every Ruby version" do
10
+
11
+ it "opens the report in a browser" do
12
+ defaults[:open].should be_true
13
+ end
14
+
15
+ it "enables Flog" do
16
+ defaults[:metrics][:flog].should be_true
17
+ end
18
+
19
+ it "enables Flay" do
20
+ defaults[:metrics][:flay].should be_true
21
+ end
22
+
23
+ it "enables Reek" do
24
+ defaults[:metrics][:reek].should be_true
25
+ end
26
+
27
+ it "enables Hotspots" do
28
+ defaults[:metrics][:hotspots].should be_true
29
+ end
30
+
31
+ it "enables Rails Best Practices" do
32
+ defaults[:metrics][:rails_best_practices].should be_true
33
+ end
34
+
35
+ it "enables Churn" do
36
+ defaults[:metrics][:churn].should be_true
37
+ end
38
+
39
+ end
40
+
41
+ context "on Ruby 1.8.6" do
42
+
43
+ before { subject.stub(:ruby).and_return("1.8.6") }
44
+
45
+ it "enables Saikuro" do
46
+ defaults[:metrics][:saikuro].should be_true
47
+ end
48
+
49
+ it "enables RCov" do
50
+ defaults[:metrics][:rcov].should be_true
51
+ end
52
+
53
+ end
54
+
55
+ context "on Ruby 1.8.7" do
56
+
57
+ before { subject.stub(:ruby).and_return("1.8.7") }
58
+
59
+ it "enables Saikuro" do
60
+ defaults[:metrics][:saikuro].should be_true
61
+ end
62
+
63
+ it "enables RCov" do
64
+ defaults[:metrics][:rcov].should be_true
65
+ end
66
+
67
+ end
68
+
69
+ context "on Ruby 1.9.2" do
70
+
71
+ before { subject.stub(:ruby).and_return("1.9.2") }
72
+
73
+ it "enables Saikuro" do
74
+ defaults[:metrics][:saikuro].should be_false
75
+ end
76
+
77
+ it "disables RCov" do
78
+ defaults[:metrics][:rcov].should be_false
79
+ end
80
+
81
+ end
82
+
83
+ context "on Ruby 1.9.3" do
84
+
85
+ before { subject.stub(:ruby).and_return("1.9.3") }
86
+
87
+ it "disables Saikuro" do
88
+ defaults[:metrics][:saikuro].should be_false
89
+ end
90
+
91
+ it "disables RCov" do
92
+ defaults[:metrics][:rcov].should be_false
93
+ end
94
+
95
+ end
96
+
97
+ end
98
+
99
+ describe ".parse" do
100
+
101
+ it "turns open in browser off" do
102
+ subject.parse(["--no-open"])[:open].should be_false
103
+ end
104
+
105
+ it "turns open in browser on" do
106
+ subject.parse(["--open"])[:open].should be_true
107
+ end
108
+
109
+ # MetricFu doesn't include Saikuro on 1.9.2 (it is broken on 1.9 anyway)
110
+ # https://github.com/jscruggs/metric_fu/blob/master/lib/base/configuration.rb#L12
111
+ unless RUBY_VERSION == "1.9.2"
112
+
113
+ it "turns saikuro off" do
114
+ subject.parse(["--no-saikuro"])[:metrics][:saikuro].should be_false
115
+ end
116
+
117
+ it "turns saikuro on" do
118
+ subject.parse(["--saikuro"])[:metrics][:saikuro].should be_true
119
+ end
120
+
121
+ end
122
+
123
+ it "turns churn off" do
124
+ subject.parse(["--no-churn"])[:metrics][:churn].should be_false
125
+ end
126
+
127
+ it "turns churn on" do
128
+ subject.parse(["--churn"])[:metrics][:churn].should be_true
129
+ end
130
+
131
+ it "turns flay off" do
132
+ subject.parse(["--no-flay"])[:metrics][:flay].should be_false
133
+ end
134
+
135
+ it "turns flay on" do
136
+ subject.parse(["--flay"])[:metrics][:flay].should be_true
137
+ end
138
+
139
+ it "turns flog off" do
140
+ subject.parse(["--no-flog"])[:metrics][:flog].should be_false
141
+ end
142
+
143
+ it "turns flog on" do
144
+ subject.parse(["--flog"])[:metrics][:flog].should be_true
145
+ end
146
+
147
+ it "turns hotspots off" do
148
+ subject.parse(["--no-hotspots"])[:metrics][:hotspots].should be_false
149
+ end
150
+
151
+ it "turns hotspots on" do
152
+ subject.parse(["--hotspots"])[:metrics][:hotspots].should be_true
153
+ end
154
+
155
+ it "turns rcov off" do
156
+ subject.parse(["--no-rcov"])[:metrics][:rcov].should be_false
157
+ end
158
+
159
+ it "turns rcov on" do
160
+ subject.parse(["--rcov"])[:metrics][:rcov].should be_true
161
+ end
162
+
163
+ it "turns reek off" do
164
+ subject.parse(["--no-reek"])[:metrics][:reek].should be_false
165
+ end
166
+
167
+ it "turns reek on" do
168
+ subject.parse(["--reek"])[:metrics][:reek].should be_true
169
+ end
170
+
171
+ it "turns roodi off" do
172
+ subject.parse(["--no-roodi"])[:metrics][:roodi].should be_false
173
+ end
174
+
175
+ it "turns roodi on" do
176
+ subject.parse(["--roodi"])[:metrics][:roodi].should be_true
177
+ end
178
+
179
+ end
180
+
181
+ end
@@ -0,0 +1,46 @@
1
+ require 'spec_helper'
2
+
3
+ describe Metrical, "running" do
4
+
5
+ before do
6
+ FileUtils.rm_rf("tmp/metric_fu")
7
+ end
8
+
9
+ it "has a clean start" do
10
+ File.should_not exist("tmp/metric_fu")
11
+ end
12
+
13
+ it "loads the .metrics file" do
14
+ out = metrical
15
+ out.should include "Metrics config loaded"
16
+ end
17
+
18
+ it "creates a report yaml file" do
19
+ expect { metrical }.to create_file("tmp/metric_fu/report.yml")
20
+ end
21
+
22
+ it "creates a report html file" do
23
+ expect { metrical }.to create_file("tmp/metric_fu/output/index.html")
24
+ end
25
+
26
+ it "displays help" do
27
+ out = metrical("bundle exec metrical --help")
28
+ out.should include "Usage: metrical [options]"
29
+ end
30
+
31
+ it "displays version" do
32
+ out = metrical("bundle exec metrical --version")
33
+ out.should == "metrical #{Metrical::VERSION}"
34
+ end
35
+
36
+ it "errors on unknown flags" do
37
+ expect { metrical "--asdasdasda" }.to raise_error
38
+ end
39
+
40
+ def metrical(command = "--no-open")
41
+ results = `metrical #{command} 2>&1`
42
+ $?.to_i.should eq(0), "The command 'metrical #{command}' failed!\n\n#{results}"
43
+ results.strip
44
+ end
45
+
46
+ end
@@ -0,0 +1,34 @@
1
+ require 'bundler/setup'
2
+ require 'metrical'
3
+ require 'rspec'
4
+
5
+ RSpec::Matchers.define :create_file do |expected|
6
+
7
+ match do |block|
8
+ @before = File.exist?(expected)
9
+ block.call
10
+ @after = File.exist?(expected)
11
+ !@before && @after
12
+ end
13
+
14
+ failure_message_for_should do |block|
15
+ existed_before_message expected do
16
+ "The file #{expected.inspect} was not created"
17
+ end
18
+ end
19
+
20
+ failure_message_for_should_not do |block|
21
+ existed_before_message expected do
22
+ "The file #{expected.inspect} was created"
23
+ end
24
+ end
25
+
26
+ def existed_before_message(expected)
27
+ if @before
28
+ "The file #{expected.inspect} existed before, so this test doesn't work"
29
+ else
30
+ yield
31
+ end
32
+ end
33
+
34
+ end
metadata ADDED
@@ -0,0 +1,128 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: metric_fu-metrical
3
+ version: !ruby/object:Gem::Version
4
+ hash: 25
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 1
10
+ version: 0.1.1
11
+ platform: ruby
12
+ authors:
13
+ - iain
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2013-01-08 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: metric_fu
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">"
27
+ - !ruby/object:Gem::Version
28
+ hash: 103
29
+ segments:
30
+ - 2
31
+ - 1
32
+ - 3
33
+ - 6
34
+ version: 2.1.3.6
35
+ type: :runtime
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: rcov
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ hash: 25
46
+ segments:
47
+ - 0
48
+ - 9
49
+ version: "0.9"
50
+ type: :runtime
51
+ version_requirements: *id002
52
+ - !ruby/object:Gem::Dependency
53
+ name: rspec
54
+ prerelease: false
55
+ requirement: &id003 !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ~>
59
+ - !ruby/object:Gem::Version
60
+ hash: 19
61
+ segments:
62
+ - 2
63
+ - 8
64
+ version: "2.8"
65
+ type: :development
66
+ version_requirements: *id003
67
+ description: MetricFu is awesome! The only problem is that it's kinda obtrusive. Metrical provides a executable so you can run metric fu on any project without making changes to the project.
68
+ email:
69
+ - iain@iain.nl
70
+ executables:
71
+ - metric_fu-metrical
72
+ extensions: []
73
+
74
+ extra_rdoc_files: []
75
+
76
+ files:
77
+ - .gitignore
78
+ - .metrics
79
+ - .rspec
80
+ - .travis.yml
81
+ - Gemfile
82
+ - README.md
83
+ - Rakefile
84
+ - bin/metric_fu-metrical
85
+ - lib/metrical.rb
86
+ - lib/metrical/options.rb
87
+ - lib/metrical/version.rb
88
+ - metrical.gemspec
89
+ - spec/options_spec.rb
90
+ - spec/running_spec.rb
91
+ - spec/spec_helper.rb
92
+ homepage: https://github.com/iain/metrical
93
+ licenses: []
94
+
95
+ post_install_message:
96
+ rdoc_options: []
97
+
98
+ require_paths:
99
+ - lib
100
+ required_ruby_version: !ruby/object:Gem::Requirement
101
+ none: false
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ hash: 3
106
+ segments:
107
+ - 0
108
+ version: "0"
109
+ required_rubygems_version: !ruby/object:Gem::Requirement
110
+ none: false
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ hash: 3
115
+ segments:
116
+ - 0
117
+ version: "0"
118
+ requirements: []
119
+
120
+ rubyforge_project: metrical
121
+ rubygems_version: 1.8.24
122
+ signing_key:
123
+ specification_version: 3
124
+ summary: Run metric_fu without making it a project dependency
125
+ test_files:
126
+ - spec/options_spec.rb
127
+ - spec/running_spec.rb
128
+ - spec/spec_helper.rb