rspec-sprint
Diagnose your RSpec/Rails test-suite slowness and get the top repo-specific fixes — diagnosis plus prescription, not just numbers.
rspec-sprint doctor runs your suite once (via test-prof's FactoryProf and RSpec's JSON formatter in a single run), interprets the output against opinionated heuristics, and asserts the top few things to fix in your repo:
$ bundle exec rspec-sprint doctor
rspec-sprint doctor — 上位2件 (信号があった項目のみ):
1. factory が suite の 44% (local実測)。最上位は :tenant(689回, うち直接生成は 30回)
→ 不要 association を trait へ退避 / build_stubbed / let_it_be / FactoryDefault
想定削減: factory 比率を半減できれば最大 22% 相当(local実測)
2. 上位5例が suite 時間の 84%。最遅: "ExportedDatum zip生成" (193034ms)
→ 外部I/O・sleep・実ブラウザ依存を切り出す
想定削減: 上位例を半減できれば最大 42% 相当(local実測)
Installation
Add to your Gemfile (development/test group):
group :development, :test do
gem "rspec-sprint"
gem "test-prof"
end
Then run bundle install.
Prerequisite: Add to your spec/spec_helper.rb (or rails_helper.rb):
require "test_prof"
This enables FactoryProf for Rule① (factory_dominance). Without it, the other rules still run.
Usage
Diagnose
Run the doctor command to diagnose your suite and get prescriptions ranked by ROI:
$ bundle exec rspec-sprint doctor
Target a subset of specs for faster feedback:
$ bundle exec rspec-sprint doctor -- spec/models
Skip saving a snapshot:
$ bundle exec rspec-sprint doctor --no-snapshot
Compare against previous run
Show delta vs the most recent snapshot (requires at least one prior doctor run):
$ bundle exec rspec-sprint doctor --compare-last
前回比 +6.9s (+15%) factory time 40% → 48% [2026-06-18 09:00]
Save a long-term baseline
Record the current performance as a named baseline for future reference:
$ bundle exec rspec-sprint compare --save-baseline
The baseline is saved to .rspec-sprint/baseline.json and is never auto-pruned, unlike the rolling snapshots used by --compare-last.
The command exits 0 whether or not findings are reported, so it is safe to run in CI as an advisory step.
Why not just test-prof?
test-prof gives you the instruments (FactoryProf, EventProf, TagProf). rspec-sprint is the judgment layer on top: it reads those instruments, ranks the bottlenecks by ROI, and tells you which one to fix first and how. It does not reimplement any profiler.
Concretely, rspec-sprint applies three opinionated heuristics to your numbers:
- factory_dominance — factory time exceeds 30% of total suite time
- path_group_skew — one spec directory accounts for a disproportionate share of slowness
- slow_examples_concentration — a handful of examples dominate the tail
For each finding it emits a ranked prescription rather than leaving interpretation to you.
Even when test-prof is not installed, FactoryBot is absent, or the suite fails partway through, rspec-sprint doctor degrades gracefully and tells you what it could and could not measure.
Compatibility
| Component | Version |
|---|---|
| Ruby | >= 3.0 |
| RSpec | ~> 3.13 |
| test-prof | >= 1.0 |
| Rails | optional (not required) |
Status
v1.0.0 — API stable. Dogfood confirmed on 3 Rails apps.
| App | Bottleneck found | Prescription |
|---|---|---|
| SonicGarden/aegis | factory_dominance — :tenant factory 689 calls (44%) | build_stubbed / let_it_be |
| SonicGarden/carecollabo | slow_examples_concentration — zip export test 193s | stub external I/O |
| SonicGarden/testra | slow_examples_concentration — SSRF guard test 3.5s | stub network calls |
All three findings were repo-specific with concrete numbers and actionable prescriptions.
Snapshot schema v1 is frozen — field additions are OK, deletions and type changes are not.
License
MIT