diff --git a/Gemfile b/Gemfile index 303e6b6b..f43276a6 100644 --- a/Gemfile +++ b/Gemfile @@ -120,8 +120,7 @@ group :test do gem 'rspec-retry' gem 'selenium-webdriver' gem 'shoulda-matchers', '~> 8.0' - gem 'simplecov', '~> 0.22.0', require: false - gem 'simplecov_json_formatter' + gem 'simplecov', '~> 1.0.1', require: false gem 'timecop' gem 'webmock' end diff --git a/Gemfile.lock b/Gemfile.lock index 29f2523a..7b1191c5 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -174,7 +174,6 @@ GEM irb (~> 1.10) reline (>= 0.3.8) diff-lcs (1.6.2) - docile (1.4.1) domain_name (0.6.20240107) dotenv (3.2.0) dotenv-rails (3.2.0) @@ -539,12 +538,7 @@ GEM shellany (0.0.1) shoulda-matchers (8.0.1) activesupport (>= 7.2) - simplecov (0.22.0) - docile (~> 1.1) - simplecov-html (~> 0.11) - simplecov_json_formatter (~> 0.1) - simplecov-html (0.13.2) - simplecov_json_formatter (0.1.4) + simplecov (1.0.1) simpleidn (0.2.3) snaky_hash (2.0.3) hashie (>= 0.1.0, < 6) @@ -663,8 +657,7 @@ DEPENDENCIES sentry-rails sentry-ruby shoulda-matchers (~> 8.0) - simplecov (~> 0.22.0) - simplecov_json_formatter + simplecov (~> 1.0.1) sprockets-rails stimulus-rails strong_migrations diff --git a/config/simplecov.rb b/config/simplecov.rb new file mode 100644 index 00000000..9272e8fc --- /dev/null +++ b/config/simplecov.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +# Shared SimpleCov configuration used by both test suites so their coverage +# setup never drifts: +# * RSpec -> required from spec/spec_helper.rb +# * Cucumber -> required from features/support/env.rb +# +# This must be required before any application code loads so SimpleCov can hook +# into Coverage. As of SimpleCov 1.0 the JSON formatter is bundled with the gem +# (the standalone simplecov_json_formatter gem is no longer needed), and calling +# SimpleCov.start more than once in a process is a no-op rather than an error. +require 'simplecov' + +SimpleCov.start 'rails' do + formatter SimpleCov::Formatter::MultiFormatter.new( + [ + SimpleCov::Formatter::HTMLFormatter, + SimpleCov::Formatter::JSONFormatter + ] + ) +end diff --git a/features/support/env.rb b/features/support/env.rb index d15cf509..c6b820b4 100644 --- a/features/support/env.rb +++ b/features/support/env.rb @@ -3,20 +3,9 @@ # Database Cleaner configuration is loaded in features/support/database_cleaner.rb -# Configure SimpleCov before requiring other files -require 'simplecov' -require 'simplecov_json_formatter' - -# Only start SimpleCov if it hasn't been started -unless SimpleCov.running - SimpleCov.start 'rails' do - track_files 'app/**/*.rb' - formatter SimpleCov::Formatter::MultiFormatter.new([ - SimpleCov::Formatter::HTMLFormatter, - SimpleCov::Formatter::JSONFormatter - ]) - end -end +# Start SimpleCov coverage reporting before requiring any application code. +# The configuration is shared with the RSpec suite (see config/simplecov.rb). +require_relative '../../config/simplecov' require 'cucumber/rails' require 'rspec/mocks' diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 21fc7fed..2e403a42 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -17,17 +17,10 @@ # See https://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration # require 'codeclimate-test-reporter' -require 'simplecov' -require 'simplecov_json_formatter' -SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new([ - SimpleCov::Formatter::HTMLFormatter, - SimpleCov::Formatter::JSONFormatter - ]) - -SimpleCov.start 'rails' do - # add_filter '/app/controllers/api' - # add_filter '/app/controllers/bcourses_controller.rb' -end +# Shared SimpleCov configuration (see config/simplecov.rb) so the RSpec and +# Cucumber suites stay in sync. Add project-wide coverage filters there, e.g.: +# skip '/app/controllers/api' +require_relative '../config/simplecov' # load libraries from lib $LOAD_PATH.unshift(File.expand_path('../lib', __dir__))