Skip to main content
You can automatically detect and manage flaky tests in your projects running RSpec by integrating with Trunk. This document explains how to use Trunk’s RSpec plugin to upload test results to Trunk.

Setup steps

Work through the steps below in order. Once you’ve finished the last one, you’ll be ready to move on to configure uploads in CI.
Using the plugin is the best way to accurately detect flaky RSpec tests.You can also manually generate and upload test results in RSpec, however, manual RSpec uploads are not recommended.

Installing the plugin

Trunk detects flaky tests by analyzing test results automatically uploaded from your CI jobs. You can do this for your Rspec tests using Trunk’s RSpec plugin. To install the plugin in your project, add the rspec_trunk_flaky_tests gem to your Gemfile:
Gemfile
Install the plugin:
Then, load the plugin in spec_helper.rb:
spec/spec_helper.rb

Disable Retries

You need to disable automatic retries if you previously enabled them. Retries compromise the accurate detection of flaky tests. If you have a step in CI to rerun failed tests with the --only-failures option, or you’re using a package like rspec-retry, remember to disable them.

Versions and Updating the Plugin

You can find the Gem for rspec_trunk_flaky_tests here, along with its version history. This plugin is periodically updated with improved support and bug fixes. If you’re encountering something unexpected, first try:

Environment Variables

These optional environment variables can be set in your project to change the behavior of the RSpec plugin.

Repository metadata variables:

Configuration variables:

Try It Locally

Test Upload

Before modifying your CI jobs to automatically upload test results to Trunk, try uploading a single test run manually. You make an upload to Trunk using the following command:
You can find your Trunk organization URL slug and token in the Settings or by following these instructions. After your upload, you can verify that Trunk has received and processed it successfully in the Uploads tab. Warnings will be displayed if the test report uploaded by the plugin has issues.
You do not need to download the trunk-analytics-cli when using the Trunk RSpec plugin. Uploads are handled for you as long as you have set TRUNK_ORG_URL_SLUG and TRUNK_API_TOKEN.

Next Steps

Configure your CI to upload test runs to Trunk. Find the guides for your CI framework below:
atlassian-bamboo

Atlassian Bamboo

azure

Azure DevOps Pipelines

bitbucket

BitBucket Pipelines

buildkite

BuildKite

circle-ci

CircleCI

drone

Drone CI

github

GitHub Actions

gitlab

GitLab

jenkins

Jenkins

semaphore

Semaphore

teamcity

TeamCity

travis

Travis CI

other

Other CI Providers