Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/56.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 禁用guard spec运行的代码覆盖率_Ruby On Rails_Rspec_Guard - Fatal编程技术网

Ruby on rails 禁用guard spec运行的代码覆盖率

Ruby on rails 禁用guard spec运行的代码覆盖率,ruby-on-rails,rspec,guard,Ruby On Rails,Rspec,Guard,出于各种原因,我发现每次从guard重新加载文件时运行代码覆盖率都是一个相当大的负担。但是,似乎没有一种方法可以有条件地阻止SimpleCov从spec助手启动 有没有一种方法可以在guard运行时禁用SimpleCov,但在我使用spec helper中的rake spec正常运行时却没有 unless ARGV.any? {|e| e =~ /guard-rspec/ } SimpleCov.start end 这里的想法是guard rspec使用一个特殊的guard rspec格式

出于各种原因,我发现每次从guard重新加载文件时运行代码覆盖率都是一个相当大的负担。但是,似乎没有一种方法可以有条件地阻止SimpleCov从spec助手启动

有没有一种方法可以在guard运行时禁用SimpleCov,但在我使用spec helper中的rake spec正常运行时却没有

unless ARGV.any? {|e| e =~ /guard-rspec/ }
  SimpleCov.start
end

这里的想法是guard rspec使用一个特殊的guard rspec格式化程序调用rspec。在给定的命令行中查找它会提示您它是从Guard调用的,因此您可以跳过SimpleCov(如果有)。

我最终找到了这个解决方案:

  • Guardfile
    中添加环境变量:

    guard:rspec,env:{'NO_COVERAGE'=>true'}

  • 从等级库辅助对象中检查它:

    unless ARGV.any? {|e| e =~ /guard-rspec/ }
      SimpleCov.start
    end
    
    SimpleCov.start:rails除非ENV[“无覆盖”]


  • 在VsCode中,我使用Ruby Spec命令:
    NO_COVERAGE=true bin/rspec
    在扩展
    Rails Run Spec


    也适用于命令行:
    NO\u COVERAGE=true bin/rspec spec/*\u spec.rb
    NO\u COVERAGE=true bundle exec rspec spec/*\u spec.rb

    现在不推荐使用
    env
    选项,将env var添加到
    cmd
    是现在推荐的解决方案,例如:
    guard:rspec,cmd:“NO\u COVERAGE=true bin/rspec”
    我使用SimpleCov gem