Skipping files in spec / when rcov starts with RSpec 2.5

When you run rake spec:rcov for a Rails 3 application, the files in the spec/ directory fall into the coverage statistics, but I don’t want them to be. I want coverage statistics only for my actual application.

In older versions of RSpec, it was possible to configure this using the spec/rcov.opts with the --exclude "spec/*" , but it seems that the file is no longer readable by Rspec 2. I tried to create the .rcov file, since spec/spec.opts changed to .rspec , but that didn't work either.

I found some documentation on how to do this when defining the rake task, but I would prefer not to overwrite the rake command provided - it seems like this should be what other people tried to do as well.

How to configure files excluded from coverage statistics?

For reference, the versions of all the relevant gems that I use are as follows:

 rails (3.0.5) rake (0.8.7) rcov (0.9.9) rspec (2.5.0,) rspec-core (2.5.1) rspec-expectations (2.5.0,) rspec-mocks (2.5.0) rspec-rails (2.5.0) 
+4
source share
1 answer

From the RSpec Upgrade file:

In RSpec-1, the rake command will read the rcov parameters from the rcov.opts file. RSpec-2 is ignored. RCov parameters are now set directly on the rake. Task:

  RSpec::Core::RakeTask.new(:rcov) do |t| t.rcov_opts = %q[--exclude "spec"] end 

Checking the source code of rspec-rails , I found that the library defines the task :rcov and does not seem to exclude the rspec folder.

 desc "Run all specs with rcov" RSpec::Core::RakeTask.new(:rcov => spec_prereq) do |t| t.rcov = true t.pattern = "./spec/**/*_spec.rb" t.rcov_opts = '--exclude /gems/,/Library/,/usr/,lib/tasks,.bundle,config,/lib/rspec/,/lib/rspec-' end 

You can delete a task and recreate it with your own settings, or define a new task.

+6
source

Source: https://habr.com/ru/post/1344109/


All Articles