[rspec-users] strange results when using rcov with rspec

David Smalley david.smalley.lists at googlemail.com
Thu May 17 13:20:24 EDT 2007

I have some specs tucked away inside my vendor/plugins directory that  
I want to run when I run rake spec.

I've got the rake task working just fine, but for some reason rcov  
seems to choke when I try to tweak the included/excluded files to  
ignore any files in app/ but to include files in vendor/plugins/ 

The error I get is this:

No file to analyze was found. All the files loaded by rcov matched  
one of the following expressions, and were thus ignored: [/\A\/usr\/ 
lib/, /\btc_[^.]*.rb/, /_test\.rb\z/, /\btest\//, /\bvendor\//, /\A\/ 
\.rb\z/, /lib\/spec/, /bin\/spec\//, /app/, /config/] 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). ./vendor/plugins/sor_core/app/models/ 
collection.rb:1: uninitialized constant ActiveRecord (NameError)  
from /usr/lib/ruby/gems/1.8/gems/rcov- from /usr/ 
bin/rcov:16 rake aborted!
RSpec failures (See full trace by running task with --trace)

A snippet of the rake task I am using looks like this:

     desc "Run the specs under vendor/plugins/**/spec/models"
      Spec::Rake::SpecTask.new(:models => "db:test:prepare") do |t|
        t.spec_opts = ['--options', "\"#{RAILS_ROOT}/spec/spec.opts\""]
        t.spec_files = FileList["vendor/plugins/#{ENV['PLUGIN'] ||  
        t.rcov = true
        t.rcov_dir = "spec/reports/model-coverage"
        t.rcov_opts = ['--include-file', "vendor\/plugins\/#{ENV 
['PLUGIN'] || "**"}\/app\/models\/*", '--exclude', "lib\/spec,bin\/ 
        t.spec_opts = ["--format", "html"]
        t.out = "spec/reports/model-report/index.html"

If I just run a plain old rspec with this command:

    desc "Run the specs under spec/models"
      Spec::Rake::SpecTask.new(:models => "db:test:prepare") do |t|
        t.spec_opts = ['--options', "\"#{RAILS_ROOT}/spec/spec.opts\""]
        t.spec_files = FileList["vendor/plugins/#{ENV['PLUGIN'] ||  

Then all my tests run through just fine without any problems (but  
obviously produce no spec reports or rcov reports)

Anyone got any ideas?



More information about the rspec-users mailing list