Make Spring & SimpleCov play nice
Want to achieve spring-ified bliss for your rails-rspec-guard setup? Read on.
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:
if ENV['RAILS_ENV'] == 'test'
require 'simplecov'
SimpleCov.start
end
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.
You might also be interested in these articles...
Startup Founder | Engineering Leader with an MBA