11---
22title : RSpec Integration with CI Insights
3- description : Report your test results from RSpec tests to CI Insights
3+ description : Report your test results from RSpec to CI Insights
44---
55
66import rspecLogo from " ../../../images/ci-insights/rspec/logo.svg"
7- import CommonTroubleshootingTips from " ./_common-troubleshooting-tips.mdx"
8- import GhaMergifyCiQuarantineSetup from " ./_gha_mergify_ci_quarantine_setup.mdx"
97import IntegrationLogo from " ../../../../components/IntegrationLogo.astro"
10- import MergifyCIUploadStep from " ../../../../components/MergifyCIUploadStep.astro"
118import CIInsightsSetupNote from " ../../../../components/CIInsightsSetupNote.astro"
12- import MergifyCIUploadStepMatrix from " ../../../../components/MergifyCIUploadStepMatrix.astro"
139
1410<IntegrationLogo src = { rspecLogo } alt = " RSpec logo" />
1511
16- This guide shows how to generate JUnit reports from your RSpec tests and upload
17- them to ** CI Insights** using a GitHub Actions workflow.
12+ This guide explains how to integrate RSpec with CI Insights using the
13+ ` rspec-mergify ` gem. Once installed, test results are automatically uploaded to
14+ CI Insights without any extra workflow changes.
1815
19- ## Generate a JUnit Report with RSpec
16+ ## Installation
2017
21- RSpec supports JUnit XML output through the built-in JUnit formatter. You can
22- configure RSpec to output JUnit reports using command-line options or
23- configuration files .
18+ You need to install the
19+ [ ` rspec-mergify ` ] ( https://rubygems.org/gems/rspec-mergify ) gem to automatically
20+ upload your test results to ** CI Insights ** .
2421
25- ### Using Command Line Options
22+ ### Gemfile
2623
27- ``` bash
28- bundle exec rspec --format RspecJunitFormatter --out junit.xml
29- ```
30-
31- ### Installing the JUnit Formatter
32-
33- First, add the JUnit formatter gem to your Gemfile:
24+ Add the gem to your ` Gemfile ` :
3425
3526``` ruby
36- # Gemfile
3727group :test do
38- gem ' rspec-junit-formatter '
28+ gem ' rspec-mergify '
3929end
4030```
4131
@@ -45,87 +35,58 @@ Then run:
4535bundle install
4636```
4737
48- ### Using RSpec Configuration
38+ ### Gem Install
4939
50- Add the formatter to your ` .rspec ` file:
51-
52- ``` text
53- --format RspecJunitFormatter
54- --out junit.xml
55- ```
56-
57- Or configure it in your ` spec_helper.rb ` :
58-
59- ``` ruby
60- # spec/spec_helper.rb
61- RSpec .configure do |config |
62- config.add_formatter(' RspecJunitFormatter' , ' junit.xml' )
63- end
64- ```
65-
66- ### Using Multiple Formatters
67-
68- You can use multiple formatters simultaneously:
40+ Alternatively, install it directly:
6941
7042``` bash
71- bundle exec rspec --format documentation --format RspecJunitFormatter --out junit.xml
43+ gem install rspec-mergify
7244```
7345
74- ### Using Rake Task
75-
76- You can also create a Rake task in your ` Rakefile ` :
77-
78- ``` ruby
79- require ' rspec/core/rake_task'
80-
81- RSpec ::Core ::RakeTask .new (:spec_junit ) do |t |
82- t.rspec_opts = ' --format RspecJunitFormatter --out junit.xml'
83- end
84- ```
85-
86- Then run:
87-
88- ``` bash
89- bundle exec rake spec_junit
90- ```
91-
92- ## Update Your GitHub Actions Workflow
46+ ## Modify Your Workflow
9347
9448<CIInsightsSetupNote />
9549
96- After generating the JUnit report, add a step to upload the results to CI
97- Insights using the mergifyio/gha-mergify-ci action.
98-
99- For example, in your workflow file:
50+ Your workflow should run your tests as usual while exporting the secret
51+ ` MERGIFY_TOKEN ` as an environment variable. You'll need to add the following
52+ code to the GitHub Actions step running your tests:
10053
10154``` yaml
102- - name : Run RSpec Tests and Generate JUnit Report
103- continue-on-error : true
104- run : bundle exec rspec --format RspecJunitFormatter --out junit.xml
55+ env :
56+ MERGIFY_TOKEN : ${{ secrets.MERGIFY_TOKEN }}
10557` ` `
10658
107- <MergifyCIUploadStep reportPath="junit.xml" />
108- <MergifyCIUploadStepMatrix reportPath="junit.xml" />
59+ For example:
10960
110- <GhaMergifyCiQuarantineSetup />
111-
112- ## Verify and Review in CI Insights
61+ ` ` ` yaml
62+ - name : Run RSpec Tests 🧪
63+ env :
64+ MERGIFY_TOKEN : ${{ secrets.MERGIFY_TOKEN }}
65+ run : bundle exec rspec
66+ ` ` `
11367
114- After pushing these changes:
68+ The gem automatically collects your test results and sends them to CI Insights.
11569
116- 1. Your GitHub Actions workflow will execute your RSpec tests.
117- 2. A JUnit report (junit.xml) is generated.
118- 3. The Mergify CI action uploads the report to CI Insights.
70+ Check the CI Insights dashboard afterward to view execution metrics, detect
71+ flaky tests, and gather actionable feedback.
11972
120- You can then review your test results, including any failures or flaky tests,
121- directly in the [CI Insights
122- dashboard](https://dashboard.mergify.com/ci-insights/jobs).
73+ ## Environment Variables
12374
124- ## Troubleshooting Tips
75+ | Variable | Purpose | Default |
76+ |----------|---------|---------|
77+ | ` MERGIFY_TOKEN` | API authentication token | **Required** |
78+ | `MERGIFY_API_URL` | API endpoint location | `https://api.mergify.com` |
79+ | `RSPEC_MERGIFY_ENABLE` | Force-enable outside CI | `false` |
80+ | `RSPEC_MERGIFY_DEBUG` | Print spans to console | `false` |
81+ | `MERGIFY_TRACEPARENT` | W3C distributed trace context | Optional |
82+ | `MERGIFY_TEST_JOB_NAME` | Test job name identifier | Optional |
12583
126- <ul>
127- <li>Gem Installation: Ensure the ` rspec-junit-formatter` gem is properly installed and included in your Gemfile.</li>
128- <li>RSpec Configuration : Verify that the formatter is correctly configured in your RSpec setup.</li>
84+ :::tip
85+ The gem auto-activates in CI environments (detected via the `CI` environment
86+ variable). To enable it outside CI, set `RSPEC_MERGIFY_ENABLE=true`.
87+ :: :
12988
130- <CommonTroubleshootingTips />
131- </ul>
89+ :::tip
90+ Use `MERGIFY_TEST_JOB_NAME` to make reports clearer in CI Insights, especially
91+ when running multiple test suites or using a matrix strategy.
92+ :: :
0 commit comments