2010-01-14 57 views
2

我正在嘗試讓metric-fu運行在我正在使用的rails項目上。每次運行我得到的指標的rcov部分:Metric-Fu/Rcov「無法分析文件」

** Invoke metrics:all (first_time) 
** Execute metrics:all 

No file to analyze was found. All the files loaded by rcov matched one of the 
following expressions, and were thus ignored: 
[/\A\/System\/Library\/Frameworks\/Ruby\.framework\/Versions\/1\.8\/usr\/lib/, 
/\btc_[^.]*.rb/, 
/_test\.rb\z/, 
/\btest\//, 
/\bvendor\//, 
/\A\/Library\/Ruby\/Gems\/1\.8\/gems\/rcov\-0\.9\.7\.1\/lib\/rcov\/formatters\/base_formatter\.rb\z/, 
/\bvendor\//, 
/\bconfig\//, 
/\benvironment\//, 
/\/gems\//, 
/\/Library\//, 
/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). 
rake aborted! 
NaN 
/Library/Ruby/Gems/1.8/gems/activesupport-2.3.3/lib/active_support/core_ext/float/rounding.rb:19:in `round_without_precision' 
/Library/Ruby/Gems/1.8/gems/activesupport-2.3.3/lib/active_support/core_ext/float/rounding.rb:19:in `round' 
/Library/Ruby/Gems/1.8/gems/metric_fu-1.2.0/lib/base/generator.rb:135:in `round_to_tenths' 
/Library/Ruby/Gems/1.8/gems/metric_fu-1.2.0/lib/generators/rcov.rb:84:in `to_h' 
/Library/Ruby/Gems/1.8/gems/metric_fu-1.2.0/lib/base/generator.rb:131:in `generate_report' 
/Library/Ruby/Gems/1.8/gems/metric_fu-1.2.0/lib/base/generator.rb:53:in `generate_report' 
/Library/Ruby/Gems/1.8/gems/metric_fu-1.2.0/lib/base/report.rb:54:in `add' 
/Library/Ruby/Gems/1.8/gems/metric_fu-1.2.0/lib/../tasks/metric_fu.rake:6 
/Library/Ruby/Gems/1.8/gems/metric_fu-1.2.0/lib/../tasks/metric_fu.rake:6:in `each' 
/Library/Ruby/Gems/1.8/gems/metric_fu-1.2.0/lib/../tasks/metric_fu.rake:6 
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:636:in `call' 
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:636:in `execute' 
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:631:in `each' 
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:631:in `execute' 
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:597:in `invoke_with_call_chain' 
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/monitor.rb:242:in `synchronize' 
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:590:in `invoke_with_call_chain' 
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:583:in `invoke' 
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:2051:in `invoke_task' 
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in `top_level' 
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in `each' 
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in `top_level' 
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:2068:in `standard_exception_handling' 
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:2023:in `top_level' 
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:2001:in `run' 
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:2068:in `standard_exception_handling' 
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:1998:in `run' 
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/bin/rake:31 
/usr/bin/rake:19:in `load' 
/usr/bin/rake:19 

運行rcov本身出現了相同的問題。如果有幫助,我使用Rspec而不是TestUnit。

+0

運行rcov的rake任務是什麼樣的? – BaroqueBobcat 2010-01-15 16:36:51

+0

當我用metric-fu做的時候,我使用的配置是http://metric-fu.rubyforge.org/ rcov.opts當我運行rake spec時:rcov有以下選項: - 排除「投機/ *,寶石/ * --rails 兩端所有默認的東西,但結果相同 – 2010-01-15 17:54:35

回答

4

如果使用耙子推出metric_fu您可以添加任何目錄rcov在這個片段中路徑:

begin 
    require 'metric_fu' 
    MetricFu::Configuration.run do |config| 
    config.rcov[:rcov_opts] << "-Ispec" 
    end 
rescue LoadError 
end 

這將增加-Ispec標誌rcov選項,這反過來將增加'spec'目錄到rcov的路徑。

0

因此,rcov會顯示「找不到要分析的文件」。當問題實際上是消息下方的堆棧跟蹤時的消息。你可以嘗試升級你的rcov版本(你在哪個版本上?)。

+0

我的寶石列表中可以看出: rcov(0.9.7.1) – 2010-01-15 17:50:36

1

我刪除了「test」目錄,並將「--include spec/spec_helper.rb」添加到Rcov配置哈希。我認爲它需要特別指出規範助手,你需要刪除測試目錄,否則它會嘗試在testunit上運行rcov,而不是rspec。

希望這可以幫助別人!