metrical 0.0.7 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.metrics CHANGED
@@ -1,4 +1,4 @@
1
1
  #!/usr/bin/env ruby
2
- MetricFu::Configuration.run do |config|
3
- config.metrics -= [ :rcov ]
4
- end
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
@@ -1,45 +1,57 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- metrical (0.0.7)
5
- main (~> 4.6.0)
4
+ metrical (0.1.0.alpha)
6
5
  metric_fu (~> 2.1.1)
7
- rake
6
+ rcov (~> 0.9)
8
7
 
9
8
  GEM
10
9
  remote: http://rubygems.org/
11
10
  specs:
12
11
  Saikuro (1.1.0)
13
- activesupport (3.1.0)
12
+ activesupport (3.2.1)
13
+ i18n (~> 0.6)
14
14
  multi_json (~> 1.0)
15
15
  arrayfields (4.7.4)
16
16
  chronic (0.3.0)
17
- churn (0.0.13)
17
+ churn (0.0.15)
18
+ arrayfields (= 4.7.4)
19
+ chronic (>= 0.2.3)
18
20
  chronic (>= 0.2.3)
21
+ fattr (= 2.2.0)
22
+ hirb (= 0.5.0)
19
23
  hirb
24
+ jeweler (= 1.6.4)
25
+ json (= 1.6.1)
20
26
  json_pure
21
27
  main
22
- ruby_parser (~> 2.0.4)
28
+ main (>= 4.6.0)
29
+ map (= 4.3.0)
30
+ ruby_parser (= 2.3.1)
31
+ ruby_parser (~> 2.3)
32
+ sexp_processor (= 3.0.7)
23
33
  sexp_processor (~> 3.0.3)
24
34
  colored (1.2)
35
+ diff-lcs (1.1.3)
25
36
  erubis (2.7.0)
26
37
  fattr (2.2.0)
27
38
  flay (1.4.3)
28
39
  ruby_parser (~> 2.0)
29
40
  sexp_processor (~> 3.0)
30
- flog (2.5.2)
41
+ flog (2.5.3)
31
42
  ruby_parser (~> 2.0)
32
43
  sexp_processor (~> 3.0)
33
- haml (3.1.3)
44
+ git (1.2.5)
34
45
  hirb (0.5.0)
35
46
  i18n (0.6.0)
36
- json_pure (1.5.4)
37
- spruz (~> 0.2.8)
38
- main (4.6.0)
39
- arrayfields (>= 4.7.4)
40
- fattr (>= 2.1.0)
41
- map (>= 2.0.0)
42
- map (4.5.0)
47
+ jeweler (1.6.4)
48
+ bundler (~> 1.0)
49
+ git (>= 1.2.5)
50
+ rake
51
+ json (1.6.1)
52
+ json_pure (1.6.5)
53
+ main (4.7.1)
54
+ map (4.3.0)
43
55
  metric_fu (2.1.1)
44
56
  Saikuro (>= 1.1.0)
45
57
  activesupport (>= 2.0.0)
@@ -52,31 +64,37 @@ GEM
52
64
  reek (>= 1.2.6)
53
65
  roodi (>= 2.1.0)
54
66
  syntax
55
- multi_json (1.0.3)
56
- rails_best_practices (0.10.1)
67
+ multi_json (1.0.4)
68
+ progressbar (0.10.0)
69
+ rails_best_practices (1.7.2)
57
70
  activesupport
58
71
  colored
59
72
  erubis
60
- haml
61
73
  i18n
62
- ruby-progressbar
63
- ruby_parser
64
- rake (0.9.2)
65
- rcov (0.9.10)
74
+ progressbar
75
+ sexp_processor
76
+ rake (0.9.2.2)
77
+ rcov (0.9.11)
66
78
  reek (1.2.8)
67
79
  ruby2ruby (~> 1.2)
68
80
  ruby_parser (~> 2.0)
69
81
  sexp_processor (~> 3.0)
