简体   繁体   English

Rails 4和SimpleCov:SimpleCov的覆盖率报告中包含lib / tasks / cucumber.rake吗?

[英]Rails 4 & SimpleCov: lib/tasks/cucumber.rake included in coverage report for SimpleCov?

I have the following code at the top of spec/spec_helper.rb and features/support/env.rb (SimpleCov merging RSpec & Cucumber coverage results): 我在spec/spec_helper.rbfeatures/support/env.rb的顶部具有以下代码(SimpleCov合并RSpec和Cucumber覆盖结果):

require 'simplecov'

I also have the following code in a .simplecov file in the project root: 我在项目根目录的.simplecov文件中也包含以下代码:

SimpleCov.start 'rails'

However, for some reason, lib/tasks/cucumber.rake is included in the coverage... 但是,由于某种原因, lib/tasks/cucumber.rake包含在本文中...

在此处输入图片说明

Any ideas? 有任何想法吗?

In spec folder there is file rcov.opts, in this file we have –exclude option. 在spec文件夹中有文件rcov.opts,在此文件中,我们有–exclude选项。

We can append our path of files to this. 我们可以将文件路径附加到此。 for example i want to exclude helpers , sweepers folders, so just add/modify 例如我想排除helpers,sweepers文件夹,所以只需添加/修改

–exclude “helpers/*,app/sweepers/*”. 

In RSpec-1, the rake task would read in rcov options from an rcov.opts file. 在RSpec-1中,rake任务将从rcov.opts文件中读取rcov选项。

This is ignored by RSpec-2. RSpec-2忽略了这一点。 RCov options are now set directly on the Rake task: 现在,可以直接在Rake任务上设置RCov选项:

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

I haven't used SimpleCov with RSpec before, but typically I would handle this type of scenario by adding a filter to SimpleCov after calling start. 我以前没有在RSpec中使用SimpleCov,但是通常我会通过在调用start之后向SimpleCov添加一个过滤器来处理这种情况。 In your case it might mean changing the start call in .simplecov from 在您的情况下,这可能意味着更改.simplecov的开始调用

SimpleCov.start "rails"

to

SimpleCov.start("rails") do
  add_filter "lib/tasks/cucumber.rake"
end

Hope this helps! 希望这可以帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM