How to add SimpleCov code coverage to Rails project.
Recently I added code coverage tool to Rails project to keep track of test coverage.
First, add simplecov gem to Gemfile then add following to spec_helper.rb, rails_helper.rb or test_helper.rb
require "simplecov"
SimpleCov.start "rails" do
enable_coverage :branch
add_group "ViewComponents", "app/components"
add_group "Queries", "app/queries"
add_group "Serializers", "app/serializers"
add_group "Services", "app/services"
add_group "Gateways", "app/gateways"
add_group "Presenters", "app/presenters"
add_group "Validators", "app/validators"
end
Above shows how one can organize report in groups.
In addition, enable_coverage :branch will show what code branches are not covered by tests.
More information can be found at simplecov
Thanks for reading!