Last active
July 13, 2023 07:02
-
-
Save hiroki-uchida/5edaffdac67373534dc0fb323a889ecf to your computer and use it in GitHub Desktop.
並列処理にも対応したSimpleCovの設定
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # File: Gemfile | |
| # 追加 | |
| group :test do | |
| gem 'simplecov', require: false | |
| gem 'simplecov-csv', require: false # 任意 | |
| gem 'simplecov-json', require: false # 任意 | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # File: spec/support/simplecov.rb | |
| if ENV['COVERAGE'] | |
| require 'simplecov' | |
| require 'simplecov-csv' # simplecov-csv をインストールしている場合 | |
| require 'simplecov-json' # simplecov-json をインストールしている場合 | |
| SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new [ | |
| SimpleCov::Formatter::CSVFormatter, # simplecov-csv をインストールしている場合 | |
| SimpleCov::Formatter::JSONFormatter, # simplecov-json をインストールしている場合 | |
| SimpleCov::Formatter::HTMLFormatter | |
| ] | |
| # 並列処理では上手く機能しない | |
| # SimpleCov.minimum_coverage 90 | |
| SimpleCov.merge_timeout 3600 | |
| # 並列化してもカバレッジ計測できるように設定 | |
| SimpleCov.command_name "rspec_#{Process.pid}#{ENV['TEST_ENV_NUMBER']}" | |
| SimpleCov.start 'rails' do | |
| # 標準でフィルタリングされているファイルの中にカバレッジ対象にしたいファイルがある場合はこの方法でリセット | |
| filters.clear | |
| # 標準では `.rb` ファイルしか計測されないので | |
| # `.rake` などをトラッキング対象に追加する場合はこの方法で追加 | |
| track_files 'lib/**/*.rake' | |
| # 計測しないファイルをフィルタリング | |
| add_filter '/.bundle/' | |
| add_filter '/vendor/' | |
| add_filter '/rbenv/' | |
| add_filter '/.rbenv/' | |
| add_filter '/spec/' | |
| # viewファイルはトラッキングしても仕組み上 計測できないので除外 | |
| add_filter 'app/views/' | |
| # annotateの設定ファイルとしての役割しかないので除外 | |
| add_filter 'lib/tasks/auto_annotate_models.rake' | |
| # 出力されるHTMLにグループを追加 | |
| add_group 'Configurations', '/config/' | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # File: spec/spec_helper.rb | |
| # カバレッジ計測が正確に行うために、必ず行頭で読み込む。 | |
| require File.expand_path('../support/simplecov.rb', __FILE__) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment