SimpleCov calculate 0% coverage for user model

It happens with me only when I use spring, actually when I use rspec binstub generated by spring-commands-rspec gem. Try to stop spring with command spring stop and run specs again with rspec spec.


I have a similar issue. I have the current simplecov 0.17.1.

I'm using Rails 6 with the default setup (Minitest and Spring, no rspec), I run my tests with rails test.

I have try all the other answers without success.

simplecov may be buggy: https://github.com/colszowka/simplecov/issues/671

I'm trying alternative like fastcov

edit1
fastcov seems to be a ligthen copy of simplecov, not mature at all. It's not released yet! Is their any alternative to simplecov?!

edit2
I manage to make it work by adding to the top of bin/rails

#!/usr/bin/env ruby
if ENV['RAILS_ENV'] == 'test'
  require 'simplecov'
  SimpleCov.start 'rails'
  puts "required simplecov"
end
# ...

AND in test_helper.rb, I set parallelize(workers: 1)

# test/test_helper.rb
require 'simplecov'
SimpleCov.start 'rails'

ENV['RAILS_ENV'] ||= 'test'
require_relative '../config/environment'
require 'rails/test_help'

class ActiveSupport::TestCase
  parallelize(workers: 1)
  fixtures :all
end

I run tests with the command RAILS_ENV=test rails test


Make sure that you are starting SimpleCov correctly. In your case,

Load and launch SimpleCov at the very top of your rails_helper.rb

See more: https://github.com/colszowka/simplecov#getting-started


You have to create an initilizer like this:

config/initializers/simplecov.rb

if ENV['RAILS_ENV'] == 'test'
  require 'simplecov'
  SimpleCov.start 'rails'
  puts "required simplecov"
end