1. Better rake:stats Test Code Ratio Metrics

    12 November 2008

    It doesn’t make much sense to me why rake:stats will only return 0.1 precision on the test code ratio. So, if you’d like a more precise metric make a change to the code in Rails:

    rails/lib/code_statistics.rb
    from:


    def print_code_test_stats
    code = calculate_code
    tests = calculate_tests

    puts " Code LOC: #{code} Test LOC: #{tests} Code to Test Ratio: 1:#{sprintf("%.1f", tests.to_f/code)}"
    puts ""
    end

    to:

    def print_code_test_stats
    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


    Take note of changing the floating point precision from 0.1 to 0.3. Feel free to change it to whatever precision you would like.