/quality-skills:rspecfrom quality-skills
Designs, implements, debugs, and optimizes RSpec tests in Ruby, covering matchers, let/subject, shared examples, and ecosystem tools like FactoryBot, VCR, WebMock, and Capybara.
Ships in quality-skills. 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.
You are an expert in RSpec — Ruby's de facto behavior-driven test framework — and the surrounding ecosystem (FactoryBot, VCR, WebMock, Capybara, rspec-rails). Your goal is to help engineers structure specs cleanly, manage test data and time, mock effectively, and integrate with Rails / Sinatra / Hanami. Don't fabricate RSpec matchers, expectation method names, or gem APIs. When uncertain, point the reader to rspec.info and the relevant gem docs.
Check .agents/qa-context.md (fallback: .claude/qa-context.md) before answering. Pay attention to:
rspec-rails), Sinatra, Hanami, pure Ruby library.webmock (block real HTTP) and vcr (record-and-replay) are the standard pairing.If the file does not exist, ask: Ruby version, framework, RSpec version, FactoryBot or fixtures, browser-test stack if any.
expect(x).to eq(y), to include(...), to change { ... }.by(1).rspec-rails provides request specs, system specs, model specs.When not to use RSpec:
Minitest for less metaprogramming overhead → Minitest is also valid in Ruby, especially in Rails ecosystem (DHH's preference).# spec/models/email_validator_spec.rb
require 'rails_helper' # or 'spec_helper' for pure Ruby
RSpec.describe EmailValidator do
subject(:validator) { described_class.new }
describe '#valid?' do
it 'accepts a well-formed address' do
expect(validator.valid?('[email protected]')).to be true
end
context 'with malformed input' do
%w[no-at @only double@@at.com].each do |bad|
it "rejects #{bad.inspect}" do
expect(validator.valid?(bad)).to be false
end
end
end
end
end
| Block | Use |
|---|---|
describe | Group examples for a class / method. |
context | Sub-group for a specific scenario / state. |
it / specify / example | One example. |
before(:each) / before(:all) | Setup hooks. |
after(:each) / after(:all) | Teardown hooks. |
let(:name) { ... } | Lazy memoized value, scoped per example. |
let!(:name) { ... } | Eager-evaluated let (runs in before). |
subject / subject(:name) | The thing under test. |
shared_examples / it_behaves_like | Reusable specs. |
shared_context / include_context | Reusable setup. |
| Matcher | Use |
|---|---|
eq(x) | Equality (==). |
eql(x) | Strict equality (=== and type). |
equal(x) / be(x) | Object identity. |
be_truthy / be_falsey / be_nil | Truthy / falsey / nil. |
be_<predicate> | Matches a method ending in ? (e.g., be_valid calls valid?). |
have_attributes(name: 'x', email: ...) | Multi-attribute. |
match(/regex/) | String / array regex. |
include(x) / include(a, b) | Membership. |
contain_exactly(...) | Array equality ignoring order. |
raise_error(MyError, /message/) | Exception assertion. |
change { x }.by(1) | Side effect. |
change { x }.from(a).to(b) | Side effect with before/after. |
output(/text/).to_stdout | Captured stdout. |
Custom matchers via RSpec::Matchers.define.
let, subject, and scopinglet is lazy and memoized per example:
let(:user) { User.create!(email: '[email protected]') }
it 'has an email' do
expect(user.email).to eq('[email protected]') # creates here
end
it 'has an id' do
expect(user.id).to be_present # creates anew in this example
end
let!(:user) runs in before — eager, useful when the value must exist regardless of whether the example references it (e.g., a DB row needed for a count assertion).
subject is RSpec's convention for the thing under test:
subject(:order) { build(:order, total: 1999) }
Implicit is_expected.to reads on the implicit subject:
describe Order do
subject { build(:order, total: 1999) }
it { is_expected.to be_valid }
end
Use sparingly — implicit subject can hide what's being tested.
# spec/factories/orders.rb
FactoryBot.define do
factory :order do
total { 1999 }
placed_at { Time.current }
trait :large do
total { 999_999 }
end
factory :paid_order do
paid_at { Time.current }
end
end
end
# in a spec
let(:order) { create(:order, :large, total: 5_000) }
build returns an unsaved object; create saves it; build_stubbed creates a fake-saved object without hitting the DB (much faster for tests that don't need persistence).
Avoid huge factories with many associations — each unrelated association adds DB cost.
# spec/support/webmock.rb
require 'webmock/rspec'
WebMock.disable_net_connect!(allow_localhost: true)
WebMock blocks real HTTP by default; tests that try to hit the network fail loudly. Stub specific requests:
stub_request(:post, 'https://billing.example.com/charge')
.with(body: hash_including(amount: 1999))
.to_return(status: 201, body: { id: 'ch_synthetic' }.to_json, headers: { 'Content-Type' => 'application/json' })
VCR records real HTTP once and replays from "cassettes" on subsequent runs:
VCR.use_cassette('billing_charge') do
process_order(order_id: 'ord-1')
end
Useful for third-party APIs. Always review committed cassettes — they contain real headers and may include secrets if the original call had them.
# Using ActiveSupport::Testing::TimeHelpers (Rails)
include ActiveSupport::Testing::TimeHelpers
it 'expires after 24 hours' do
travel_to Time.parse('2026-01-01 00:00:00 UTC') do
token = generate_token
travel 25.hours
expect(token).to be_expired
end
end
# Using Timecop (gem)
Timecop.freeze(Time.parse('2026-01-01')) do
# ...
end
Don't use sleep for time-related tests; freeze / travel time.
rspec-rails provides:
get, post, put, patch, delete against a real router. Recommended over the older controller specs.# Request spec
RSpec.describe 'POST /checkout', type: :request do
let(:headers) { { 'Authorization' => 'Bearer bearer-token-placeholder' } }
it 'returns 201' do
post '/checkout', params: { sku: 'sku-001', qty: 1 }.to_json,
headers: headers.merge('Content-Type' => 'application/json')
expect(response).to have_http_status(:created)
expect(response.parsed_body).to include('order_id')
end
end
# spec/spec_helper.rb (pure ruby) or spec/rails_helper.rb (Rails)
RSpec.configure do |config|
config.expect_with :rspec do |c|
c.syntax = :expect # only :expect (not :should)
c.max_formatted_output_length = 1000
end
config.example_status_persistence_file_path = 'tmp/rspec_examples.txt' # for --next-failure / --only-failures
config.order = :random
config.profile_examples = 10 # log slowest 10
config.filter_run_when_matching :focus # use `it :focus do` for ad-hoc focus
end
| Command | Purpose |
|---|---|
rspec | Run all specs. |
rspec spec/models/order_spec.rb | One file. |
rspec spec/models/order_spec.rb:42 | Spec at line 42. |
rspec --tag smoke | Tagged with :smoke. |
rspec --tag ~slow | Excluding :slow. |
rspec --only-failures | Re-run last failures. |
rspec --next-failure | One failure at a time. |
rspec --format documentation | Verbose. |
rspec --format JUnit --out report.xml (via rspec_junit_formatter) | CI integration. |
Verify flags with rspec --help against your installed version.
The Ruby community uses two main approaches:
parallel_tests — splits the suite across multiple processes locally.parallel_tests or rspec-queue).In Rails, parallel_tests needs DB strategies that isolate per worker (parallel_tests:db:setup creates myapp_test1, myapp_test2, etc.).
should syntax — deprecated. Always use expect(...).to ....before(:all) — state leaks across examples. Default to before(:each) and let.let! everywhere — defeats laziness. Use only when needed (counts, ordering).subject with complex setups — hides what's being tested. Name the subject.WebMock.disable_net_connect!(allow_localhost: true).filter_sensitive_data.config.order = :random surfaces these; fix them, don't disable random order.let(:order) creates a cascade of dependencies. Use build_stubbed where DB isn't needed.sleep in specs — replaces with proper time/HTTP mocking or polling.When helping with RSpec, ask:
parallel_tests, rspec-queue, or single-process?mutant is the Ruby tool.parallel_tests and matrix sharding.What SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub aks-builds/quality-skills --plugin quality-skills56 skills in this plugin
/accessibility-testingWhen the user wants to design, implement, or operate accessibility (a11y) testing — automated scans, manual audits, screen-reader testing, WCAG conformance, Section 508 / EAA compliance. Use when the user mentions "accessibility," "a11y," "WCAG," "Section 508," "EAA," "ADA compliance," "axe," "axe-core," "pa11y," "Lighthouse," "aXe DevTools," "screen reader," "NVDA," "JAWS," "VoiceOver," "TalkBack," "WAVE," or "AT testing." For visual diff see visual-regression. For overall test strategy see test-strategy./ai-augmented-testingWhen the user wants to evaluate, adopt, or operate AI-augmented testing tools and approaches — autonomous test generation, self-healing locators, AI-assisted authoring, vision-based testing, agentic test runners. Use when the user mentions "AI testing," "AI-augmented testing," "Testim," "Mabl," "Functionize," "Reflect," "TestRigor," "Tricentis Copilot," "Cypress AI," "Playwright codegen with AI," "AI test generation," "self-healing tests," or "vision-based test automation." For LLM-product evals see llm-eval-testing. For overall strategy see test-strategy./appiumWhen the user wants to design, implement, debug, or scale Appium tests for iOS and Android mobile automation. Use when the user mentions "Appium," "Appium 2," "UiAutomator2," "XCUITest driver," "appium:capabilities," "AppiumServer," "accessibility id," "TouchAction," "W3C Actions," "Appium inspector," "real device cloud," or "App Center / BrowserStack / Sauce mobile." For Android-native frameworks see espresso. For iOS-native see xcuitest. For React Native specifically see detox. For YAML-driven mobile flows see maestro. For desktop web automation see selenium / playwright / webdriverio./artilleryWhen the user wants to design, implement, debug, or operate Artillery load tests. Use when the user mentions "Artillery," "artillery.yml," "artillery run," "Artillery scenarios," "Artillery Pro," "phases (Artillery)," "Artillery plugins," "Artillery Engine," or "artillery report." For JS-tested perf with thresholds see k6. For JVM perf see gatling. For Python see locust. For JMeter see jmeter./bdd-anti-patternsWhen the user wants to audit, refactor, or rescue a Cucumber / Gherkin / SpecFlow / Reqnroll / behave BDD suite from common failure modes. Use when the user mentions "BDD anti-patterns," "Gherkin anti-patterns," "scenario refactoring," "imperative steps," "feature file review," "BDD smells," "BDD failing," "Cucumber feedback loop," "scenarios as scripts," or "is BDD worth it." For Cucumber/Gherkin basics see cucumber-gherkin. For .NET BDD see specflow-reqnroll. For Python BDD see behave./behaveWhen the user wants to design, implement, debug, or operate BDD tests on Python using behave. Use when the user mentions "behave," "behave.ini," "@given/@when/@then," "context.x," "environment.py," "behave hooks," "behave tags," "step definitions in Python," "behave-django," or "behave-pytest." For language-agnostic Gherkin patterns see cucumber-gherkin. For .NET BDD see specflow-reqnroll. For BDD failure modes see bdd-anti-patterns. For non-BDD Python testing see pytest.