论坛首页 编程语言技术论坛

解决Rcov报告仅能列出被Rspec测试调用过的文件

浏览 1727 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2008-03-21  
ruby的框架确实还很不成熟(这点确实不比java爽),不废话,在某个initializer中加入如下代码
#这里写你要包含的目录
RCOV_APPS_FILES = [/app[\/\\][^\.]+\.rb/]
require 'rcov'
class Rcov::CodeCoverageAnalyzer
  alias_method(:old_dump_coverage_info, :dump_coverage_info) unless method_defined?(:old_dump_coverage_info)
  def dump_coverage_info(formatters)
    all_files = []
    require 'find'

    Find.find(RAILS_ROOT) do |path|
      Find.prune if path.index(".svn") || path.index(".cvs")
      RCOV_APPS_FILES.each do |r|
        if path =~ r
          all_files << path
          break
        end
      end
    end
    all_files.each do |file|
      formatters.each do |formatter|
        lines = File.read(file).split("\n")
        coverage = lines.collect{|i| false}
        counts = coverage.collect{|i| 0}
        formatter.add_file(file, lines, coverage, counts)
      end
    end
    
    old_dump_coverage_info(formatters)
  end
end
论坛首页 编程语言技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics