2

我正在尝试在 Rails 3 应用程序上运行 metric_fu。一切都很好,除了rcov。我已经配置了 RSpec,我的测试遵循 spec/**/*.rb 格式并在 RSpec 中运行良好。但是,尝试使用 rcov 检查覆盖率时,出现以下错误:

** Running the specs/tests in the [test] environment

No file to analyze was found. All the files loaded by rcov matched one of the
following expressions, and were thus ignored:
[/\A\/Users\/Eric\/\.rvm\/rubies\/ruby\-1\.8\.7\-p299\/lib/,
 /\btc_[^.]*.rb/,
 /_test\.rb\z/,
 /\btest\//,
 /\bvendor\//,
 /\A\/Users\/Eric\/\.rvm\/gems\/ruby\-1\.8\.7\-p299@-backend\/gems\/rcov\-0\.9\.8\/lib\/rcov\/formatters\/base_formatter\.rb\z/,
 /\bvendor\//,
 /\bconfig\//,
 /\benvironment\//,
 /\/gems\//,
 /\/Library\//,
 /\/usr\//,
 /spec/]

You can solve this by doing one or more of the following:
* rename the files not to be ignored so they don't match the above regexps
* use --include-file to give a list of patterns for files not to be ignored
* use --exclude-only to give the new list of regexps to match against
* structure your code as follows:
      test/test_*.rb  for the test cases
      lib/**/*.rb     for the target source code whose coverage you want
  making sure that the test/test_*.rb files are loading from lib/, e.g. by 
  using the -Ilib command-line argument, adding  
    $:.unshift File.join(File.dirname(__FILE__), "..", "lib")
  to test/test_*.rb, or running rcov via a Rakefile (read the RDoc
  documentation or README.rake in the source distribution).
/Users/Eric/.rvm/rubies/ruby-1.8.7-p299/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require': no such file to load -- spec_helper (LoadError)
    from /Users/Eric/.rvm/rubies/ruby-1.8.7-p299/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
    from ./spec/models/account_spec.rb:1
    from /Users/Eric/.rvm/gems/ruby-1.8.7-p299@backend/gems/rcov-0.9.8/bin/rcov:511:in `load'
    from /Users/Eric/.rvm/gems/ruby-1.8.7-p299@backend/gems/rcov-0.9.8/bin/rcov:511
    from /Users/Eric/.rvm/gems/ruby-1.8.7-p299@backend/bin/rcov:19:in `load'
    from /Users/Eric/.rvm/gems/ruby-1.8.7-p299@backend/bin/rcov:19

当我直接运行 rcov 时,问题的一部分似乎是 rcov 没有正确加载我的规范中的 spec_helper,这是“require 'spec_helper'”所必需的。

有关如何解决此问题的任何帮助?谢谢。

4

1 回答 1

0

在 Metric-Fu 配置中添加“-Ispec”可以解决此问题。

于 2010-07-15T17:09:54.837 回答