/ruby-rails:testproffrom ruby-rails
Diagnoses and fixes slow RSpec test suites using TestProf profilers and proven optimization techniques. Investigates actual codebase before prescribing fixes.
Ships in ruby-rails. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Expert guidance for diagnosing and fixing slow RSpec test suites. Based on field-tested techniques from Evil Martians' work reducing a 30,000-spec Rails suite from 4m30s to 2m (and targeting 1m30s with parallelization).
The core idea: slow test suites are rarely slow for one reason. They're slow for a handful of fixable reasons, stacked. This skill walks you through diagnosing which reasons apply, then fixing each one — in an order that avoids wasted effort.
When a user brings a slow RSpec suite, investigate their actual codebase before prescribing anything. A skill full of generic advice is worse than useless — the value is in mapping the general patterns onto their specific code. Follow this order:
spec/spec_helper.rb and spec/rails_helper.rb for suspicious requires (rubocop/rspec/support, SimpleCov config, global hooks).Gemfile for the suspects: SimpleCov, blind_index, any encryption gem, retry gems (retriable, Faraday retry middleware).sleep, retry, ObjectSpace, create_list(:..., with large numbers.The four findings in references/bottlenecks.md cover the most common heavy hitters. Read that file when you're ready to dig into a specific bottleneck.
Bad (generic suggestion list):
"Your service might be sleeping in tests. You could inject a delay parameter, or stub sleep, or use Retriable with base_interval: 0..."
Good (grounded in the user's code):
"I read
app/services/your_service.rb— the retry is hand-rolled at line 42 (sleep(2 ** attempt)), not delegated to a gem. So injection is the right fix, not gem config. Here's the diff..."
The second version took one Read call and one Grep but produced a fix the user can apply immediately. Always aim for the second version.
Use the symptoms the user describes to pick the first profiler. Don't try to run all of them — start with the one most likely to surface signal, then pivot based on what you learn.
| Symptom | First thing to run | What it tells you |
|---|---|---|
| "Slow everywhere, no obvious hotspot" | TEST_STACK_PROF=1 bin/rspec (StackProf) or Vernier | Global issues: gems loading heavy hooks, coverage, autoloading |
| "Specific files/groups are slow" | TPS_PROF=20 TPS_PROF_MIN_EXAMPLES=5 bin/rspec | Tests-per-second for each file; surfaces low-TPS groups |
| "GC time looks high" | TEST_MEM_PROF=gc bin/rspec | Per-spec GC overhead. Healthy is ~5%; investigate at 15%+ |
| "Want to know which spec types cost the most" | TAG_PROF=type bin/rspec (TagProf) | Aggregate time by tag (model, request, system, etc.) |
| "Specific slow spec, want a line-level view" | RUBY_PROF=1 bin/rspec path/to/spec.rb | Method-level hotspots inside one example |
Rule of thumb: if the user hasn't profiled yet, start with StackProf and a TPS run. Global issues and slow-file issues are usually independent problems.
TestProf v1.6+ has all the profilers referenced here:
# Gemfile
group :test do
gem "test-prof", "~> 1.6"
end
Most profilers activate via environment variables — no code changes needed. For let_it_be, before_all, and FactoryProf, add the relevant requires to spec/spec_helper.rb (see references/testprof_features.md).
From a real 30k-spec suite, these accounted for the majority of the speedup. Any of them could apply to the user's suite. See references/bottlenecks.md for the full diagnostic steps and code for each.
rubocop/rspec/support causing GC bloat — global hooks keep memory allocated across every spec. Replace with narrower requires. (~1 minute saved on the reference suite.)oneshot_line mode. (~1 minute saved.)pbkdf2_sha256 with cost: 1 in the test environment. (~30s saved.)let_it_be vs letlet_it_be (from TestProf) memoizes across an entire describe block instead of per-example. For read-only records used across many examples, this is a massive win:
# Before: creates a user for every example
let(:user) { create(:user) }
# After: creates once for the whole describe block
let_it_be(:user) { create(:user) }
Use let_it_be when the record doesn't need to be fresh per-example. If examples mutate it, either keep let or use let_it_be(:user, reload: true) / refind: true.
See references/testprof_features.md for the full set of TestProf primitives (before_all, AnyFixture, FactoryProf, EventProf, sample modes).
Total runtime hides the real problem. A file with 1,080 examples that runs in 2m50s is 6 TPS — terrible. A file with 5 examples that runs in 10s is 0.5 TPS — worse per-example, but maybe unavoidable.
TPS prioritizes files where high runtime meets high example count. That's where refactoring pays off most:
# Show the 20 slowest files with at least 5 examples
TPS_PROF=20 TPS_PROF_MIN_EXAMPLES=5 bin/rspec
When a file shows up in TPS, read references/slow_spec_patterns.md for the common root causes (ObjectSpace walks, sleep/retry delays, oversized fixtures).
After optimizing, the suite will grow. To keep gains:
let that could be let_it_be, tests that create hundreds of records for pagination/boundary checks, and reintroduction of require "rubocop/rspec/support".test-queue parallelizer plus periodic TPS runs will surface regressions.Read these when you need more depth on a specific topic:
references/bottlenecks.md — the four major bottlenecks with full diagnosis steps, code, and expected impactreferences/testprof_features.md — complete TestProf v1.6 feature reference (let_it_be, before_all, profilers, AnyFixture, FactoryProf, EventProf)references/slow_spec_patterns.md — common root causes inside individual slow specs, with before/after codereferences/diagnostic_scripts.md — drop-in snippets: GC tracker, timing decorator, suite summary hookWhat SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
test-prof, rspec-performance, test-optimization, ruby-testing
npx claudepluginhub el-feo/ai-context --plugin ruby-rails13 skills in this plugin
/brakemanStatic analysis security vulnerability scanner for Ruby on Rails applications. Use when analyzing Rails code for security issues, running security audits, reviewing code for vulnerabilities, setting up security scanning in CI/CD, managing security warnings, or investigating specific vulnerability types (SQL injection, XSS, command injection, etc.). Also use when configuring Brakeman, reducing false positives, or integrating with automated workflows./cucumber-gherkinBDD testing with Cucumber and Gherkin for Ruby and Rails applications. Use when writing feature files (.feature), step definitions, hooks, or implementing Behaviour-Driven Development in Ruby/Rails projects. Covers Gherkin keywords (Feature, Scenario, Given/When/Then, Background, Scenario Outline, Rule), Ruby step definition patterns, Cucumber Expressions, hooks (Before/After/BeforeAll/AfterAll), tags, data tables, doc strings, World modules, and Capybara integration. Triggers on cucumber, gherkin, BDD, feature files, step definitions, acceptance testing, executable specifications./design-patterns-rubyComprehensive Ruby implementations of Gang of Four (GoF) design patterns. Use when implementing object-oriented design solutions, refactoring to reduce coupling, solving architecture problems, or when user mentions specific patterns (Factory, Singleton, Observer, Strategy, etc.) in Ruby context./postgresql-rails-analyzerComprehensive PostgreSQL configuration and usage analysis for Rails applications. Use when Claude Code needs to analyze a Rails codebase for database performance issues, optimization opportunities, or best practice violations. Detects N+1 queries, missing indexes, suboptimal database configurations, anti-patterns, and provides actionable recommendations. Ideal for performance audits, optimization tasks, or when users ask to "analyze the database", "check for N+1 queries", "optimize PostgreSQL", "review database performance", or "suggest database improvements"./railsComprehensive Ruby on Rails v8.1 development guide with detailed documentation for Active Record, controllers, views, routing, testing, jobs, mailers, and more. Use when working on Rails applications, building Rails features, debugging Rails code, writing migrations, setting up associations, configuring Rails apps, or answering questions about Rails best practices and patterns./rails-generatorsCreate expert-level Ruby on Rails generators for models, services, controllers, and full-stack features, plus application templates for whole-app setup. Use when building custom generators, scaffolds, code generation tools, or Rails application templates (rails new -m, app:template, starter-app automation, multi-tenant setup), or when the user mentions Rails generators, Thor DSL, or automated code generation.Other plugins' skills for the same job