From fb778d61f11768df49573d3efb8232a9f1757ea8 Mon Sep 17 00:00:00 2001 From: Lorenzo Farnararo <2814802+baldarn@users.noreply.github.com> Date: Sat, 14 Sep 2024 10:50:47 +0200 Subject: [PATCH] Add code coverage (#14) --- .github/workflows/ci.yml | 29 +---------------------------- .gitignore | 5 +++++ Gemfile | 1 + Gemfile.lock | 8 ++++++++ config/environments/test.rb | 2 +- {tmp/pids => coverage}/.keep | 0 test/test_helper.rb | 3 +++ 7 files changed, 19 insertions(+), 29 deletions(-) rename {tmp/pids => coverage}/.keep (100%) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ec824d3..1c436b2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -32,34 +32,7 @@ jobs: - name: Set up database schema run: bin/rails db:schema:load - name: Run tests - run: bin/rails test - - system-tests: - runs-on: ubuntu-latest - services: - postgres: - image: postgres:16.4-alpine - ports: - - "5432:5432" - env: - POSTGRES_DB: opengas_test - POSTGRES_USER: opengas - POSTGRES_PASSWORD: opengas - env: - RAILS_ENV: test - DATABASE_URL: "postgres://opengas:opengas@localhost:5432/opengas_test" - steps: - - name: Checkout code - uses: actions/checkout@v4 - - name: Install Ruby and gems - uses: ruby/setup-ruby@v1 - with: - ruby-version: 3.3.5 - bundler-cache: true - - name: Set up database schema - run: bin/rails db:schema:load - - name: Run tests - run: bin/rails test:system + run: bin/rails test:all lint: runs-on: ubuntu-latest diff --git a/.gitignore b/.gitignore index 3b4329e..799c684 100644 --- a/.gitignore +++ b/.gitignore @@ -38,4 +38,9 @@ /app/assets/builds/* !/app/assets/builds/.keep +# coverage +/coverage/* +!/coverage +!/coverage/.keep + .DS_Store diff --git a/Gemfile b/Gemfile index 0cc754a..061ab9b 100644 --- a/Gemfile +++ b/Gemfile @@ -83,4 +83,5 @@ end group :test do gem 'capybara' gem 'selenium-webdriver' + gem 'simplecov', require: false end diff --git a/Gemfile.lock b/Gemfile.lock index deaf2ba..35e17d2 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -148,6 +148,7 @@ GEM warden (~> 1.2.3) devise-i18n (1.12.1) devise (>= 4.9.0) + docile (1.4.1) dotenv (2.8.1) dotenv-rails (2.8.1) dotenv (= 2.8.1) @@ -419,6 +420,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) solid_queue (0.5.0) activejob (>= 7.1) activerecord (>= 7.1) @@ -539,6 +546,7 @@ DEPENDENCIES selenium-webdriver simple_calendar simple_form (~> 5.3) + simplecov solid_queue (~> 0.5.0) sprockets-rails sqlite3 (~> 1.4) diff --git a/config/environments/test.rb b/config/environments/test.rb index 268bb31..bcec91f 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -17,7 +17,7 @@ # this is usually not necessary, and can slow down your test suite. However, it's # recommended that you enable it in continuous integration systems to ensure eager # loading is working properly before deploying your code. - config.eager_load = ENV['CI'].present? + config.eager_load = true # Configure public file server for tests with Cache-Control for performance. config.public_file_server.headers = { 'Cache-Control' => "public, max-age=#{1.hour.to_i}" } diff --git a/tmp/pids/.keep b/coverage/.keep similarity index 100% rename from tmp/pids/.keep rename to coverage/.keep diff --git a/test/test_helper.rb b/test/test_helper.rb index 3e74cf5..08fd581 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -1,5 +1,8 @@ # frozen_string_literal: true +require 'simplecov' +SimpleCov.start + ENV['RAILS_ENV'] ||= 'test' require_relative '../config/environment' require 'rails/test_help'