View as Markdown

RSpec Integration with CI Insights

Report your test results from RSpec to CI Insights


This guide explains how to integrate RSpec with CI Insights using the rspec-mergify gem. Once installed, test results are automatically uploaded to CI Insights without any extra workflow changes.

You need to install the rspec-mergify gem to automatically upload your test results to CI Insights.

Add the gem to your Gemfile:

group :test do
gem 'rspec-mergify'
end

Then run:

Terminal window
bundle install

Alternatively, install it directly:

Terminal window
gem install rspec-mergify

Your workflow should run your tests as usual while exporting the secret MERGIFY_TOKEN as an environment variable. You’ll need to add the following code to the GitHub Actions step running your tests:

env:
MERGIFY_TOKEN: ${{ secrets.MERGIFY_TOKEN }}

For example:

- name: Run RSpec Tests 🧪
env:
MERGIFY_TOKEN: ${{ secrets.MERGIFY_TOKEN }}
run: bundle exec rspec

The gem automatically collects your test results and sends them to CI Insights.

Check the CI Insights dashboard afterward to view execution metrics, detect flaky tests, and gather actionable feedback.

VariablePurposeDefault
MERGIFY_TOKENAPI authentication tokenRequired
MERGIFY_API_URLAPI endpoint locationhttps://api.mergify.com
RSPEC_MERGIFY_ENABLEForce-enable outside CIfalse
RSPEC_MERGIFY_DEBUGPrint spans to consolefalse
MERGIFY_TRACEPARENTW3C distributed trace contextOptional
MERGIFY_TEST_JOB_NAMETest job name identifierOptional

Alternative: Manual JUnit XML Upload

Section titled Alternative: Manual JUnit XML Upload

If you prefer not to use the rspec-mergify gem, you can manually generate JUnit XML reports and upload them using the Mergify CI action.

Install the JUnit formatter gem:

# Gemfile
group :test do
gem 'rspec-junit-formatter'
end

Configure RSpec to output JUnit reports in your .rspec file:

--format RspecJunitFormatter
--out junit.xml
- name: Run RSpec Tests
continue-on-error: true
run: bundle exec rspec --format RspecJunitFormatter --out junit.xml
- name: Upload test results to Mergify
if: success() || failure()
uses: mergifyio/gha-mergify-ci@v14
with:
token: ${{ secrets.MERGIFY_TOKEN }}
report_path: "junit.xml"

Was this page helpful?