测试设置是一个'lib'文件夹,其中包含一个定义类的文件,文件夹'test'和'test / sub_test','sub_test'包含单个'test_example_lib.rb'和一个像这样的Rakefile :
require 'rcov/rcovtask' task :default => [:rcov] desc "RCov" Rcov::RcovTask.new do | t | t.test_files = FileList[ 'test/**/test_*.rb' ] end
#rake (in /Users/stephan/tmp/rcov_example) rm -r coverage Loaded suite /Users/stephan/.rvm/gems/ruby-1.8.7-p174/bin/rcov Started . Finished in 0.000508 seconds. 1 tests, 2 assertions, 0 failures, 0 errors +----------------------------------------------------+-------+-------+--------+ | File | Lines | LOC | COV | +----------------------------------------------------+-------+-------+--------+ |...ms/rcov-0.9.8/lib/rcov/code_coverage_analyzer.rb | 271 | 156 | 5.1% | |...ems/rcov-0.9.8/lib/rcov/differential_analyzer.rb | 116 | 82 | 9.8% | |lib/example_lib.rb | 16 | 11 | 72.7% | +----------------------------------------------------+-------+-------+--------+ |Total | 403 | 249 | 9.6% | +----------------------------------------------------+-------+-------+--------+ 9.6% 3 file(s) 403 Lines 249 LOC
为什么RCov本身会在这里进行分析? 我希望(当使用'rvm use system'时不会发生这种情况)。 事实上,这似乎是由于我使用通过rvm安装的Ruby。
答案 0 :(得分:3)
在rcov中添加一些排除:
- exclude / gems /,/ Library /,/ usr /,spec,lib / tasks
require 'rcov/rcovtask'
task :default => [:rcov]
desc "RCov"
Rcov::RcovTask.new do | t |
t.test_files = FileList[ 'test/**/test_*.rb' ]
t.rcov_opts << '--exclude /gems/,/Library/,/usr/,spec,lib/tasks'
end