Last Updated: February 25, 2016
· tlrdstd

SimpleCov and Cucumber

SimpleCov is a great Ruby coverage profiler for Ruby 1.9. But you don't always want it to run on every test run. (It slows down my test suite by nearly 20%.)

The official docs suggest conditionally activating SimpleCov like this:

SimpleCov.start if ENV["COVERAGE"]

and running it like this:

COVERAGE=true rake test

If you think you're clever, you might want to rename that variable to ENV['SIMPLECOV']. Problem is, the folks who wrote the Cucumber gem are also pretty clever:

  require 'simplecov'

  SimpleCov.start do

So, if you name your SimpleCov environment variable to ENV['SIMPLECOV'] and then run Cucumber tests, the Cucumber gem will hijack your SimpleCov setup and eat your lunch.

If you're still too clever to use ENV['COVERAGE'] in your app, try ENV['SIMPLE_COV'] instead.