RSpec Tracer is a specs dependency analyzer, flaky tests detector, tests accelerator, and coverage reporter tool.
RSpec Tracer is a specs dependency analyzer, flaky tests detector, tests accelerator, and coverage reporter tool.
Test-dependency intelligence for RSpec: detect flaky tests, map code coupling, and, when you are ready, re-run only what changed.
rspec-tracer records the inputs it can observe for each RSpec example (Ruby files, file I/O, Rails templates and queries, declared globs and ENV branches) and turns that record into a flaky-test detector, a per-example dependency map, and optional CI acceleration. The flaky report and the dependency map never skip a test: value before trust.
Measured, not promised. In the maintainer's May 2026 field test
(rspec-tracer 2.0.0.pre.1, Apple M2 Max), Mastodon's spec/lib
(1,234 examples, Rails 8.1.3, Ruby 3.4.8) ran in 116.4 s cold and
17.0 s warm: 6.85x, with the tracer's own recording overhead
included in both runs. "Cold" here is the tracer's own first run,
not plain RSpec: recording costs roughly 1.6x plain RSpec on this
repository's Rails benchmark fixture (approximate), and no
tracer-free Mastodon baseline was measured, so your gain over a
suite without the tracer will be smaller than cold minus warm.
Suite shape matters: across the same field tests, warm-run skip
rates ranged from 31% (a suite carrying 177 pre-existing failures:
failed examples are never skipped) to 100%. Measure your own suite
before you rely on these numbers.
Conservative by design, honest about its limits. The tracer
never skips failed, flaky, or pending examples, nor any example
whose recorded inputs changed; when a recorded input is ambiguous,
it re-runs. Real blind spots exist (runtime metaprogramming and
monkey-patches are invisible to it; the tracks: DSL is the escape
hatch), and the soundness model
catalogues the known blind spots. Shadow mode (run everything,
report what would have been skipped) lands in v2.0.0.rc.2, so you
can verify the tracer on your own data before trusting it with a
single skip.
Your data never leaves your infrastructure. Everything runs inside your test process and your CI cache: no SaaS backend, no telemetry, no per-seat pricing.
Requires Ruby 3.1+ and rspec-core 3.12+ (Rails 7.0+ when using Rails; Rails 8.0 needs Ruby 3.2+; JRuby 9.4 supported). Every CI-gated Ruby is supported until at least six months past its upstream EOL; see Maintenance.
# Gemfile: 2.0 is in pre-release; pin explicitly until 2.0.0 final
gem 'rspec-tracer', '= 2.0.0.rc.1', group: :test, require: falseAdd the tracer's working directories to your .gitignore before the
first run:
rspec_tracer.lock
rspec_tracer_cache/
rspec_tracer_coverage/
rspec_tracer_report/# Top of spec_helper.rb / rails_helper.rb, before any application
# code. With SimpleCov, start SimpleCov first: load order is part
# of the contract.
require 'rspec_tracer'
RSpecTracer.startRun the suite twice. The second run skips the examples whose recorded
inputs are unchanged and prints a per-reason breakdown of what
re-ran; open rspec_tracer_report/index.html to audit every
per-example decision. Not ready to let it skip anything? Set
RSPEC_TRACER_RUN_ALL_EXAMPLES=true (or run_all_examples true
inside the RSpecTracer.configure block in .rspec-tracer);
every example still runs while the flaky report and the dependency
maps accumulate data.
Setting up CI? docs/CI_RECIPES.md has copy-paste cache recipes for CircleCI, GitLab CI, Buildkite, and Heroku CI, plus a link to the canonical GitHub Actions workflow.
tracks: DSLAll timings are wall-clock and measured, not projected: maintainer field tests, May 2026, Apple M2 Max, rspec-tracer 2.0.0.pre.1. In every row, "cold" is the tracer's own first, recording run: it costs more than plain RSpec (roughly 1.6x on this repository's Rails benchmark fixture; approximate), and no tracer-free baseline was measured for these projects, so your savings versus a suite without the tracer will be smaller than cold minus warm.
| Project measured | Examples | Cold run | Warm run | Warm skip rate | Saved per warm run |
|---|---|---|---|---|---|
Mastodon spec/lib (Rails 8.1.3, Ruby 3.4.8) |
1,234 | 116.4 s | 17.0 s | 98% (1,212 skipped) | ~99 s |
| thoughtbot/clearance (Rails 8 engine + dummy app) | 258 | 11.1 s | 1.6 s | 100% | ~9.5 s |
| publify (carries 177 pre-existing failures; failed examples are never skipped) | 257 | 6.7 s | 4.8 s | 31% | ~1.9 s |
The Mastodon warm run is the zero-change best case; in the same field test, editing one file re-ran 68 of 1,234 examples in 19.0 s. Laptop rows understate CI savings: CI runners are slower than the development machine, so the seconds saved per run are typically larger there; the skip ratios are what transfer.
Worked examples (every input is an assumption you should replace with your own). For any suite:
(cold seconds - warm seconds) x runs/day / 60 x $/CI-minute x 30 = $/month per full-suite job
At $0.006/CI-minute (illustrative: GitHub-hosted Linux list price at the time of writing; check your provider's current rate) and 50 CI runs/day on one job:
Multiply by the number of jobs that each run the full suite (for example, a Ruby-version matrix); jobs that split one suite across workers share the saving rather than multiply it.
Conservative assumptions: 50 runs/day and the dollar rate are stated assumptions, not measurements; your skip rate may be far lower (see the 31% row: suites with many failing examples skip less, by design); remote-cache download time on fresh CI workers is not subtracted (measured end-to-end remote-cache gain on clearance was still ~4.6x).
Each example's observed inputs are digested and stored per example:
executed Ruby source (via Coverage), file I/O (via
Module#prepend hooks), Rails framework events, declared globs and
env vars, and whole-suite invalidators like Gemfile.lock. The next
run recomputes the digests and skips examples whose recorded inputs
are unchanged. The full input taxonomy lives in
ARCHITECTURE.md; what each input
kind does and does not guarantee is the
soundness model; the Rails
config.eager_load precision trade-off is covered by the Rails
recipe in COOKBOOK.md.
tracks: DSLAnnotate any describe / context / example with extra inputs the tracker can't auto-observe — config files baked at boot, env-var branches, non-Ruby deps:
RSpec.describe AdminController,
tracks: { files: 'app/policies/**/*.rb',
env: 'ROLE_CONFIG' } do
it 'gates on the feature flag' do
# ...
end
end| Key | Value shape | Semantics |
|---|---|---|
:files |
String glob OR Array of strings | Each matched file is attached as a :declared-kind dep on the example. |
:env |
String name OR Array OR wildcard | Each named env var is digested at finalize. Missing env reads as empty. |
Wildcards ('RAILS_*', '*_TOKEN', '*') expand against the
live ENV at register time; the persisted snapshot only carries
concrete keys.
Cascade. Nested groups contribute additively. A parent's
tracks: { files: 'a/*' } and a child's tracks: { env: 'B' } both
attach to the child's examples; the child does not clobber the parent
on any shared key.
Use track_files / track_env for the global case. Files /
env vars every test depends on (Gemfile.lock, AUTH_TOKEN,
RAILS_ENV) belong in .rspec-tracer:
RSpecTracer.configure do
track_files 'config/locales/**/*.yml', 'db/schema.rb', 'Gemfile.lock'
track_env 'AUTH_TOKEN', 'DATABASE_URL', 'RAILS_*'
end# spec/rails_helper.rb
require 'simplecov' # if used; load BEFORE rspec_tracer
SimpleCov.start
require 'rspec_tracer'
RSpecTracer.start
require File.expand_path('../config/environment', __dir__)
require 'rspec/rails'# .rspec-tracer
RSpecTracer.configure do
track_rails_defaults
endtrack_rails_defaults attaches the common Rails-side declared globs:
views, locales, fixtures, factories, helpers, config. Drop a
specific glob to hand attribution off to the per-example subscribers
instead:
RSpecTracer.configure do
# Templates → render_template.action_view subscriber attributes
# them per-example. Schema → opt-in sql.active_record observer
# attributes db/schema.rb + db/structure.sql per AR-touching
# example (read the Narrow AR-schema attribution section before
# enabling).
track_rails_defaults except: [:views, :schema]
track_ar_schema_notifications
endSupported Rails matrix: 7.0 / 7.1 / 7.2 / 8.0 (8.0 requires Ruby
3.2+). On JRuby use JRUBY_OPTS="--debug -X+O" and the JDBC
adapter (gem 'activerecord-jdbcsqlite3-adapter', '~> 71.0', platforms: :jruby for Rails 7.1; track the major to your Rails
line).
track_ar_schema_notifications promises per-example attribution of
db/schema.rb via the sql.active_record subscriber. The narrow
promise only holds when no per-example AR cleanup mechanism fires
queries inside the per-example bucket. Common Rails setups trip
this:
use_transactional_fixtures = true (Rails default) — per-example
BEGIN/COMMIT fires sql.active_record.:truncation / :deletion / :transaction in
around hooks — cleanup queries fire inside the bucket.Either case attributes db/schema.rb to every AR-touching example
(safe, but widens invalidation). A boot-time warn fires when the
precondition is unmet so you don't discover this from a confused
cache-hit-rate chart later.
For genuinely narrow attribution: set use_transactional_fixtures = false and use sequence-based factories (or another non-AR cleanup
mechanism that doesn't fire sql.active_record inside the example
window).
Supported out of the box. The tracker writes to per-worker directories and merges at finalize on the elected last worker. If you interrupt a run mid-flight, delete the lock file:
rm -f rspec_tracer.lock && bundle exec parallel_rspecCopy-paste cache recipes for CircleCI, GitLab CI, Buildkite, and
Heroku CI live in docs/CI_RECIPES.md; the
canonical GitHub Actions workflow is
.github/workflows/example-tracer-cache.yml.
The rest of this section covers the remote-cache rake flow and the
cache-key pattern all the recipes share.
The 1.x flow is preserved bit-for-bit. In your project's Rakefile:
spec = Gem::Specification.find_by_name('rspec-tracer')
load "#{spec.gem_dir}/lib/rspec_tracer/remote_cache/Rakefile"Then in your CI pipeline:
bundle exec rake rspec_tracer:remote_cache:download
bundle exec rspec
bundle exec rake rspec_tracer:remote_cache:uploadWith these env vars:
No open issues yet, or sync has not completed.