diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c3a91f2..f4dfc48 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -6,10 +6,6 @@ on: pull_request: branches: [ main ] -env: - BUNDLE_WITHOUT: "development" - JRUBY_OPTS: "--dev --debug" - jobs: test: name: "rspec (ruby:${{ matrix.ruby }})" @@ -40,8 +36,37 @@ jobs: ruby-version: ${{ matrix.ruby }} bundler-cache: true - - name: RSpec - run: scripts/ci-rspec + - run: bundle exec rake test + + - name: "Upload coverage results" + uses: actions/upload-artifact@v3 + with: + name: coverage-${{ matrix.ruby }} + path: coverage/.resultset.json + + test-coverage: + runs-on: ubuntu-latest + needs: test + + steps: + - uses: actions/checkout@v4 + + - uses: ruby/setup-ruby@v1 + with: + ruby-version: ruby-3.2 + bundler-cache: true + + - name: "Download coverage results" + uses: actions/download-artifact@v3 + with: + path: coverage + + - run: bundle exec rake test:coverage + + - name: Upload coverage reports to Codecov + uses: codecov/codecov-action@v3 + env: + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} lint: runs-on: ubuntu-latest @@ -54,5 +79,4 @@ jobs: ruby-version: ruby-3.2 bundler-cache: true - - name: Rubocop - run: bundle exec rubocop --format progress --color + - run: bundle exec rake lint diff --git a/.rspec b/.rspec index c99d2e7..283edea 100644 --- a/.rspec +++ b/.rspec @@ -1 +1,2 @@ +--require simplecov --require spec_helper diff --git a/.simplecov b/.simplecov new file mode 100644 index 0000000..b80209d --- /dev/null +++ b/.simplecov @@ -0,0 +1,24 @@ +# frozen_string_literal: true + +SimpleCov.start do + gemfile = File.basename(ENV.fetch("BUNDLE_GEMFILE", "Gemfile"), ".gemfile").strip + gemfile = nil if gemfile.empty? || gemfile.casecmp?("gems.rb") || gemfile.casecmp?("Gemfile") + + command_name ["#{RUBY_ENGINE}-#{RUBY_ENGINE_VERSION}", gemfile].compact.join("/") + + enable_coverage :branch + + if ENV["CI"] + formatter SimpleCov::Formatter::SimpleFormatter + else + formatter SimpleCov::Formatter::MultiFormatter.new([ + SimpleCov::Formatter::SimpleFormatter, + SimpleCov::Formatter::HTMLFormatter + ]) + end + + add_filter "/demo/" + add_filter "/gemfiles/" + add_filter "/spec/" + add_filter "/vendor/" +end diff --git a/Gemfile b/Gemfile index 690275a..ad09f96 100644 --- a/Gemfile +++ b/Gemfile @@ -16,7 +16,9 @@ group :test do gem "rspec" gem "rspec-parameterized" + gem "simplecov" + gem "simplecov-cobertura" gem "rubocop", require: false gem "rubocop-capybara", require: false diff --git a/Rakefile b/Rakefile index ba00716..c5191e6 100644 --- a/Rakefile +++ b/Rakefile @@ -1,9 +1,46 @@ # frozen_string_literal: true -require "appraisal" require "bundler/gem_tasks" -require "rspec/core/rake_task" -RSpec::Core::RakeTask.new +desc "Run tests" +task :test do + rm_rf "coverage" + rm_rf "gemfiles" -task default: ENV["APPRAISAL_INITIALIZED"] ? %i[spec] : %i[appraisal rubocop] + Bundler.with_unbundled_env do + sh "bundle exec appraisal generate" + + # XXX: `bundle exec appraisal install` fails on ruby-3.2 + Dir["gemfiles/*.gemfile"].each do |gemfile| + sh({ "BUNDLE_GEMFILE" => gemfile }, "bundle lock") + sh({ "BUNDLE_GEMFILE" => gemfile }, "bundle check") do |ok| + sh({ "BUNDLE_GEMFILE" => gemfile }, "bundle install") unless ok + end + end + + sh "bundle exec appraisal rspec --force-colour" + end +end + +namespace :test do + desc "Generate test coverage report" + task :coverage do + require "simplecov" + + SimpleCov.collate Dir["coverage/**/.resultset.json"] do + if ENV["CI"] + require "simplecov-cobertura" + formatter SimpleCov::Formatter::CoberturaFormatter + else + formatter SimpleCov::Formatter::HTMLFormatter + end + end + end +end + +desc "Lint codebase" +task :lint do + sh "bundle exec rubocop --color" +end + +task default: %i[test lint] diff --git a/rubocop/layout.yml b/rubocop/layout.yml index 76bc629..6e5c7f1 100644 --- a/rubocop/layout.yml +++ b/rubocop/layout.yml @@ -1,6 +1,14 @@ +Layout/ArgumentAlignment: + Enabled: true + EnforcedStyle: with_fixed_indentation + Layout/EmptyLinesAroundAttributeAccessor: Enabled: true +Layout/FirstArrayElementIndentation: + Enabled: true + EnforcedStyle: consistent + Layout/FirstHashElementIndentation: Enabled: true EnforcedStyle: consistent diff --git a/rubocop/rspec.yml b/rubocop/rspec.yml index c129a66..182e2e4 100644 --- a/rubocop/rspec.yml +++ b/rubocop/rspec.yml @@ -7,3 +7,7 @@ RSpec/MultipleExpectations: RSpec/NamedSubject: Enabled: false + +RSpec/BeNil: + Enabled: true + EnforcedStyle: be diff --git a/rubocop/style.yml b/rubocop/style.yml index 18f14c2..3a7e90f 100644 --- a/rubocop/style.yml +++ b/rubocop/style.yml @@ -67,7 +67,7 @@ Style/RegexpLiteral: Style/RescueStandardError: Enabled: true - EnforcedStyle: implicit + EnforcedStyle: explicit Style/SingleArgumentDig: Enabled: true diff --git a/scripts/ci-rspec b/scripts/ci-rspec deleted file mode 100755 index 1aedbca..0000000 --- a/scripts/ci-rspec +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/env bash - -set -Eeuxo pipefail - -rm -f ./Gemfile.lock -bundle install - -rm -f ./gemfiles/*.gemfile ./gemfiles/*.gemfile.lock -bundle exec appraisal generate - -# XXX: `bundle exec appraisal install` fails on CI with ruby-3.2 -for BUNDLE_GEMFILE in gemfiles/*.gemfile; do - export BUNDLE_GEMFILE - bundle check || bundle install -done - -bundle exec appraisal rspec diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index a005712..4fc3cb1 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,6 +1,5 @@ # frozen_string_literal: true -require_relative "support/simplecov" if ENV["CI"] || ENV["COVERAGE"] require_relative "support/sidekiq" require "rspec-parameterized" diff --git a/spec/support/simplecov.rb b/spec/support/simplecov.rb deleted file mode 100644 index ca4f6f6..0000000 --- a/spec/support/simplecov.rb +++ /dev/null @@ -1,13 +0,0 @@ -# frozen_string_literal: true - -require "simplecov" - -SimpleCov.start do - command_name "BUNDLE_GEMFILE=#{ENV.fetch('BUNDLE_GEMFILE')}" - - enable_coverage :branch - - add_filter "/gemfiles/" - add_filter "/spec/" - add_filter "/vendor/" -end