使用 RSpec 2.5 运行 rcov 时跳过 spec/ 中的文件
当为 Rails 3 应用程序运行 rake spec:rcov
时,spec/
目录中的文件将包含在覆盖率统计信息中,但我不希望它们被包含在。我只需要我的实际应用程序的覆盖率统计数据。
在旧版本的 RSpec 中,可以使用 spec/rcov.opts
文件中的行 --exclude "spec/*"
进行自定义,但似乎该文件Rspec 2 不再读取。自从 spec/spec.opts
更改为 .rspec
后,我尝试创建一个 .rcov
文件,但这并没有也读不到。
我找到了一些关于如何在定义 rake 任务时执行此操作的文档,但我不想覆盖提供的 rake 任务 - 看起来这一定是其他人也尝试过做的事情。
如何自定义从覆盖率统计中排除的文件?
作为参考,我正在使用的所有相关 gem 的版本是:
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)
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 either.
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)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
从 RSpec 升级文件:
检查 rspec-rails 源代码我发现该库定义了 :rcov 任务,并且它似乎没有排除 rspec 文件夹。
您可能想要删除任务并使用自己的设置重新创建它或定义新任务。
From the RSpec Upgrade file:
Inspecting the
rspec-rails
source code I found the library defines the:rcov
task and it doesn't seem to exclude the rspec folder.You might want to remove the task and recreate it with your own settings or define a new task.