---
title: RSpec Integration with CI Insights
description: Report your test results from RSpec to CI Insights
---

import rspecLogo from "../../../images/ci-insights/rspec/logo.svg"
import IntegrationLogo from "../../../../components/IntegrationLogo.astro"
import CIInsightsSetupNote from "../../../../components/CIInsightsSetupNote.astro"

<IntegrationLogo src={rspecLogo} alt="RSpec logo" />

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.

## Installation

You need to install the
[`rspec-mergify`](https://rubygems.org/gems/rspec-mergify) gem to automatically
upload your test results to **CI Insights**.

### Gemfile

Add the gem to your `Gemfile`:

```ruby
group :test do
  gem 'rspec-mergify'
end
```

Then run:

```bash
bundle install
```

### Gem Install

Alternatively, install it directly:

```bash
gem install rspec-mergify
```

## Modify Your Workflow

<CIInsightsSetupNote />

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:

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

For example:

```yaml
- 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.

## 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 |

:::tip
The gem auto-activates in CI environments (detected via the `CI` environment
variable). To enable it outside CI, set `RSPEC_MERGIFY_ENABLE=true`.
:::

:::tip
Use `MERGIFY_TEST_JOB_NAME` to make reports clearer in CI Insights, especially
when running multiple test suites or using a matrix strategy.
:::