70
82
  roodi (2.1.0)
71
83
  ruby_parser
72
- ruby-progressbar (0.0.10)
73
- ruby2ruby (1.3.0)
84
+ rspec (2.8.0)
85
+ rspec-core (~> 2.8.0)
86
+ rspec-expectations (~> 2.8.0)
87
+ rspec-mocks (~> 2.8.0)
88
+ rspec-core (2.8.0)
89
+ rspec-expectations (2.8.0)
90
+ diff-lcs (~> 1.1.2)
91
+ rspec-mocks (2.8.0)
92
+ ruby2ruby (1.3.1)
74
93
  ruby_parser (~> 2.0)
75
94
  sexp_processor (~> 3.0)
76
- ruby_parser (2.0.6)
95
+ ruby_parser (2.3.1)
77
96
  sexp_processor (~> 3.0)
78
- sexp_processor (3.0.6)
79
- spruz (0.2.13)
97
+ sexp_processor (3.0.7)
80
98
  syntax (1.0.0)
81
99
 
82
100
  PLATFORMS
@@ -84,3 +102,4 @@ PLATFORMS
84
102
 
85
103
  DEPENDENCIES
86
104
  metrical!
105
+ rspec (~> 2.8)
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # Metrical
2
2
 
3
+ [![Build Status](https://secure.travis-ci.org/iain/metrical.png)](http://travis-ci.org/iain/metrical)
4
+
3
5
  MetricFu is awesome! Metrical strives to make it a little bit easier to get working.
4
6
 
5
7
  ## Features
@@ -30,6 +32,10 @@ Run:
30
32
 
31
33
  metrical
32
34
 
35
+ To get help:
36
+
37
+ metrical --help
38
+
33
39
  ## Configuration
34
40
 
35
41
  You can configure MetricFu in a `.metrics` file in the root of your project.
@@ -50,7 +56,7 @@ please drop me a line, or make a github issue.
50
56
 
51
57
  RCov doesn't work with Ruby 1.9. You should use something like
52
58
  [SimpleCov](https://github.com/colszowka/simplecov). Unfortunately, it hasn't been included into
53
- MetricFu yet. Until then, make sure to remove RCov from MetricFu, as the example above shows.
59
+ MetricFu yet. Until then, Metrical automatically disables RCov under Ruby 1.9.
54
60
 
55
61
  ### New syntax in Ruby 1.9
56
62
 
@@ -75,5 +81,29 @@ If you get a message like `can't activate X, already activated Y`, or something
75
81
  open an issue. Please include the entire error message and the output of `gem list` and the version
76
82
  of Ruby you are using.
77
83
 
84
+
85
+ ## Development
86
+
87
+ Install dependencies:
88
+
89
+ gem install bundler && bundle install
90
+
91
+ Run the specs:
92
+
93
+ rspec
94
+
95
+
96
+ ## Changelog
97
+
98
+ Version 0.1.0:
99
+
100
+ * Finally added tests and added metrical to Travis
101
+ * Add option `--no-open` to stop it from opening in the browser
102
+ * Automatically turn off RCov in Ruby 1.9.x
103
+ * Depend on RCov 0.9, so installation will work under Ruby 1.9
104
+ * Remove other dependencies, it looks like MetricFu has that covered now.
105
+ * Automatically turn off Saikuro on Ruby 1.9.x
106
+ * Add switches for every metric (run `metrical --help` to see them all)
107
+
78
108
  ---
79
109
  Copyright 2010-2011, [Iain Hecker](http://iain.nl) - Released under the MIT License.
data/Rakefile CHANGED
@@ -1 +1,8 @@
1
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
@@ -1,4 +1,4 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require "metrical"
4
- Metrical.run(*ARGV)
4
+ Metrical.run(ARGV.dup)
@@ -1,4 +1,5 @@
1
1
  require "metrical/version"
2
+ require "metrical/options"
2
3
 
3
4
  require 'rubygems'
4
5
  require 'json'
@@ -11,16 +12,27 @@ require 'active_support/core_ext'
11
12
  module Metrical
12
13
  extend self
13
14
 
14
- def run(*)
15
+ def run(argv)
16
+ options = Options.parse(argv)
15
17
  load_defaults
16
18
  set_new_rcov_defaults
17
19
  load_user_configuration
20
+ disable_metrics(options)
18
21
  run_metric_fu
19
- open_in_browser
22
+ open_in_browser if options[:open]
20
23
  end
21
24
 
22
25
  private
23
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
+
24
36
  def load_defaults
25
37
  MetricFu::Configuration.run {}
26
38
  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
@@ -1,3 +1,3 @@
1
1
  module Metrical
2
- VERSION = "0.0.7"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -19,6 +19,6 @@ Gem::Specification.new do |s|
19
19
  s.require_paths = ["lib"]
20
20
 
21
21
  s.add_runtime_dependency "metric_fu", "~> 2.1.1"
22
- s.add_runtime_dependency "main", "~> 4.6.0"
23
- s.add_runtime_dependency "rake"
22
+ s.add_runtime_dependency "rcov", "~> 0.9"
23
+ s.add_development_dependency "rspec", "~> 2.8"
24
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 CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: metrical
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-09-11 00:00:00.000000000Z
12
+ date: 2012-02-13 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: metric_fu
16
- requirement: &2173451920 !ruby/object:Gem::Requirement
16
+ requirement: &70219138027460 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,29 +21,29 @@ dependencies:
21
21
  version: 2.1.1
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *2173451920
24
+ version_requirements: *70219138027460
25
25
  - !ruby/object:Gem::Dependency
26
- name: main
27
- requirement: &2173451400 !ruby/object:Gem::Requirement
26
+ name: rcov
27
+ requirement: &70219138026940 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
31
31
  - !ruby/object:Gem::Version
32
- version: 4.6.0
32
+ version: '0.9'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *2173451400
35
+ version_requirements: *70219138026940
36
36
  - !ruby/object:Gem::Dependency
37
- name: rake
38
- requirement: &2173450960 !ruby/object:Gem::Requirement
37
+ name: rspec
38
+ requirement: &70219138026440 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
- - - ! '>='
41
+ - - ~>
42
42
  - !ruby/object:Gem::Version
43
- version: '0'
44
- type: :runtime
43
+ version: '2.8'
44
+ type: :development
45
45
  prerelease: false
46
- version_requirements: *2173450960
46
+ version_requirements: *70219138026440
47
47
  description: MetricFu is awesome! The only problem is that it's kinda obtrusive. Metrical
48
48
  provides a executable so you can run metric fu on any project without making changes
49
49
  to the project.
@@ -56,14 +56,20 @@ extra_rdoc_files: []
56
56
  files:
57
57
  - .gitignore
58
58
  - .metrics
59
+ - .rspec
60
+ - .travis.yml
59
61
  - Gemfile
60
62
  - Gemfile.lock
61
63
  - README.md
62
64
  - Rakefile
63
65
  - bin/metrical
64
66
  - lib/metrical.rb
67
+ - lib/metrical/options.rb
65
68
  - lib/metrical/version.rb
66
69
  - metrical.gemspec
70
+ - spec/options_spec.rb
71
+ - spec/running_spec.rb
72
+ - spec/spec_helper.rb
67
73
  homepage: https://github.com/iain/metrical
68
74
  licenses: []
69
75
  post_install_message:
@@ -84,8 +90,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
84
90
  version: '0'
85
91
  requirements: []
86
92
  rubyforge_project: metrical
87
- rubygems_version: 1.8.6
93
+ rubygems_version: 1.8.15
88
94
  signing_key:
89
95
  specification_version: 3
90
96
  summary: Run metric_fu without making it a project dependency
91
- test_files: []
97
+ test_files:
98
+ - spec/options_spec.rb
99
+ - spec/running_spec.rb
100
+ - spec/spec_helper.rb