Ruby on rails 禁用guard spec运行的代码覆盖率
出于各种原因,我发现每次从guard重新加载文件时运行代码覆盖率都是一个相当大的负担。但是,似乎没有一种方法可以有条件地阻止SimpleCov从spec助手启动 有没有一种方法可以在guard运行时禁用SimpleCov,但在我使用spec helper中的rake 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格式
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