RSpec Integration with Mergify
Report your test results from RSpec to Mergify
This guide explains how to integrate RSpec with Test Insights using the
rspec-mergify gem. Once installed, test results are automatically uploaded to
Test Insights without any extra workflow changes.
Installation
Section titled InstallationYou need to install the
rspec-mergify gem to automatically
upload your test results to Test Insights.
Gemfile
Section titled GemfileAdd the gem to your Gemfile:
group :test do gem 'rspec-mergify'endThen run:
bundle installGem Install
Section titled Gem InstallAlternatively, install it directly:
gem install rspec-mergifyUpdate Your CI Workflow
Section titled Update Your CI WorkflowYour workflow should run your tests as usual while exporting the secret
MERGIFY_TOKEN as an environment variable.
GitHub Actions
Section titled GitHub ActionsAdd the following 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 rspecBuildkite
Section titled BuildkiteSet MERGIFY_TOKEN in the environment of the agents running your tests.
The step itself then needs no Mergify-specific configuration:
steps: - label: "Run RSpec Tests 🧪" command: bundle exec rspecThe gem automatically collects your test results and sends them to Test Insights.
Quarantine and Crashed Runs
Section titled Quarantine and Crashed RunsThe gem applies quarantine inside the RSpec run.
When a quarantined example fails, the gem marks it pending with the message
Test is quarantined from Mergify Test Insights, so it does not count as a
failure and does not change RSpec’s exit code. The exit code of your test step
already accounts for quarantine, so the step needs nothing more:
-
Do not add
continue-on-error: true. The recipes that upload a JUnit report with themergifyio/gha-mergify-ciaction need it because the action decides the job’s result after the tests. Here nothing does, so it would let every real failure through. -
There is no step
idto set and notest_step_outcometo pass: both belong to that action, which this setup does not use.
A crash cannot pass for a green run either. Quarantine only covers failures
inside an example: a spec file that fails to load, a failing before(:suite)
or after(:context) hook, or RSpec dying mid-run still exits non-zero and fails
the step. The gem uploads results when the run ends, so a process killed
outright before then, such as by the out-of-memory killer, sends nothing to
Test Insights.
If the gem cannot fetch the quarantine list, it quarantines nothing for that run, and a quarantined example that fails makes the step fail as usual.
Verify and Review in Test Insights
Section titled Verify and Review in Test InsightsAfter pushing these changes, your next CI run reports its RSpec results automatically.
You can then review your test results, including any failures or flaky tests, directly in the Test Insights dashboard.
Environment Variables
Section titled Environment Variables| Variable | Purpose | Default |
|---|---|---|
MERGIFY_TOKEN | API authentication token | Required |
MERGIFY_API_URL | API endpoint location | https://api.mergify.com |
RSPEC_MERGIFY_ENABLE | Force-enable outside CI | false |
RSPEC_MERGIFY_DEBUG | Print spans to console | false |
MERGIFY_TRACEPARENT | W3C distributed trace context | Optional |
MERGIFY_TEST_JOB_NAME | Test job name identifier | Optional |
Was this page helpful?
Thanks for your feedback!