doc/ci/testing/fail_fast_testing.md
{{< details >}}
{{< /details >}}
Fail fast testing runs the test specs most relevant to your merge request changes before the rest of the suite runs. If those specs fail, the pipeline stops immediately to save time and compute resources.
For Ruby on Rails projects that use RSpec, the
Verify/FailFast CI/CD template
selects and runs only the relevant specs. It uses the
test_file_finder (tff) gem,
which maps changed files to their related spec files.
By default, the template runs in the .pre stage,
before all other pipeline stages.
Configure fail fast testing to get faster feedback on merge request changes before your full test suite runs.
Prerequisites:
To configure fail fast testing:
Add an RSpec job to run your full suite on merge request pipelines:
rspec-complete:
stage: test
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
script:
- bundle install
- bundle exec rspec
Include the Verify/FailFast template in your CI/CD configuration:
include:
- template: Verify/FailFast.gitlab-ci.yml
Optional. To use a different Docker image, set the image on the
rspec-rails-modified-path-specs job in your CI/CD configuration file:
include:
- template: Verify/FailFast.gitlab-ci.yml
rspec-rails-modified-path-specs:
image: custom-docker-image-with-ruby
The following examples assume a suite of 100 specs per model across 10 models (1000 specs total).
| Changed files | rspec-rails-modified-path-specs | rspec-complete |
|---|---|---|
| No Ruby files | Does not run | Runs all 1000 specs |
app/models/example.rb (all specs pass) | Runs 100 specs for example.rb | Runs all 1000 specs |
app/models/example.rb (any spec fails) | Runs 100 specs for example.rb | Skipped |