edouard-metric_fu 1.2.0 → 1.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/HISTORY CHANGED
@@ -4,6 +4,7 @@
4
4
  * Add tooltips to graphs
5
5
  * Fix `activesupport` deprecation
6
6
  * Vendor Saikuro as a gem dependency
7
+ * Merge back Rails Best Practice Results from Richard Huang
7
8
 
8
9
  === MetricFu 1.2.0 / 2010-01-09
9
10
 
data/README CHANGED
@@ -1 +1 @@
1
- See http://metric-fu.rubyforge.org/ for documentation, or the HISTORY file for a change log.
1
+ See http://metric-fu.rubyforge.org/ for documentation, or the HISTORY file for a change log.
data/Rakefile CHANGED
@@ -2,7 +2,9 @@ require 'rake'
2
2
  require 'rake/rdoctask'
3
3
  require 'spec/rake/spectask'
4
4
  require 'lib/metric_fu'
5
-
5
+ require 'mg'
6
+ MG.new("metric_fu.gemspec")
7
+
6
8
  desc "Run all specs in spec directory"
7
9
  Spec::Rake::SpecTask.new(:spec) do |t|
8
10
  t.spec_files = FileList['spec/**/*_spec.rb']
@@ -10,9 +12,9 @@ Spec::Rake::SpecTask.new(:spec) do |t|
10
12
  t.rcov_opts = ['--exclude', 'spec,config,Library,usr/lib/ruby']
11
13
  t.rcov_dir = File.join(File.dirname(__FILE__), "tmp")
12
14
  end
13
-
15
+
14
16
  MetricFu::Configuration.run do |config|
15
17
  config.template_class = AwesomeTemplate
16
18
  end
17
-
19
+
18
20
  task :default => [:"metrics:all"]
@@ -8,7 +8,7 @@ module MetricFu
8
8
  AVAILABLE_METRICS = [:churn, :flog, :flay, :reek,
9
9
  :roodi, :saikuro, :rcov]
10
10
 
11
- AVAILABLE_GRAPHS = [:flog, :flay, :reek, :roodi, :rcov]
11
+ AVAILABLE_GRAPHS = [:flog, :flay, :reek, :roodi, :rcov, :rails_best_practices]
12
12
  AVAILABLE_GRAPH_ENGINES = [:gchart, :bluff]
13
13
 
14
14
  # The @@configuration class variable holds a global type configuration
@@ -109,7 +109,8 @@ module MetricFu
109
109
  set_metrics
110
110
  set_graphs
111
111
  set_code_dirs
112
- @flay = { :dirs_to_flay => @code_dirs }
112
+ @flay = { :dirs_to_flay => @code_dirs,
113
+ :minimum_score => 100 }
113
114
  @flog = { :dirs_to_flog => @code_dirs }
114
115
  @reek = { :dirs_to_reek => @code_dirs }
115
116
  @roodi = { :dirs_to_roodi => @code_dirs }
@@ -122,7 +123,8 @@ module MetricFu
122
123
  :formater => "text"}
123
124
  @churn = {}
124
125
  @stats = {}
125
- @rcov = { :test_files => ['test/**/*_test.rb',
126
+ @rcov = { :environment => 'test',
127
+ :test_files => ['test/**/*_test.rb',
126
128
  'spec/**/*_spec.rb'],
127
129
  :rcov_opts => ["--sort coverage",
128
130
  "--no-html",
@@ -131,6 +133,7 @@ module MetricFu
131
133
  "--profile",
132
134
  "--rails",
133
135
  "--exclude /gems/,/Library/,/usr/,spec"]}
136
+ @rails_best_practices = {}
134
137
 
135
138
  @file_globs_to_ignore = []
136
139
 
@@ -149,7 +152,7 @@ module MetricFu
149
152
  # running within rails.
150
153
  def set_metrics
151
154
  if rails?
152
- @metrics = MetricFu::AVAILABLE_METRICS + [:stats]
155
+ @metrics = MetricFu::AVAILABLE_METRICS + [:stats, :rails_best_practices]
153
156
  else
154
157
  @metrics = MetricFu::AVAILABLE_METRICS
155
158
  end
@@ -13,7 +13,7 @@ module MetricFu
13
13
  end
14
14
 
15
15
  def add(graph_type, graph_engine)
16
- grapher_name = graph_type.to_s.capitalize + graph_engine.to_s.capitalize + "Grapher"
16
+ grapher_name = graph_type.to_s.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase } + graph_engine.to_s.capitalize + "Grapher"
17
17
  self.clazz.push MetricFu.const_get(grapher_name).new
18
18
  end
19
19
 
@@ -50,7 +50,7 @@ module MetricFu
50
50
  # @param report_type Hash
51
51
  # The hash to add to the aggregate report_hash
52
52
  def add(report_type)
53
- clazz = MetricFu.const_get(report_type.to_s.capitalize)
53
+ clazz = MetricFu.const_get(report_type.to_s.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase })
54
54
  report_hash.merge!(clazz.generate_report)
