【问题标题】:Rails 4 & SimpleCov: lib/tasks/cucumber.rake included in coverage report for SimpleCov?Rails 4 和 SimpleCov:lib/tasks/cucumber.rake 包含在 SimpleCov 的覆盖率报告中吗?
【发布时间】:2015-03-13 07:42:00
【问题描述】:

我在spec/spec_helper.rb 和features/support/env.rb 的顶部有以下代码(SimpleCov 合并RSpec & Cucumber 覆盖结果):

require 'simplecov'

我在项目根目录的.simplecov 文件中也有以下代码:

SimpleCov.start 'rails'

但是,出于某种原因,lib/tasks/cucumber.rake 包含在报道中...

有什么想法吗?

【问题讨论】:

  • 在spec文件夹中有rcov.opts文件,在这个文件中我们有--exclude选项。我们可以将我们的文件路径附加到此。例如,我想排除 helpers、sweepers 文件夹,所以只需添加/修改 –exclude “helpers/*,app/sweepers/*”。在 RSpec-1 中,rake 任务将从 rcov.opts 文件中读取 rcov 选项。 RSpec-2 忽略了这一点。 RCov 选项现在直接在 Rake 任务上设置: RSpec::Core::RakeTask.new(:rcov) do |t| t.rcov_opts = %q[--exclude "spec/,gems/,features/*"] end

标签: ruby-on-rails simplecov


【解决方案1】:

在 spec 文件夹中有文件 rcov.opts,在这个文件中我们有 –exclude 选项。

我们可以将我们的文件路径附加到这里。 例如我想排除 helpers、sweepers 文件夹,所以只需添加/修改

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

在 RSpec-1 中,rake 任务将从 rcov.opts 文件中读取 rcov 选项。

这被 RSpec-2 忽略。 RCov 选项现在直接在 Rake 任务上设置:

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

【讨论】:

    【解决方案2】:

    我之前没有将 SimpleCov 与 RSpec 一起使用,但通常我会通过在调用 start 后向 SimpleCov 添加过滤器来处理这种类型的场景。在您的情况下,这可能意味着将.simplecov 中的开始调用从

    SimpleCov.start "rails"
    

    到

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

    希望这会有所帮助!

    【讨论】:

    • 我试过了,但它不起作用。 :( - 我在我的项目中使用 Cucumber 和 TestUnit,但 simplecov 报告覆盖率为 0.0%。
    • @etagwerker,您的项目是否在我可以查看的公共仓库中?
    • 不,但我在simplecov 中创建了一个问题:github.com/colszowka/simplecov/issues/587
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-09-27
    • 2017-06-22
    • 1970-01-01
    • 2012-12-03
    • 1970-01-01
    • 2019-01-19
    相关资源
    最近更新 更多