Add RSpec test reporter to CI workflows#10
Conversation
Publishes a consolidated RSpec test report as a GitHub Check Run after all parallel spec jobs complete. Each specs job uploads its JUnit XML as an artifact; the finalize job aggregates them via dorny/test-reporter. The non-parallel workflow publishes the report inline in the test job. Services need rspec_junit_formatter in their Gemfile and RSpec configured to write XML to tmp/rspec-results*.xml.
Setting permissions at the job level in a reusable workflow implicitly sets everything else to none, including contents: read, causing the hausgold/actions/ci@v2 checkout to be skipped and all subsequent steps to follow. Use the inherited GITHUB_TOKEN permissions instead; if checks: write is unavailable, fail-on-error: false prevents breakage.
Download step gets continue-on-error so a missing artifact (repo with no rspec_junit_formatter) does not skip the publish step. Both download and publish run with if: always() so a coverage merge failure cannot prevent the report from being attempted.
list-tests: all makes every test case appear in the Check detail view grouped by classname, which rspec_junit_formatter populates with the full describe/context chain — giving a nested view of the suite.
|
First off: I like the idea and the result. Just some thoughts:
That can be an anoying thing, but it also shows deprecations and an eagle eyed
I'm not a fan of external GHA workflows and alike. This stuff is run within the Example rspec json (from your Payment API pr):
vs RSpec.configuration.add_formatter(
RSpec::Core::Formatters::JsonFormatter,
"tmp/rspec-results#{ENV['TEST_ENV_NUMBER']}.json"
)Could be just added to painless/rspec This would save us from various config changes on all applications, and this
|

Adds RSpec test result reporting to both parallel and non-parallel test workflows using
dorny/test-reporter. After all spec jobs complete, the results are published as a GitHub Check Run called RSpec Tests on the PR or commit — failures are listed individually with expandable error output. No more scrolling through logs.The reporter uses RSpec's built-in JSON formatter (
rspec-json), so services do not need therspec_junit_formattergem.For the non-parallel workflow, a
--format json --outline in.rspecis enough — the file is written once and picked up by the publish step at the end of the job.For the parallel workflow, the formatter must be registered in
spec_helper.rbrather than.rspec, becauseparallel_tests' rake task invocation does not pass.rspecformatter config through to workers.spec_helper.rbis explicitly required by each worker subprocess.TEST_ENV_NUMBER(already used for SimpleCov) gives each worker a unique output filename so they don't overwrite each other.Each
specsmatrix job uploads its JSON files as an artifact namedrspec-json-N. Thefinalizejob downloads all artifacts into subdirectories and publishes the consolidated report.finalizeruns withif: always()so the report appears even when tests fail. The report steps usefail-on-error: falseandcontinue-on-error: trueso a missing JSON file does not break the build.dorny/test-reporteralso supportsjest-junitandmocha-json, so the same approach can be applied to frontend services using Jest or Mocha — no additional tooling needed.Note
Services need to opt in. For single-worker services: add
--format json --out tmp/rspec-results.jsonto.rspec. For parallel services: register the formatter inspec_helper.rbusingTEST_ENV_NUMBER. Without any output file the upload and report steps silently no-op.Warning
Todo — Verify this works correctly for repos that do not use RSpec at all. A real CI run against a non-RSpec service (e.g. a pure frontend) is needed to confirm nothing silently breaks.
Example PRs with enabled test reporter
test-nonparalleltest-parallel