55
55
  end
56
56
 
@@ -1,90 +1,34 @@
1
- require 'chronic'
2
1
  module MetricFu
3
-
2
+
4
3
  class Churn < Generator
5
4
 
6
-
7
5
  def initialize(options={})
8
6
  super
9
- if self.class.git?
10
- @source_control = Git.new(MetricFu.churn[:start_date])
11
- elsif File.exist?(".svn")
12
- @source_control = Svn.new(MetricFu.churn[:start_date])
13
- else
14
- raise "Churning requires a subversion or git repo"
15
- end
16
- @minimum_churn_count = MetricFu.churn[:minimum_churn_count] || 5
17
7
  end
18
8
 
19
- def self.git?
20
- system("git branch")
9
+ def self.verify_dependencies!
10
+ result = `churn --help`
11
+ raise 'sudo gem install churn # if you want the churn tasks' unless result.match(/churn/)
21
12
  end
13
+
22
14
 
23
15
  def emit
24
- @changes = parse_log_for_changes.reject {|file, change_count| change_count < @minimum_churn_count}
16
+ @output = `churn --yaml`
17
+ yaml_start = @output.index("---")
18
+ @output = @output[yaml_start...@output.length] if yaml_start
25
19
  end
26
20
 
27
21
  def analyze
28
- @changes = @changes.to_a.sort {|x,y| y[1] <=> x[1]}
29
- @changes = @changes.map {|change| {:file_path => change[0], :times_changed => change[1] }}
30
- end
31
-
32
- def to_h
33
- {:churn => {:changes => @changes}}
34
- end
35
-
36
- private
37
-
38
- def parse_log_for_changes
39
- changes = {}
40
-
41
- logs = @source_control.get_logs
42
- logs.each do |line|
43
- changes[line] ? changes[line] += 1 : changes[line] = 1
44
- end
45
- changes
46
- end
47
-
48
-
49
- class SourceControl
50
- def initialize(start_date=nil)
51
- @start_date = start_date
52
- end
53
- end
54
-
55
- class Git < SourceControl
56
- def get_logs
57
- `git log #{date_range} --name-only --pretty=format:`.split(/\n/).reject{|line| line == ""}
58
- end
59
-
60
- private
61
- def date_range
62
- if @start_date
63
- date = Chronic.parse(@start_date)
64
- "--after=#{date.strftime('%Y-%m-%d')}"
65
- end
22
+ if @output.match(/fatal: Not a git repository/)
23
+ @churn = [:churn => {}]
24
+ else
25
+ @churn = YAML::load(@output)
66
26
  end
67
-
68
27
  end
69
28
 
70
- class Svn < SourceControl
71
- def get_logs
72
- `svn log #{date_range} --verbose`.split(/\n/).map { |line| clean_up_svn_line(line) }.compact
73
- end
74
-
75
- private
76
- def date_range
77
- if @start_date
78
- date = Chronic.parse(@start_date)
79
- "--revision {#{date.strftime('%Y-%m-%d')}}:{#{Time.now.strftime('%Y-%m-%d')}}"
80
- end
81
- end
82
-
83
- def clean_up_svn_line(line)
84
- m = line.match(/\W*[A,M]\W+(\/.*)\b/)
85
- m ? m[1] : nil
86
- end
29
+ def to_h
30
+ {:churn => @churn[:churn]}
87
31
  end
88
-
89
32
  end
33
+
90
34
  end
@@ -10,7 +10,8 @@ module MetricFu
10
10
  def emit
11
11
  files_to_flay = MetricFu.flay[:dirs_to_flay].map{|dir| Dir[File.join(dir, "**/*.rb")] }
12
12
  files = remove_excluded_files(files_to_flay.flatten)
13
- @output = `flay #{files.join(" ")}`
13
+ mimimum_score_parameter = MetricFu.flay[:minimum_score] ? "--mass #{MetricFu.flay[:minimum_score]} " : ""
14
+ @output = `flay #{mimimum_score_parameter}#{files.join(" ")}`
14
15
  end
15
16
 
