aboutsummaryrefslogtreecommitdiffstats
path: root/railties
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2004-12-22 13:08:26 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2004-12-22 13:08:26 +0000
commitebf2b12b07641cbdf07218d2661a721ebab6092f (patch)
treedd48278c02c6f7761254a3ea20265a630f9c78f8 /railties
parentdcc486805e5d79bd10fd5dfe302302522d250e86 (diff)
downloadrails-ebf2b12b07641cbdf07218d2661a721ebab6092f.tar.gz
rails-ebf2b12b07641cbdf07218d2661a721ebab6092f.tar.bz2
rails-ebf2b12b07641cbdf07218d2661a721ebab6092f.zip
Fixed "rake stats" to work with sub-directories in models and controllers and to report the code to test ration [Scott Baron]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@245 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'railties')
-rw-r--r--railties/CHANGELOG2
-rwxr-xr-xrailties/fresh_rakefile8
-rw-r--r--railties/lib/code_statistics.rb39
3 files changed, 42 insertions, 7 deletions
diff --git a/railties/CHANGELOG b/railties/CHANGELOG
index a0e402e5e1..38f4cb1928 100644
--- a/railties/CHANGELOG
+++ b/railties/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Fixed "rake stats" to work with sub-directories in models and controllers and to report the code to test ration [Scott Baron]
+
* Added that Active Record associations are now reloaded instead of cleared to work with the new const_missing hook in Active Record.
* Added graceful handling of an inaccessible log file by redirecting output to STDERR with a warning #330 [rainmkr]
diff --git a/railties/fresh_rakefile b/railties/fresh_rakefile
index e9f3afd7ae..437c999522 100755
--- a/railties/fresh_rakefile
+++ b/railties/fresh_rakefile
@@ -63,11 +63,11 @@ Rake::RDocTask.new("apidoc") { |rdoc|
desc "Report code statistics (KLOCs, etc) from the application"
task :stats do
CodeStatistics.new(
- ["Controllers", "app/controllers"],
["Helpers", "app/helpers"],
+ ["Controllers", "app/controllers"],
+ ["Functionals", "test/functional"],
["Models", "app/models"],
- ["Units", "test/unit"],
- ["Functionals", "test/functional"]
+ ["Units", "test/unit"]
).to_s
end
@@ -103,4 +103,4 @@ task :purge_test_database do
`dropdb -U #{ActiveRecord::Base.configurations["test"]["username"]} #{ActiveRecord::Base.configurations["test"]["database"]}`
`createdb -U #{ActiveRecord::Base.configurations["test"]["username"]} #{ActiveRecord::Base.configurations["test"]["database"]}`
end
-end \ No newline at end of file
+end
diff --git a/railties/lib/code_statistics.rb b/railties/lib/code_statistics.rb
index 53e7feb1c0..825772fcf1 100644
--- a/railties/lib/code_statistics.rb
+++ b/railties/lib/code_statistics.rb
@@ -7,13 +7,15 @@ class CodeStatistics
def to_s
print_header
- @statistics.each{ |k, v| print_line(k, v) }
+ @pairs.each { |pair| print_line(pair.first, @statistics[pair.first]) }
print_splitter
if @total
print_line("Total", @total)
print_splitter
end
+
+ print_code_test_stats
end
private
@@ -25,6 +27,11 @@ class CodeStatistics
stats = { "lines" => 0, "codelines" => 0, "classes" => 0, "methods" => 0 }
Dir.foreach(directory) do |file_name|
+ if File.stat(directory + "/" + file_name).directory? and (/^\./ !~ file_name)
+ newstats = calculate_directory_statistics(directory + "/" + file_name, pattern)
+ stats.each { |k, v| stats[k] += newstats[k] }
+ end
+
next unless file_name =~ pattern
f = File.open(directory + "/" + file_name)
@@ -46,6 +53,18 @@ class CodeStatistics
total
end
+ def calculate_code
+ code_loc = 0
+ @statistics.each { |k, v| code_loc += v['codelines'] unless ['Units', 'Functionals'].include? k }
+ code_loc
+ end
+
+ def calculate_tests
+ test_loc = 0
+ @statistics.each { |k, v| test_loc += v['codelines'] if ['Units', 'Functionals'].include? k }
+ test_loc
+ end
+
def print_header
print_splitter
puts "| Name | Lines | LOC | Classes | Methods | M/C | LOC/M |"
@@ -60,7 +79,13 @@ class CodeStatistics
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
- puts "| #{name.ljust(20)} " +
+ start = if ['Units', 'Functionals'].include? name
+ "| #{name.ljust(18)} "
+ else
+ "| #{name.ljust(20)} "
+ end
+
+ puts start +
"| #{statistics["lines"].to_s.rjust(5)} " +
"| #{statistics["codelines"].to_s.rjust(5)} " +
"| #{statistics["classes"].to_s.rjust(7)} " +
@@ -68,4 +93,12 @@ class CodeStatistics
"| #{m_over_c.to_s.rjust(3)} " +
"| #{loc_over_m.to_s.rjust(5)} |"
end
-end \ No newline at end of file
+
+ def print_code_test_stats
+ code = calculate_code
+ tests = calculate_tests
+
+ puts " Code LOC: #{code} Test LOC: #{tests} Code to Test Ratio: #{sprintf("%.1f", code/tests.to_f)}:1"
+ puts ""
+ end
+ end