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
factory が suite の 47% (local実測)。最上位は :user(420回, うち直接生成は 30回 = カスケード)。
  → 不要 association を trait へ退避 / build_stubbed / let_it_be / FactoryDefault
...

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:

require "test_prof"

Usage

Run the doctor command to diagnose your suite and get prescriptions ranked by ROI:

$ bundle exec rspec-sprint doctor

To target a subset of specs (faster feedback during investigation):

$ bundle exec rspec-sprint doctor -- spec/models

Snapshot comparison (coming in v0.2.0):

$ bundle exec rspec-sprint doctor --no-snapshot

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 (e.g. "retire unused associations to a trait, switch to build_stubbed") 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

v0.1.0 — install-day tested, dogfood confirmed.

Dogfood result (SonicGarden/aegis, 2026-06-18):

$ bundle exec rspec-sprint doctor -- spec/models spec/policies

1. path group spec/models が suite 時間の 92% (local実測)
   → spec/models を別CIジョブに分離し fast suite から切り出す(候補)

2. factory が suite の 44%。最上位は :tenant(689回)
   → 不要な association を trait へ退避 / build_stubbed / let_it_be

Both findings are repo-specific with concrete numbers — not generic advice.

License

MIT