16
17
  def analyze
@@ -0,0 +1,31 @@
1
+ module MetricFu
2
+ class RailsBestPractices < Generator
3
+
4
+ def self.verify_dependencies!
5
+ `rails_best_practices --help`
6
+ raise 'sudo gem install rails_best_practices # if you want the rails_best_practices tasks' unless $?.success?
7
+ end
8
+
9
+
10
+ def emit
11
+ @output = `rails_best_practices .`
12
+ end
13
+
14
+ def analyze
15
+ @matches = @output.chomp.split("\n").map{|m| m.split(" - ") }
16
+ total = @matches.pop
17
+ 2.times { @matches.pop } # ignore wiki link
18
+ @matches.reject! {|array| array.empty? }
19
+ @matches.map! do |match|
20
+ file, line = match[0].split(':')
21
+ problem = match[1]
22
+ {:file => file, :line => line, :problem => problem}
23
+ end
24
+ @rails_best_practices_results = {:total => total, :problems => @matches}
25
+ end
26
+
27
+ def to_h
28
+ {:rails_best_practices => @rails_best_practices_results}
29
+ end
30
+ end
31
+ end
@@ -36,6 +36,8 @@ module MetricFu
36
36
  test_files = FileList[*MetricFu.rcov[:test_files]].join(' ')
37
37
  rcov_opts = MetricFu.rcov[:rcov_opts].join(' ')
38
38
  output = ">> #{MetricFu::Rcov.metric_directory}/rcov.txt"
39
+ puts "** Running the specs/tests in the [#{MetricFu.rcov[:environment]}] environment"
40
+ puts "RAILS_ENV=#{MetricFu.rcov[:environment]} rcov #{test_files} #{rcov_opts} #{output}"
39
41
  `rcov #{test_files} #{rcov_opts} #{output}`
40
42
  rescue LoadError
41
43
  if RUBY_PLATFORM =~ /java/
@@ -83,4 +83,17 @@ module MetricFu
83
83
  File.open(File.join(MetricFu.output_directory, 'roodi.js'), 'w') {|f| f << content }
84
84
  end
85
85
  end
