Uruchomienie testów w CI\CD w aplikacji pisanej z Rails 6[SOLVED]

Cześć.

Postanowiłem sobie przypomnieć Railsy i chciałem skonfigurować sobie w moim projekcie CI\CD GitLaba, aby robiło za mnie cześć roboty. Niestety napotkałem problem z uruchamianiem testów. Mianowicie znalazłem informacje, że modne teraz jest Minitest (https://guides.rubyonrails.org/testing.html#rails-meets-minitest) a RSpec już jest passe. Nie stanowi to problemu lokalnie ponieważ zawsze mogę sobie testy uruchomić komendami rails test lub bundle exec rake test. Pierwsza z nich nie działa mi w CI\CD, a druga powinna mi generować coverage i raport w stylu junit. Do tego celu zaopatrzyłem projekt w simplecov i minitest-junit. Niestety nie wykonanie bundle exec test --junit informuje mnie, że flaga ta nie jest odpowiednia.
Poniżej prezentuje moje ustawienia CI\CD gitlaba, Gemfile, test_helper.rb

.gitlab-ci.yml

stages:
  - build
  - test
  - deploy

.base:
  image: ruby:2.6.6
  before_script:
	- gem install rake bundler --no-document
	- bundle config set with 'development test'
	- bundle install --no-deployment --jobs $(nproc)
	- apt-get update -qy
	- apt-get install -y nodejs

.base_db:
  extends: .base
  before_script:
	- export APT_CACHE_DIR=`pwd`/apt-cache && mkdir -pv $APT_CACHE_DIR
	- apt-get update -qq && apt-get install -yqq nodejs npm graphviz
	- node -v && npm -v
	- npm install -g yarn
	- yarn install --check-files
	- yarn config set cache-folder .yarn
	- gem install rake bundler --no-document
	- bundle config set with 'development test'
	- bundle install --no-deployment --jobs $(nproc) --path=vendor
	- bundle exec rake db:setup

build:rubocop:
  extends: .base
  stage: build
  script:
	- bundle exec rubocop

build:assets_precompile:
  extends: .base_db
  stage: build
  script:
	- bundle exec rake assets:precompile

# test:bundle_audit:
#   extends: .base
#   allow_failure: true
#   script:
#     - bundle exec bundle audit check --update

test:brakeman:
  extends: .base
  stage: test
  allow_failure: true
  artifacts:
	name: brakeman_report
	when: always
	paths:
	  - brakeman/
  only:
	- master
  script:
	- bundle exec brakeman --format html -o brakeman/index.html

test:dawnscanner:
  extends: .base
  stage: test
  allow_failure: true
  artifacts:
	name: dawnscanner_report
	when: always
	paths:
	  - dawnscanner/
  only:
	- master
  script:
	- mkdir dawnscanner
	- bundle exec dawn --html -zF dawnscanner/index.html .

test:erd:
  extends: .base_db
  stage: test
  allow_failure: true
  artifacts:
	name: erd
	paths:
	  - erd.pdf
  only:
	- master
  script:
	- bundle exec rake erd

test:minitest:
  extends: .base_db
  stage: test
  artifacts:
	name: coverage_report
	when: always
	paths:
	  - coverage/
	  - test/reports/
	reports:
	  junit: test/reports/**/TEST-*.xml
  script:
	- bundle exec rake db:create RAILS_ENV=test
	- bundle exec rake test

staging:
  stage: deploy
  script:
	- gem install dpl
	- dpl --provider=heroku --app=$HEROKU_APP_STAGING --api-key=$HEROKU_API_KEY
  only:
	- master

production:
  stage: deploy
  script:
	- gem install dpl
	- dpl --provider=heroku --app=$HEROKU_APP_PRODUCTION --api-key=$HEROKU_API_KEY
  only:
	- tags

Gemfile

source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }

ruby '2.6.6'

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 6.0.3', '>= 6.0.3.3'
# Use sqlite3 as the database for Active Record
gem 'sqlite3', '~> 1.4'
# Use Puma as the app server
gem 'puma', '~> 4.1'
# Use SCSS for stylesheets
gem 'sass-rails', '>= 6'
# Transpile app-like JavaScript. Read more: https://github.com/rails/webpacker
gem 'webpacker', '~> 4.0'
# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
gem 'turbolinks', '~> 5'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.7'
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 4.0'
# Use Active Model has_secure_password
# gem 'bcrypt', '~> 3.1.7'

# Use Active Storage variant
# gem 'image_processing', '~> 1.2'

# Reduces boot times through caching; required in config/boot.rb
gem 'bootsnap', '>= 1.4.2', require: false

group :development, :test do
  # Call 'byebug' anywhere in the code to stop execution and get a debugger console
  gem 'brakeman'
  gem 'byebug', platforms: %i[mri mingw x64_mingw]
  gem 'dawnscanner', require: false
  gem 'minitest-reporters'
  gem 'rails-erd'
  gem 'rubocop'
  gem 'rubocop-minitest'
  gem 'rubocop-performance'
  gem 'rubocop-rails'
  gem 'simplecov'
end

group :development do
  # Access an interactive console on exception pages or by calling 'console' anywhere in the code.
  gem 'web-console', '>= 3.3.0'
end

group :test do
  # Adds support for Capybara system testing and selenium driver
  gem 'capybara', '>= 2.15'
  gem 'selenium-webdriver'
  # Easy installation and use of web drivers to run system tests with browsers
  gem 'webdrivers'
end

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: %i[mingw mswin x64_mingw jruby]

test_helper.rb

ENV['RAILS_ENV'] ||= 'test'
require_relative '../config/environment'
require 'minitest/autorun'
require 'minitest/reporters'
require 'rails/test_help'
require 'simplecov'

Minitest::Reporters.use! Minitest::Reporters::JUnitReporter.new
SimpleCov.start 'rails' do
  add_filter 'vendor'
end

class ActiveSupport::TestCase
  # Run tests in parallel with specified workers
  parallelize(workers: :number_of_processors, with: :threads)

  # Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order.
  fixtures :all

  # Add more helper methods to be used by all tests here...
end

Dzięki wielkie za wszelką pomoc. Pozdrawiam
Draqun

EDIT:

Rozwiązaniem było użycie minitest-reporters za miast minitest-junit. Wszystkie pliki gwarantujące poprawne działanie CI\CD GitLaba znajdują się powyżej.

1 Like