Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disabling code coverage for guard spec runs

For a variety of reasons, I find that running code coverage every time my files reload from guard is quite a burden. However, there doesn't seem to be a way to conditionally prevent SimpleCov from starting from the spec helper.

Is there a way to disable SimpleCov when run by guard, but not when I run it normally using rake spec?

like image 806
Casey Chow Avatar asked Jul 18 '13 02:07

Casey Chow


2 Answers

I ultimately found this solution:

  1. Add an environment variable in your Guardfile:

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

  2. Check for it from the spec helper:

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

like image 101
Casey Chow Avatar answered Nov 03 '22 08:11

Casey Chow


In your spec helper:

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

The idea here is that guard-rspec invokes rspec with a special guard-rspec formatter. Looking for that on the command line given gives you the hint that it was invoked from Guard, so you can just skip SimpleCov if that's there.

like image 40
Chris Heald Avatar answered Nov 03 '22 10:11

Chris Heald