Agent skill
rspec
RSpec testing best practices for Ruby and Rails applications, covering test organization, data management, and isolation patterns.
Install this agent skill to your Project
npx add-skill https://github.com/Mindrally/skills/tree/main/rspec
SKILL.md
RSpec Testing Best Practices
You are an expert in Ruby, Rails, and RSpec testing.
Key Principles
Comprehensive Coverage
Tests must cover both typical cases and edge cases, including invalid inputs and error conditions.
Readability and Clarity
- Employ descriptive names for
describe,context, anditblocks - Use the
expectsyntax for improved assertion readability - Keep test code concise without unnecessary complexity
- Include comments explaining complex logic
Test Organization
- Use
describefor classes/modules andcontextfor different scenarios - Use the
subjecthelper to prevent repetition when defining objects under test - Mirror your source file structure within the spec directory
Test Data Management
- Leverage
letandlet!for minimal, necessary setup - Prefer FactoryBot factories over fixtures for generating test data
- Create only the data necessary for each test
Test Isolation
- Each test must be independent without shared state between tests
- Mock external services (APIs, databases) and stub methods appropriately
- Avoid over-mocking: test real behavior when feasible
Reduce Duplication
- Share common behaviors across contexts using
shared_examples - Extract repetitive patterns into helpers or custom matchers
- Use
shared_contextfor common setup across multiple specs
Example Structure
RSpec.describe User, type: :model do
subject { build(:user) }
describe 'validations' do
it { is_expected.to validate_presence_of(:email) }
it { is_expected.to validate_uniqueness_of(:email) }
end
describe '#full_name' do
context 'when both first and last name are present' do
let(:user) { build(:user, first_name: 'John', last_name: 'Doe') }
it 'returns the combined name' do
expect(user.full_name).to eq('John Doe')
end
end
context 'when last name is missing' do
let(:user) { build(:user, first_name: 'John', last_name: nil) }
it 'returns only the first name' do
expect(user.full_name).to eq('John')
end
end
end
end
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
pixi-js
Expert guidance for Pixi.js game development with TypeScript, focusing on high-performance web and mobile games
fastify-typescript
Guidelines for building high-performance APIs with Fastify and TypeScript, covering validation, Prisma integration, and testing best practices
deep-learning-pytorch
Expert guidance for deep learning, transformers, diffusion models, and LLM development with PyTorch, Transformers, Diffusers, and Gradio.
python-testing
Expert in Python testing with pytest and test-driven development
svelte
Expert in Svelte and SvelteKit development with modern patterns and SSR
deep-learning
Comprehensive deep learning guidelines for neural network development, training, and optimization.
Didn't find tool you were looking for?