From d002e0c12bfdbc8c4fc90098d52efe4801b7da78 Mon Sep 17 00:00:00 2001 From: jacky Date: Sun, 27 Oct 2024 15:09:12 +0700 Subject: [PATCH] feat: add simplecov --- .gitignore | 4 +++ Gemfile | 2 ++ Gemfile.lock | 13 ++++++++++ spec/rails_helper.rb | 62 ++++++++++++-------------------------------- 4 files changed, 35 insertions(+), 46 deletions(-) diff --git a/.gitignore b/.gitignore index 72a873b..da20712 100644 --- a/.gitignore +++ b/.gitignore @@ -51,4 +51,8 @@ node_modules !/.env.sample config/database.yml +# Ignore husky /.husky + +# Ignore coverage +coverage/**/* diff --git a/Gemfile b/Gemfile index 729f063..d4383c2 100644 --- a/Gemfile +++ b/Gemfile @@ -81,4 +81,6 @@ group :test do gem 'shoulda-matchers' gem 'vcr' gem 'webmock' + gem 'simplecov', require: false + gem 'rails-controller-testing' end diff --git a/Gemfile.lock b/Gemfile.lock index bcc3bb5..12e8fec 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -127,6 +127,7 @@ GEM responders warden (~> 1.2.3) diff-lcs (1.5.1) + docile (1.4.1) dotenv (3.1.4) drb (2.2.1) dry-cli (1.2.0) @@ -327,6 +328,10 @@ GEM activesupport (= 7.2.1.1) bundler (>= 1.15.0) railties (= 7.2.1.1) + rails-controller-testing (1.0.5) + actionpack (>= 5.0.1.rc1) + actionview (>= 5.0.1.rc1) + activesupport (>= 5.0.1.rc1) rails-dom-testing (2.2.0) activesupport (>= 5.0.0) minitest @@ -445,6 +450,12 @@ GEM simple_form (5.3.1) actionpack (>= 5.2) activemodel (>= 5.2) + simplecov (0.22.0) + docile (~> 1.1) + simplecov-html (~> 0.11) + simplecov_json_formatter (~> 0.1) + simplecov-html (0.13.1) + simplecov_json_formatter (0.1.4) slim (5.2.1) temple (~> 0.10.0) tilt (>= 2.1.0) @@ -556,6 +567,7 @@ DEPENDENCIES puma (>= 5.0) pundit (~> 2.4) rails (~> 7.2.0) + rails-controller-testing rails-mermaid_erd redis (>= 4.0.1) rolify @@ -574,6 +586,7 @@ DEPENDENCIES sidekiq-scheduler sidekiq-unique-jobs simple_form + simplecov slim-rails (~> 3.6, >= 3.6.3) stackprof stimulus-rails diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index e16a62a..64b57e5 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -1,36 +1,32 @@ # frozen_string_literal: true -# This file is copied to spec/ when you run 'rails generate rspec:install' +require 'simplecov' +SimpleCov.start do + add_filter 'config/' + add_filter 'spec/' + add_group 'Models', 'app/models' + add_group 'Controllers', 'app/controllers' + add_group 'Jobs', 'app/jobs' + add_group 'Mailers', 'app/mailers' + add_group 'Serializers', 'app/serializers' + add_group 'Services', 'app/services' + add_group 'Policies', 'app/policies' +end + require 'spec_helper' ENV['RAILS_ENV'] ||= 'test' require_relative '../config/environment' -# Prevent database truncation if the environment is production + abort('The Rails environment is running in production mode!') if Rails.env.production? require 'rspec/rails' -# Add additional requires below this line. Rails is not loaded until this point! +require 'faker' -# Requires supporting ruby files with custom matchers and macros, etc, in -# spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are -# run as spec files by default. This means that files in spec/support that end -# in _spec.rb will both be required and run as specs, causing the specs to be -# run twice. It is recommended that you do not name files matching this glob to -# end with _spec.rb. You can configure this pattern with the --pattern -# option on the command line or in ~/.rspec, .rspec or `.rspec-local`. -# -# The following line is provided for convenience purposes. It has the downside -# of increasing the boot-up time by auto-requiring all files in the support -# directory. Alternatively, in the individual `*_spec.rb` files, manually -# require only the support files necessary. -# -# Rails.root.glob('spec/support/**/*.rb').sort.each { |f| require f } - -# Checks for pending migrations and applies them before tests are run. -# If you are not using ActiveRecord, you can remove these lines. begin ActiveRecord::Migration.maintain_test_schema! rescue ActiveRecord::PendingMigrationError => e abort e.to_s.strip end + RSpec.configure do |config| config.include ViewComponent::TestHelpers, type: :view_component config.include Capybara::RSpecMatchers, type: :view_component @@ -39,36 +35,10 @@ metadata[:type] = :view_component end - # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures config.fixture_paths = [ Rails.root.join('spec/fixtures') ] - - # If you're not using ActiveRecord, or you'd prefer not to run each of your - # examples within a transaction, remove the following line or assign false - # instead of true. config.use_transactional_fixtures = true - - # You can uncomment this line to turn off ActiveRecord support entirely. - # config.use_active_record = false - - # RSpec Rails can automatically mix in different behaviours to your tests - # based on their file location, for example enabling you to call `get` and - # `post` in specs under `spec/controllers`. - # - # You can disable this behaviour by removing the line below, and instead - # explicitly tag your specs with their type, e.g.: - # - # RSpec.describe UsersController, type: :controller do - # # ... - # end - # - # The different available types are documented in the features, such as in - # https://rspec.info/features/6-0/rspec-rails config.infer_spec_type_from_file_location! - - # Filter lines from Rails gems in backtraces. config.filter_rails_from_backtrace! - # arbitrary gems may also be filtered via: - # config.filter_gems_from_backtrace("gem name") end