From 915380ad38e2a7df088014856235e401467e8a4b Mon Sep 17 00:00:00 2001
From: Richard Penwell <almightylinuxgod@me.com>
Date: Fri, 12 Mar 2010 14:12:49 -0500
Subject: [PATCH] Enhanced code statistics tasks for Rails.
* Statistics module detects other test and spec types.
* Provided a Rails spec task
---
Rakefile | 17 +++++++++++++++++
railties/lib/rails/code_statistics.rb | 8 ++++----
2 files changed, 21 insertions(+), 4 deletions(-)
diff --git a/Rakefile b/Rakefile
index 4437b48..8e47641 100644
--- a/Rakefile
+++ b/Rakefile
@@ -148,3 +148,20 @@ task :update_versions do
end
end
end
+
+desc "Report code statistics (KLOCs, etc) from the application"
+task :stats do
+ require ''railties/lib/rails/code_statistics''
+
+ STATS_DIRECTORIES + %w(ActionPack ActiveSupport Railties ActiveModel ARel
ActiveRecord ActionMailer ActiveResource).inject(Array.new) do |array,
framework|
+ array << [framework, File.join(framework.downcase,
''lib'')]
+ if File.exists?(File.join(framework.downcase, ''test''))
+ array << [framework + '' tests'',
File.join(framework.downcase,
''test'')]
+ elsif File.exists?(File.join(framework.downcase,
''spec''))
+ array << [framework + '' specs'',
File.join(framework.downcase,
''spec'')]
+ end
+ end
+
+ CodeStatistics.new(*STATS_DIRECTORIES).to_s
+end
diff --git a/railties/lib/rails/code_statistics.rb b/railties/lib/
rails/code_statistics.rb
index 740d8a1..4be8041 100644
--- a/railties/lib/rails/code_statistics.rb
+++ b/railties/lib/rails/code_statistics.rb
@@ -1,6 +1,6 @@
class CodeStatistics #:nodoc:
- TEST_TYPES = %w(Units Functionals Unit\ tests Functional\ tests
Integration\ tests)
+ TEST_TYPES = %w(tests specs)
def initialize(*pairs)
@pairs = pairs
@@ -58,13 +58,13 @@ class CodeStatistics #:nodoc:
def calculate_code
code_loc = 0
- @statistics.each { |k, v| code_loc += v[''codelines'']
unless
TEST_TYPES.include? k }
+ @statistics.each { |k, v| code_loc += v[''codelines'']
unless
TEST_TYPES.any?{|t| k.include? t} }
code_loc
end
def calculate_tests
test_loc = 0
- @statistics.each { |k, v| test_loc += v[''codelines''] if
TEST_TYPES.include? k }
+ @statistics.each { |k, v| test_loc += v[''codelines''] if
TEST_TYPES.any?{|t| k.include? t} }
test_loc
end
@@ -82,7 +82,7 @@ class CodeStatistics #:nodoc:
m_over_c = (statistics["methods"] /
statistics["classes"])
rescue m_over_c = 0
loc_over_m = (statistics["codelines"] /
statistics["methods"])
- 2 rescue loc_over_m = 0
- start = if TEST_TYPES.include? name
+ start = if TEST_TYPES.any?{|t| name.include? t}
"| #{name.ljust(20)} "
else
"| #{name.ljust(20)} "
--
1.6.6
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Core" group.
To post to this group, send email to rubyonrails-core@googlegroups.com.
To unsubscribe from this group, send email to
rubyonrails-core+unsubscribe@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/rubyonrails-core?hl=en.