86
+
87
+ class RailsBestPracticesBluffGrapher < RailsBestPracticesGrapher
88
+ def graph!
89
+ content = <<-EOS
90
+ #{BLUFF_DEFAULT_OPTIONS}
91
+ g.title = 'Rails Best Practices: design problems';
92
+ g.data('rails_best_practices', [#{@rails_best_practices_count.join(',')}]);
93
+ g.labels = #{@labels.to_json};
94
+ g.draw();
95
+ EOS
96
+ File.open(File.join(MetricFu.output_directory, 'rails_best_practices.js'), 'w') {|f| f << content }
97
+ end
98
+ end
86
99
  end
@@ -0,0 +1,22 @@
1
+ module MetricFu
2
+
3
+ class RailsBestPracticesGrapher < Grapher
4
+
5
+ attr_accessor :rails_best_practices_count, :labels
6
+
7
+ def initialize
8
+ super
9
+ @rails_best_practices_count = []
10
+ @labels = {}
11
+ end
12
+
13
+ def get_metrics(metrics, date)
14
+ if metrics[:rails_best_practices]
15
+ @rails_best_practices_count.push(metrics[:rails_best_practices][:problems].size)
16
+ @labels.update( { @labels.size => date })
17
+ end
18
+ end
19
+
20
+ end
21
+
22
+ end
@@ -16,4 +16,43 @@
16
16
  <% count += 1 %>
17
17
  <% end %>
18
18
  </table>
19
+
20
+ <% if @churn[:class_churn] %>
21
+ <p>Classes that change a lot in your project may be bad a sign.</p>
22
+ <table>
23
+ <tr>
24
+ <th>File Path</th>
25
+ <th>Times Changed</th>
26
+ </tr>
27
+ <% count = 0 %>
28
+ <% @churn[:class_churn].each do |change| %>
29
+ <tr>
30
+ <td><%= link_to_filename(change['klass']['file']) %> <%= change['klass']['klass'] %></td>
31
+ <td><%= change['times_changed'] %></td>
32
+ </tr>
33
+ <% count += 1 %>
34
+ <% end %>
35
+ </table>
36
+ <% end %>
37
+
38
+ <% if @churn[:method_churn] %>
39
+ <p>Methods that change a lot in your project may be bad a sign.</p>
40
+ <table>
41
+ <tr>
42
+ <th>File Path</th>
43
+ <th>Times Changed</th>
44
+ </tr>
45
+ <% count = 0 %>
46
+ <% @churn[:method_churn].each do |change| %>
47
+ <tr>
48
+ <td><%= link_to_filename(change['method']['file']) %> <%= change['method']['method'] %></td>
49
+ <td><%= change['times_changed'] %></td>
50
+ </tr>
51
+ <% count += 1 %>
52
+ <% end %>
53
+ </table>
54
+ <% end %>
55
+
56
+
57
+
19
58
  <p>Generated on <%= Time.now.localtime %></p>
@@ -11,6 +11,7 @@
11
11
  <% end %>
12
12
 
13
13
  <h4>Total Score (lower is better): <%= @flay[:total_score] %></h4>
14
+ <h5>Scores less than <%= MetricFu.flay[:minimum_score] %> are not shown or part of the total</h5>
14
15
 
15
16
  <table>
16
17
  <tr>
@@ -23,6 +23,9 @@
23
23
  <% end %>
24
24
  <% if @stats %>
25
25
  <li class='even failure'><a href="stats.html">Stats</a></li>
26
+ <% end %>
27
+ <% if @rails_best_practices %>
28
+ <li class='even failure'><a href="rails_best_practices.html">Rails Best Practices</a></li>
26
29
  <% end %>
27
30
  </ul>
28
31
  <p>Generated on <%= Time.now.localtime %></p>
@@ -0,0 +1,27 @@
1
+ <h3>Rails Best Practices Results</h3>
2
+
3
+ <p><a href="http://github.com/flyerhzm/rails_best_practices">rails_best_practices</a> checks quality of rails app files according to ihower’s presentation from Kungfu RailsConf in Shanghai China.</p>
4
+
5
+ <% graph_name = 'rails_best_practices' %>
6
+ <% if MetricFu.configuration.graph_engine == :gchart %>
7
+ <img src="<%= graph_name %>.png?<%= Time.now.to_i %>" />
8
+ <% else %>
9
+ <canvas id="graph"></canvas>
10
+ <script language="javascript" src="<%= graph_name %>.js?<%= Time.now.to_i %>" type="text/javascript"></script>
11
+ <% end %>
12
+
13
+ <table>
14
+ <tr>
15
+ <th>File Path</th>
16
+ <th>Warning</th>
17
+ </tr>
18
+ <% count = 0 %>
19
+ <% @rails_best_practices[:problems].each do |problem| %>
20
+ <tr class='<%= cycle("light", "dark", count) %>'>
21
+ <td><%= link_to_filename(problem[:file], problem[:line]) %></td>
22
+ <td><%= problem[:problem] %></td>
23
+ </tr>
24
+ <% count += 1 %>
25
+ <% end %>
26
+ </table>
27
+ <p>Generated on <%= Time.now.localtime %></p>
@@ -32,6 +32,9 @@
32
32
  <% if @stats %>
33
33
  <p><a href="stats.html">Stats report</a></p>
34
34
  <% end %>
35
+ <% if @rails_best_practices %>
36
+ <p><a href="rails_best_practices.html">Rails Best Practices report</a></p>
37
+ <% end %>
35
38
  <p>Generated on <%= Time.now.localtime %></p>
36
39
  </body>
37
40
  </html>
@@ -0,0 +1,29 @@
1
+ <html>
2
+ <head>
3
+ <title>Rails Best Practices Results</title>
4
+ <style>
5
+ <%= inline_css("default.css") %>
6
+ </style>
7
+ </head>
8
+
9
+ <body>
10
+ <h1>Rails Best Practices Results</h1>
11
+ <a href="index.html">back to menu</a>
12
+ <p><a href="http://github.com/flyerhzm/rails_best_practices">rails_best_practices</a> checks quality of rails app files according to ihower’s presentation from Kungfu RailsConf in Shanghai China.</p>
13
+ <table>
14
+ <tr>
15
+ <th>File Path</th>
16
+ <th>Warning</th>
17
+ </tr>
18
+ <% count = 0 %>
19
+ <% @rails_best_practices[:problems].each do |problem| %>
20
+ <tr class='<%= cycle("light", "dark", count) %>'>
21
+ <td><%= problem[:file] %>:<%= problem[:line] %></td>
22
+ <td><%= problem[:problem] %></td>
23
+ </tr>
24
+ <% count += 1 %>
25
+ <% end %>
26
+ </table>
27
+ <p>Generated on <%= Time.now.localtime %></p>
28
+ </body>
29
+ </html>
@@ -87,7 +87,7 @@ describe MetricFu::Configuration do
87
87
 
88
88
  it 'should set @flay to {:dirs_to_flay => @code_dirs}' do
89
89
  @config.instance_variable_get(:@flay).
90
- should == {:dirs_to_flay => ['lib']}
90
+ should == {:dirs_to_flay => ['lib'], :minimum_score => 100}
91
91
  end
92
92
 
93
93
  it 'should set @flog to {:dirs_to_flog => @code_dirs}' do
@@ -125,7 +125,8 @@ describe MetricFu::Configuration do
125
125
  "--rails",
126
126
  "--exclude /gems/,/Library/,/usr/,spec"]}' do
