Make Spring & SimpleCov play nice

Background

Spring, the app preloader that's integrated with Rails 4.1+, and SimpleCov, everyone's favorite test coverage analyzer don't seem to play nice. The symptoms are differing results when you run rspec with and without Spring. The Spring results will skip many files because of eager loading; SimpleCov doesn't get loaded before your app does.

The Solution

Create a config/spring.rb file and move your SimpleCov config into it from your spec_helper.rb file. For example:

ifENV['RAILS_ENV']=='test'require'simplecov'SimpleCov.startend

Update

I've essentially given up on Spring. Despite this fix, coverage reporting is inconsistent, and often lower when running tests with Spring. See here for more discussion. None of the proposed fixes in that discussion have worked for me.