Disabling code coverage for security features

For various reasons, I find that when I run the contents of the code every time my files are reloaded with protection, this is a pretty heavy burden. However, there seems to be no way to conditionally prevent SimpleCov from starting with the spec helper.

Is there a way to disable SimpleCov when starting with protection, but not when I start it with rake spec ?

+8
ruby-on-rails rspec guard
source share
2 answers

I eventually found this solution:

  • Add the environment variable to the Guardfile :

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

  • Check it out with the spec helper:

    SimpleCov.start :rails unless ENV["NO_COVERAGE"]

+12
source share

In your spec helper:

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

The idea here is that guard-rspec calls rspec with special guard-rspec formatting. Searching for this in the given command line gives you a hint that it has been called from Guard, so you can just skip SimpleCov if it is there.

+4
source share

All Articles