SimpleCov ignore some files (0%) when others are successfully covered (100%) with the same tests.
I run my tests with the framework's testing tools (Rails 5.1.4).
This is my test_helper.rb
file.
require 'simplecov'
# save to CircleCI's artifacts directory if we're on CircleCI
if ENV['CIRCLE_ARTIFACTS']
dir = File.join(ENV['CIRCLE_ARTIFACTS'], 'coverage')
SimpleCov.coverage_dir(dir)
end
SimpleCov.start 'rails'
ENV['RAILS_ENV'] ||= 'test'
require File.expand_path('../../config/environment', __FILE__)
require 'rails/test_help'
This is a file successfully covered (100%) by SimpleCov with a Connection.types
:
class Connection < ApplicationRecord
validates :type_of, inclusion: { in: proc { Connection.types.map(&:to_s) } }
TYPES = %i[
friend
industry
investor
].freeze
belongs_to :project
belongs_to :user
def self.types
TYPES
end
end
This is a file unsuccessfully covered (0%) by SimpleCov with Kpi.types
:
class Kpi < ApplicationRecord
REGEX = {
float: "^\d+(\.?\d)?$"
}.freeze
TYPES = [
{ id: :buyers, name: 'Number of buyers', unit: 'users', example: '1000', regex: :float },
{ id: :sellers, name: 'Number of sellers', unit: 'users', example: '1000', regex: :float },
].freeze
belongs_to :project
def self.types
TYPES
end
end
I don't see a pattern here... do you?
Ok, found the culprit: ActiveAdmin. Here is the answer for posterity :)
I added a filter:
SimpleCov.start 'rails' do
add_filter('/admin')
end
And it works fine now.