127
127
  @config.instance_variable_get(:@rcov).
128
- should == { :test_files => ['test/**/*_test.rb',
128
+ should == { :environment => 'test',
129
+ :test_files => ['test/**/*_test.rb',
129
130
  'spec/**/*_spec.rb'],
130
131
  :rcov_opts => ["--sort coverage",
131
132
  "--no-html",
@@ -1,6 +1,9 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
2
2
 
3
3
  describe MetricFu::Generator do
4
+
5
+ include Construct::Helpers
6
+
4
7
  MetricFu::Configuration.run do |config|
5
8
  end
6
9
 
@@ -1,151 +1,42 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
2
2
 
3
3
  describe Churn do
4
- describe "initialize" do
5
- before :each do
6
- MetricFu::Configuration.run {}
7
- File.stub!(:directory?).and_return(true)
8
- end
9
-
10
- it "should setup git if .git exits" do
11
- MetricFu::Churn.should_receive(:system).and_return(true)
12
- Churn::Git.should_receive(:new)
13
- MetricFu::Churn.new
14
- end
15
-
16
- it "should setup git if .svn exits" do
17
- MetricFu::Churn.should_receive(:system).and_return(false)
18
- File.should_receive(:exist?).with(".svn").and_return(true)
19
- Churn::Svn.should_receive(:new)
20
- MetricFu::Churn.new()
21
- end
22
-
23
- it "should raise an error if not .svn or .git" do
24
- MetricFu::Churn.should_receive(:system).and_return(false)
25
- lambda{MetricFu::Churn.new()}.should raise_error(Exception)
26
- end
27
- end
28
-
29
- describe "emit method with git" do
30
- before :each do
31
- MetricFu::Configuration.run {|config| config.churn = {:minimum_churn_count => 2} }
32
- File.stub!(:directory?).and_return(true)
33
- MetricFu::Churn.should_receive(:system).and_return(true)
34
- @git = Churn::Git.new
35
- Churn::Git.should_receive(:new).and_return(@git)
36
- @lines = <<-HERE.gsub(/^\s*/, "")
37
-
38
- lib/generators/flog.rb
39
- spec/generators/flog_spec.rb
40
-
41
-
42
- lib/generators/flog.rb
43
- spec/generators/flay_spec.rb
44
-
45
-
46
- lib/metric_fu.rb
47
-
48
-
49
- lib/generators/saikuro.rb
50
- lib/metric_fu.rb
51
- tasks/metric_fu.rake
52
-
53
-
54
- spec/churn_spec.rb
55
- spec/config_spec.rb
56
- spec/flay_spec.rb
57
- spec/flog_spec.rb
58
- lib/metric_fu.rb
59
- spec/reek_spec.rb
60
- HERE
61
- end
62
-
63
- it "should read the logs" do
64
- churn = MetricFu::Churn.new
65
- @git.should_receive(:`).with("git log --name-only --pretty=format:").and_return(@lines)
66
- changes = churn.emit
67
- changes["lib/generators/flog.rb"].should == 2
68
- changes["lib/metric_fu.rb"].should == 3
69
- end
70
- end
71
-
72
- describe "emit method with svn" do
73
- before :each do
74
- MetricFu::Configuration.run{|config| config.churn = {:minimum_churn_count => 2} }
75
- File.stub!(:directory?).and_return(true)
76
- MetricFu::Churn.should_receive(:system).and_return(false)
77
- File.should_receive(:exist?).with(".svn").and_return(true)
78
- @svn = Churn::Svn.new
79
- Churn::Svn.should_receive(:new).and_return(@svn)
80
- @lines = <<-HERE.gsub(/^\s*/, "")
81
- ------------------------------------------------------------------------
82
- r3183 | dave | 2009-04-28 07:23:37 -0500 (Tue, 28 Apr 2009) | 1 line
83
- Changed paths:
84
- M /trunk/app/views/promotions/index.erb
85
- M /trunk/app/models/email_personalizer.rb
86
-
87
- making custom macros case-insensitive
88
- ------------------------------------------------------------------------
89
- r3182 | marc | 2009-04-28 03:59:32 -0500 (Tue, 28 Apr 2009) | 1 line
90
- Changed paths:
91
- M /trunk/app/models/file_extraction.rb
92
- M /trunk/app/views/promotions/index.erb
93
- M /trunk/config/environment.rb
94
-
95
- Demo of the drop out effect for uploading promotions.
96
- ------------------------------------------------------------------------
97
- r3181 | dave | 2009-04-27 21:40:04 -0500 (Mon, 27 Apr 2009) | 1 line
98
- Changed paths:
99
- M /trunk/app/views/promotions/index.erb
100
- A /trunk/app/models/file_extraction.rb
101
- A /trunk/app/models/url_file_extraction.rb
102
- M /trunk/app/models/zip_file_extraction.rb
103
- M /trunk/test/data/zip_test.zip
104
- M /trunk/test/unit/zip_file_extraction_test.rb
105
-
106
- URL imports
107
- HERE
108
- end
109
-
110
- it "should read the logs" do
111
- churn = MetricFu::Churn.new
112
- @svn.should_receive(:`).with("svn log --verbose").and_return(@lines)
113
- changes = churn.emit
114
- changes["/trunk/app/views/promotions/index.erb"].should == 3
115
- changes["/trunk/app/models/file_extraction.rb"].should == 2
116
- end
117
- end
118
4
 
119
5
  describe "analyze method" do
120
6
  before :each do
121
7
  MetricFu::Configuration.run {}
122
8
  File.stub!(:directory?).and_return(true)
123
- MetricFu::Churn.should_receive(:system).and_return(true)
9
+ MetricFu::Churn.should_receive(:verify_dependencies!).and_return(true)
124
10
  @changes = {"lib/generators/flog.rb"=>2, "lib/metric_fu.rb"=>3}
125
11
  end
126
12
 
127
- it "should organize and format" do
13
+ it "should be empty on error" do
128
14
  churn = MetricFu::Churn.new
129
- churn.instance_variable_set(:@changes, @changes)
130
- changes = churn.analyze
131
- changes.first[:file_path].should == "lib/metric_fu.rb"
132
- changes.first[:times_changed].should == 3
133
- changes[1][:file_path].should == "lib/generators/flog.rb"
134
- changes[1][:times_changed].should == 2
15
+ churn.instance_variable_set(:@output, "fatal: Not a git repository")
16
+ result = churn.analyze
17
+ result.should == [:churn => {}]
135
18
  end
19
+
20
+ it "should return yaml results" do
21
+ churn = MetricFu::Churn.new
22
+ churn.instance_variable_set(:@output, "--- \n:churn: \n :changed_files: \n - spec/graphs/flog_grapher_spec.rb\n - spec/base/graph_spec.rb\n - lib/templates/awesome/layout.html.erb\n - lib/graphs/rcov_grapher.rb\n - lib/base/base_template.rb\n - spec/graphs/grapher_spec.rb\n - lib/templates/awesome/flog.html.erb\n - lib/templates/awesome/flay.html.erb\n - lib/graphs/roodi_grapher.rb\n - lib/graphs/reek_grapher.rb\n - HISTORY\n - spec/graphs/roodi_grapher_spec.rb\n - lib/generators/rcov.rb\n - spec/graphs/engines/gchart_spec.rb\n - spec/graphs/rcov_grapher_spec.rb\n - lib/templates/javascripts/excanvas.js\n - lib/templates/javascripts/bluff-min.js\n - spec/graphs/reek_grapher_spec.rb\n")
23
+ result = churn.analyze
24
+ result.should == {:churn=>{:changed_files=>["spec/graphs/flog_grapher_spec.rb", "spec/base/graph_spec.rb", "lib/templates/awesome/layout.html.erb", "lib/graphs/rcov_grapher.rb", "lib/base/base_template.rb", "spec/graphs/grapher_spec.rb", "lib/templates/awesome/flog.html.erb", "lib/templates/awesome/flay.html.erb", "lib/graphs/roodi_grapher.rb", "lib/graphs/reek_grapher.rb", "HISTORY", "spec/graphs/roodi_grapher_spec.rb", "lib/generators/rcov.rb", "spec/graphs/engines/gchart_spec.rb", "spec/graphs/rcov_grapher_spec.rb", "lib/templates/javascripts/excanvas.js", "lib/templates/javascripts/bluff-min.js", "spec/graphs/reek_grapher_spec.rb"]}}
25
+ end
26
+
136
27
  end
137
28
 
138
29
  describe "to_h method" do
139
30
  before :each do
140
31
  MetricFu::Configuration.run {}
141
32
  File.stub!(:directory?).and_return(true)
142
- MetricFu::Churn.should_receive(:system).and_return(true)
33
+ MetricFu::Churn.should_receive(:verify_dependencies!).and_return(true)
143
34
  end
144
35
 
145
36
  it "should put the changes into a hash" do
146
37
  churn = MetricFu::Churn.new
147
- churn.instance_variable_set(:@changes, "churn_info")
148
- churn.to_h[:churn][:changes].should == "churn_info"
38
+ churn.instance_variable_set(:@churn, {:churn => 'results'})
39
+ churn.to_h[:churn].should == "results"
149
40
  end
150
41
  end
151
42
  end
@@ -5,19 +5,25 @@ describe Flay do
5
5
  MetricFu::Flay.stub!(:verify_dependencies!).and_return(true)
6
6
  end
7
7
  describe "emit method" do
8
- before :each do
8
+ it "should look at the dirs" do
9
9
  MetricFu::Configuration.run {|config| config.flay = { :dirs_to_flay => ['app', 'lib'] } }
10
10
  File.stub!(:directory?).and_return(true)
11
- @flay = MetricFu::Flay.new('base_dir')
12
-
13
- end
11
+ @flay = MetricFu::Flay.new('base_dir')
14
12
 
15
- it "should look at the dirs" do
16
13
  Dir.should_receive(:[]).with(File.join("app", "**/*.rb")).and_return("path/to/app")
17
14
  Dir.should_receive(:[]).with(File.join("lib", "**/*.rb")).and_return("path/to/lib")
18
15
  @flay.should_receive(:`).with("flay path/to/app path/to/lib")
19
16
  output = @flay.emit
20
17
  end
18
+
19
+ it "should limit flay scores by the minimum_score" do
20
+ MetricFu::Configuration.run {|config| config.flay = { :dirs_to_flay => [], :minimum_score => 99 } }
21
+ File.stub!(:directory?).and_return(true)
22
+ @flay = MetricFu::Flay.new('base_dir')
23
+
24
+ @flay.should_receive(:`).with("flay --mass 99 ")
25
+ output = @flay.emit
26
+ end
21
27
  end
22
28
 
23
29
  describe "analyze method" do
@@ -4,7 +4,6 @@ describe "Gchart graphers responding to #graph!" do
4
4
  MetricFu::AVAILABLE_GRAPHS.each do |metric|
5
5
  it "should write chart file for #{metric}" do
6
6
  MetricFu.configuration
7
- puts "#{metric.to_s.capitalize}GchartGrapher"
8
7
  grapher = MetricFu.const_get("#{metric.to_s.capitalize}GchartGrapher").new
9
8
  grapher.flog_average, grapher.top_five_percent_average = [7.0],[20.0] if metric == :flog #googlecharts gem has problems with [[],[]] as data
10
9
  grapher.graph!
@@ -1,6 +1,7 @@
1
1
  require 'rubygems'
2
2
  require 'spec/autorun'
3
3
  require 'date'
4
+ require 'construct'
4
5
 
5
6
  require File.join(File.dirname(__FILE__), '/../lib/metric_fu.rb')
6
7
  include MetricFu
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: edouard-metric_fu
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jake Scruggs
@@ -12,11 +12,12 @@ authors:
12
12
  - Nick Quaranto
13
13
  - "\xC3\x89douard Bri\xC3\xA8re"
14
14
  - Carl Youngblood
15
+ - Richard Huang
15
16
  autorequire:
16
17
  bindir: bin
17
18
  cert_chain: []
18
19
 
19
- date: 2010-01-15 00:00:00 +01:00
20
+ date: 2010-01-22 00:00:00 +01:00
20
21
  default_executable:
21
22
  dependencies:
22
23
  - !ruby/object:Gem::Dependency
@@ -49,6 +50,36 @@ dependencies:
49
50
  - !ruby/object:Gem::Version
50
51
  version: 0.9.7.1
51
52
  version:
53
+ - !ruby/object:Gem::Dependency
54
+ name: reek
55
+ type: :runtime
56
+ version_requirement:
57
+ version_requirements: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: 1.2.6
62
+ version:
63
+ - !ruby/object:Gem::Dependency
64
+ name: roodi
65
+ type: :runtime
66
+ version_requirement:
67
+ version_requirements: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: 2.1.0
72
+ version:
73
+ - !ruby/object:Gem::Dependency
74
+ name: rails_best_practices
75
+ type: :runtime
76
+ version_requirement:
77
+ version_requirements: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: 0.3.16
82
+ version:
52
83
  - !ruby/object:Gem::Dependency
53
84
  name: chronic
54
85
  type: :runtime
@@ -59,6 +90,16 @@ dependencies:
59
90
  - !ruby/object:Gem::Version
60
91
  version: 0.2.3
61
92
  version:
93
+ - !ruby/object:Gem::Dependency
94
+ name: churn
95
+ type: :runtime
96
+ version_requirement:
97
+ version_requirements: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ version: 0.0.10
102
+ version:
62
103
  - !ruby/object:Gem::Dependency
63
104
  name: Saikuro
64
105
  type: :runtime
@@ -69,7 +110,47 @@ dependencies:
69
110
  - !ruby/object:Gem::Version
70
111
  version: 1.1.0
71
112
  version:
72
- description: Code metrics from Flog, Flay, RCov, Saikuro, Churn, Reek, Roodi and Rails' stats task
113
+ - !ruby/object:Gem::Dependency
114
+ name: activesupport
115
+ type: :runtime
116
+ version_requirement:
117
+ version_requirements: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ version: 2.2.3
122
+ version:
123
+ - !ruby/object:Gem::Dependency
124
+ name: rspec
125
+ type: :development
126
+ version_requirement:
127
+ version_requirements: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: 1.2.0
132
+ version:
133
+ - !ruby/object:Gem::Dependency
134
+ name: devver-construct
135
+ type: :development
136
+ version_requirement:
137
+ version_requirements: !ruby/object:Gem::Requirement
138
+ requirements:
139
+ - - ">="
140
+ - !ruby/object:Gem::Version
141
+ version: 1.1.0
142
+ version:
143
+ - !ruby/object:Gem::Dependency
144
+ name: mg
145
+ type: :development
146
+ version_requirement:
147
+ version_requirements: !ruby/object:Gem::Requirement
148
+ requirements:
149
+ - - ">="
150
+ - !ruby/object:Gem::Version
151
+ version: 0.0.6
152
+ version:
153
+ description: Code metrics from Flog, Flay, RCov, Saikuro, Churn, Reek, Roodi and Rails' stats task and Rails Best Practices
73
154
  email: jake.scruggs@gmail.com
74
155
  executables: []
75
156
 
@@ -99,6 +180,7 @@ files:
99
180
  - lib/generators/roodi.rb
100
181
  - lib/generators/saikuro.rb
101
182
  - lib/generators/stats.rb
183
+ - lib/generators/rails_best_practices.rb
102
184
  - lib/graphs/engines/bluff.rb
103
185
  - lib/graphs/engines/gchart.rb
104
186
  - lib/graphs/flay_grapher.rb
@@ -107,6 +189,7 @@ files:
107
189
  - lib/graphs/rcov_grapher.rb
108
190
  - lib/graphs/reek_grapher.rb
109
191
  - lib/graphs/roodi_grapher.rb
192
+ - lib/graphs/rails_best_practices_grapher.rb
110
193
  - lib/metric_fu.rb
111
194
  - lib/templates/awesome/awesome_template.rb
112
195
  - lib/templates/awesome/churn.html.erb
@@ -123,6 +206,7 @@ files:
123
206
  - lib/templates/awesome/roodi.html.erb
124
207
  - lib/templates/awesome/saikuro.html.erb
125
208
  - lib/templates/awesome/stats.html.erb
209
+ - lib/templates/awesome/rails_best_practices.html.erb
126
210
  - lib/templates/javascripts/bluff-min.js
127
211
  - lib/templates/javascripts/excanvas.js
128
212
  - lib/templates/javascripts/js-class.js
@@ -137,6 +221,7 @@ files:
137
221
  - lib/templates/standard/saikuro.html.erb
138
222
  - lib/templates/standard/standard_template.rb
139
223
  - lib/templates/standard/stats.html.erb
224
+ - lib/templates/standard/rails_best_practices.html.erb
140
225
  - tasks/metric_fu.rake
141
226
  - Manifest.txt
142
227
  has_rdoc: true
@@ -146,7 +231,7 @@ licenses: []
146
231
  post_install_message:
147
232
  rdoc_options:
148
233
  - --main
149
- - README
234
+ - README.textile
150
235
  require_paths:
151
236
  - lib
152
237
  required_ruby_version: !ruby/object:Gem::Requirement