Search code examples
ruby-on-railsrspecguard

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?


Solution

  • 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"]