开发者

Skipping files in spec/ when running rcov with RSpec 2.5

When running rake spec:rcov for a Rails 3 application, the files in the spec/ directory are getting included in 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 customize this with a spec/rcov.opts file with the line --exclude "spec/*" but it seems that file is no longer read by Rspec 2. I tried creating a .rcov file since spec/spec.opts changed to .rspec, but that didn't get read eit开发者_StackOverflow社区her.

I've found some documentation on how to do this when defining a rake task, but I'd rather not overwrite the provided rake task — it seems like this must be something other people have tried to do as well.

How can I customize the files that are excluded from coverage statistics?

For reference, the versions of all relevant gems I'm using are:

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)


From the RSpec Upgrade file:

In RSpec-1, the rake task would read in rcov options from an rcov.opts file. This is ignored by RSpec-2. RCov options are now set directly on the Rake task:

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

Inspecting the rspec-rails source code I found the library defines the :rcov task and it doesn't 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 might want to remove the task and recreate it with your own settings or define a new task.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