Skip to content

Commit

Permalink
tests: fix test coverage reporting for parallel testing.
Browse files Browse the repository at this point in the history
* Fix simplecov clobbering test coverage reports when using parallel tests.
* Generate coverage reports by default (remove $SIMPLECOV flag).
* Store coverage reports in tmp/coverage/ instead of coverage/.
* Enable branch coverage.

ref: github.com /simplecov-ruby/simplecov/issues/718#issuecomment-538201587
  • Loading branch information
evazion committed Jun 11, 2020
1 parent 99a9149 commit a829fbf
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ config/database.yml
config/danbooru_local_config.rb
config/deploy/*.rb
config/newrelic.yml
coverage/
node_modules/
log/
tmp/
Expand Down
6 changes: 6 additions & 0 deletions .simplecov
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
SimpleCov.start "rails" do
add_group "Libraries", ["app/logical", "lib"]
add_group "Presenters", "app/presenters"
enable_coverage :branch
coverage_dir "tmp/coverage"
end
17 changes: 8 additions & 9 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
ENV["RAILS_ENV"] = "test"

if ENV["SIMPLECOV"]
require 'simplecov'
SimpleCov.start 'rails' do
add_group "Libraries", ["app/logical", "lib"]
add_group "Presenters", "app/presenters"
end
end

require 'simplecov'
require File.expand_path('../config/environment', __dir__)
require 'rails/test_help'
require 'cache'
Expand Down Expand Up @@ -48,8 +41,14 @@ class ActiveSupport::TestCase
mock_pool_version_service!

parallelize
parallelize_setup do
parallelize_setup do |worker|
Rails.application.load_seed

SimpleCov.command_name "#{SimpleCov.command_name}-#{worker}"
end

parallelize_teardown do |worker|
SimpleCov.result
end

setup do
Expand Down

0 comments on commit a829fbf

Please sign in to comment.