Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

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  
    11STATS_DIRECTORIES = [ 
    2   %w(Helpers     app/helpers),  
    3   %w(Controllers app/controllers),  
    4   %w(APIs        app/apis), 
    5   %w(Components  components), 
    6   %w(Functionals test/functional), 
    7   %w(Models      app/models), 
    8   %w(Units       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/) 
    1010].collect { |name, dir| [ name, "#{RAILS_ROOT}/#{dir}" ] }.select { |name, dir| File.directory?(dir) } 
    1111 
    1212desc "Report code statistics (KLOCs, etc) from the application" 
  • railties/lib/code_statistics.rb

    old new  
    11class CodeStatistics 
     2 
     3  TEST_TYPES = ['Unit tests', 'Functional tests'] 
     4 
    25  def initialize(*pairs) 
    36    @pairs      = pairs 
    47    @statistics = calculate_statistics 
     
    5558 
    5659    def calculate_code 
    5760      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 } 
    5962      code_loc 
    6063    end 
    6164 
    6265    def calculate_tests 
    6366      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 } 
    6568      test_loc 
    6669    end 
    6770 
     
    7982      m_over_c   = (statistics["methods"] / statistics["classes"])   rescue m_over_c = 0 
    8083      loc_over_m = (statistics["codelines"] / statistics["methods"]) - 2 rescue loc_over_m = 0 
    8184 
    82       start = if ['Units', 'Functionals'].include? name 
     85      start = if TEST_TYPES.include? name 
    8386        "|   #{name.ljust(18)} " 
    8487      else 
    8588        "| #{name.ljust(20)} "