rspec
Skill15 starsChanged 42 days agoMITView on GitHub
Expert RSpec testing assistance covering Ruby BDD testing, mocks, expectations, and let/subject helpers. Use when writing Rails/Ruby tests, testing controllers/models, or running `bundle exec rspec`.
5 other projects use a version of this.
Adopted by
Most recently taken up by
- mukco/claude-skillstheir own version, first seen Oct 15, 2026
- Mindrally/skillstheir own version, first seen Oct 8, 2026
- instructure/canvas-lmstheir own version, first seen Oct 8, 2026
- tuannv14/claude-team-toolkittheir own version, first seen May 5, 2026
- martinstreicher/claude-skillstheir own version, first seen Feb 14, 2026
Other versions5 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 5
- instructure/canvas-lms★ 6.9ksame name
- Mindrally/skills★ 275same name
- tuannv14/claude-team-toolkit★ 1same name
- martinstreicher/claude-skills★ 0same name
- mukco/claude-skills★ 0same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository350 other files it gives its agents.
- airflowSkill
- catboostSkill
- claudeSkill
- comfyuiSkill
- cursor-aiSkill
- dalleSkill
- daskSkill
- dbtSkill
- deepseekSkill
- fastaiSkill
- geminiSkill
- github-copilotSkill
- huggingfaceSkill
- jaxSkill
- jupyterSkill
- kerasSkill
- langchainSkill
- lightgbmSkill
- llamaindexSkill
- llamaSkill
- matplotlibSkill
- midjourneySkill
- mistralSkill
- mlflowSkill
- nltkSkill
- numpySkill
- ollamaSkill
- openai-gptSkill
- opencvSkill
- pandasSkill
- perplexitySkill
- plotlySkill
- polarsSkill
- pytorchSkill
- raySkill
- scikit-learnSkill
- seabornSkill
- spacySkill
- sparkSkill
- stable-diffusionSkill
- tensorflowSkill
- vaexSkill
- weights-biasesSkill
- whisperSkill
- xgboostSkill
- api-gatewaySkill
- clean-architectureSkill
- cqrsSkill
- domain-driven-designSkill
- event-drivenSkill
- event-sourcingSkill
- graphqlSkill
- grpcSkill
- hexagonalSkill
- microservicesSkill
- modular-monolithSkill
- monolithSkill
- rest-apiSkill
- sagaSkill
- serverlessSkill
- The first 60 shown.
The file
We split this skill into the rules it gives an agent
7 rules. 0 are common, 1 is distinctive, and 6 are very specific to this project.
0
Common
Most of the 5 edited versions we read keep these.
1
Distinctive
This author's own choices. Worth a look.
6
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 104
Use nested context blocks with lazy-evaluated let:
- Very specific: line 134
Use instance_double Instead of double: Catch renamed or deleted methods immediately during test execution.
- Very specific: line 135
Use build_stubbed in FactoryBot for Unit Tests: Avoid touching the database when testing pure model logic.
- Very specific: line 136
Keep it Blocks to a Single Expectation: Isolate failures clearly.
- Very specific: line 137
Use context Blocks Starting with "when" or "with": Clarify environmental preconditions and business states.
- Distinctive: line 142
Test framework features: Test custom business logic.
- Very specific: line 143
Leave mysterious instance variables (@user): Use explicit let bindings for predictable memoization.
“Common” is measured: kept by at least 6 in 10 of the 5 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
RSpec
RSpec is the primary testing tool for Ruby (especially Rails). It focuses on "Behavior Driven Development" (BDD), making tests read like documentation specifications.
When to Use
- Ruby on Rails BDD Testing: The standard Behavior-Driven Development testing framework for Ruby and Rails applications.
- Expressive Specification Design: Writing readable, self-documenting specifications using
describe,context, andit. - Database & Model Validation: Testing ActiveRecord validations, scopes, and associations with
shoulda-matchers. - Comprehensive Mocking & Stubbing: Isolating dependencies using
instance_doubleandallow().to receive().
Quick Start
# user_spec.rb
RSpec.describe User, type: :model do
context "when newly created" do
it "has no name" do
user = User.new
expect(user.name).to be_nil
end
end
endCore Concepts
Hierarchical Contexts & Readable Specifications
Structures tests to match human-readable business expectations:
# spec/models/order_spec.rb
RSpec.describe Order, type: :model do
describe "#apply_coupon" do
context "when coupon is valid" do
let(:coupon) { create(:coupon, discount_percentage: 20) }
let(:order) { create(:order, total: 100) }
it "deducts percentage from order total" do
order.apply_coupon(coupon)
expect(order.total).to eq(80)
end
end
context "when coupon has expired" do
let(:expired_coupon) { create(:coupon, expires_at: 1.day.ago) }
let(:order) { create(:order, total: 100) }
it "raises an expired coupon error" do
expect { order.apply_coupon(expired_coupon) }
.to raise_error(CouponExpiredError)
end
end
end
endVerified Mocks (instance_double)
Prevents stale mocks by validating that mocked methods actually exist on the target class:
it "calls external payment gateway" do
gateway = instance_double(PaymentGateway)
expect(gateway).to receive(:charge).with(100).and_return(true)
service = CheckoutService.new(gateway: gateway)
service.process(100)
endFactoryBot Integration for Test Fixtures
Generates flexible model test records without brittle fixtures:
# spec/factories/users.rb
FactoryBot.define do
factory :user do
sequence(:email) { |n| "user#{n}@example.com" }
password { "Password123!" }
role { "member" }
trait :admin do
role { "admin" }
end
end
endCommon Patterns
Expressive Contexts with Let and Subject
Problem: Monolithic test cases testing both valid and invalid states together with hard-to-read assertions.
Solution:
Use nested context blocks with lazy-evaluated let:
RSpec.describe Order do
let(:order) { described_class.new(amount: amount) }
context "when amount is positive" do
let(:amount) { 50 }
it "is valid and processes successfully" do
expect(order).to be_valid
expect(order.process).to be true
end
end
context "when amount is zero or negative" do
let(:amount) { 0 }
it "is invalid with an error message" do
expect(order).not_to be_valid
expect(order.errors[:amount]).to include("must be greater than 0")
end
end
endBest Practices
Do:
- Use
instance_doubleInstead ofdouble: Catch renamed or deleted methods immediately during test execution. - Use
build_stubbedin FactoryBot for Unit Tests: Avoid touching the database when testing pure model logic. - Keep
itBlocks to a Single Expectation: Isolate failures clearly; one assertion per specification. - Use
contextBlocks Starting with "when" or "with": Clarify environmental preconditions and business states.
Don't:
- Overuse
let!(bang): Eager loading on every test slows down test suites; prefer lazyletunless eager creation is required. - Test framework features: Test custom business logic; avoid testing standard Rails ActiveRecord functionality directly.
- Leave mysterious instance variables (
@user): Use explicitletbindings for predictable memoization.
Troubleshooting
| Error | Cause | Solution |
LoadError: cannot load such file -- rails_helper | Running RSpec in a Rails app without loading helper. | Ensure require 'rails_helper' is at the top of the spec file. |
Double received unexpected message | Test double received a method call that was not declared. | Allow or expect method with allow(mock).to receive(:method_name). |
RSpec::Expectations::ExpectationNotMetError | Expected return value or predicate failed. | Check diff in terminal output and verify matcher syntax. |
References
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

