Ticket #2297: rake_stats_names_for_tests_patch.diff
| File rake_stats_names_for_tests_patch.diff, 2.3 kB (added by lasse.koskela@gmail.com, 4 years ago) |
|---|
-
railties/lib/tasks/statistics.rake
old new 1 1 STATS_DIRECTORIES = [ 2 %w(Helpers app/helpers),3 %w(Controllers app/controllers),4 %w(APIs app/apis),5 %w(Components components),6 %w(Functional s test/functional),7 %w(Models app/models),8 %w(Unit s test/unit),9 %w(Libraries lib/)2 %w(Helpers app/helpers), 3 %w(Controllers app/controllers), 4 %w(APIs app/apis), 5 %w(Components components), 6 %w(Functional\ tests test/functional), 7 %w(Models app/models), 8 %w(Unit\ tests test/unit), 9 %w(Libraries lib/) 10 10 ].collect { |name, dir| [ name, "#{RAILS_ROOT}/#{dir}" ] }.select { |name, dir| File.directory?(dir) } 11 11 12 12 desc "Report code statistics (KLOCs, etc) from the application" -
railties/lib/code_statistics.rb
old new 1 1 class CodeStatistics 2 3 TEST_TYPES = ['Unit tests', 'Functional tests'] 4 2 5 def initialize(*pairs) 3 6 @pairs = pairs 4 7 @statistics = calculate_statistics … … 55 58 56 59 def calculate_code 57 60 code_loc = 0 58 @statistics.each { |k, v| code_loc += v['codelines'] unless ['Units', 'Functionals'].include? k }61 @statistics.each { |k, v| code_loc += v['codelines'] unless TEST_TYPES.include? k } 59 62 code_loc 60 63 end 61 64 62 65 def calculate_tests 63 66 test_loc = 0 64 @statistics.each { |k, v| test_loc += v['codelines'] if ['Units', 'Functionals'].include? k }67 @statistics.each { |k, v| test_loc += v['codelines'] if TEST_TYPES.include? k } 65 68 test_loc 66 69 end 67 70 … … 79 82 m_over_c = (statistics["methods"] / statistics["classes"]) rescue m_over_c = 0 80 83 loc_over_m = (statistics["codelines"] / statistics["methods"]) - 2 rescue loc_over_m = 0 81 84 82 start = if ['Units', 'Functionals'].include? name85 start = if TEST_TYPES.include? name 83 86 "| #{name.ljust(18)} " 84 87 else 85 88 "| #{name.ljust(20)} "