Created
November 6, 2009 19:51
-
-
Save mtkd/228223 to your computer and use it in GitHub Desktop.
Monkeypatch to add 3 decimal places to 'Code to Test Ratio' in rake stats
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Monkey patch to add 3 decimal places to code/test ratio | |
# Add to rakefile | |
Rake::TaskManager.class_eval do | |
def remove_task(task_name) | |
@tasks.delete(task_name.to_s) | |
end | |
end | |
def remove_task(task_name) | |
Rake.application.remove_task(task_name) | |
end | |
remove_task :stats | |
task :stats => [ :environment ] do | |
require 'code_statistics' | |
class CodeStatistics | |
alias to_s_old to_s | |
def to_s | |
print_header | |
@pairs.each { |pair| print_line(pair.first, @statistics[pair.first]) } | |
print_splitter | |
if @total | |
print_line("Total", @total) | |
print_splitter | |
end | |
code = calculate_code | |
tests = calculate_tests | |
puts " Code LOC: #{code} Test LOC: #{tests} Code to Test Ratio: 1:#{sprintf("%.3f", tests.to_f/code)}" | |
puts "" | |
end | |
end | |
CodeStatistics.new( | |
["Controllers", "app/controllers"], | |
["Helpers", "app/helpers"], | |
["Models", "app/models"], | |
["Libraries", "lib/"], | |
["Functionals", "test/functional"], | |
["Units", "test/unit"] | |
).to_s | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment