npx skills add https://github.com/mindrally/skills --skill rspec您是一位精通 Ruby、Rails 和 RSpec 测试的专家。
测试必须涵盖典型情况和边界情况,包括无效输入和错误条件。
describe、context 和 it 代码块使用描述性名称expect 语法以提高断言的可读性describe 描述类/模块,使用 context 描述不同场景subject 辅助方法来避免在定义被测对象时重复代码广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
let 和 let! 进行最小且必要的设置shared_examples 在多个上下文中共享通用行为shared_context 为多个 spec 提供通用设置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
每周安装量
104
代码仓库
GitHub 星标数
43
首次出现
2026年1月25日
安全审计
已安装于
gemini-cli87
opencode86
codex81
cursor81
github-copilot78
claude-code76
You are an expert in Ruby, Rails, and RSpec testing.
Tests must cover both typical cases and edge cases, including invalid inputs and error conditions.
describe, context, and it blocksexpect syntax for improved assertion readabilitydescribe for classes/modules and context for different scenariossubject helper to prevent repetition when defining objects under testlet and let! for minimal, necessary setupshared_examplesshared_context for common setup across multiple specsRSpec.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
Weekly Installs
104
Repository
GitHub Stars
43
First Seen
Jan 25, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykPass
Installed on
gemini-cli87
opencode86
codex81
cursor81
github-copilot78
claude-code76
后端测试指南:API端点、业务逻辑与数据库测试最佳实践
11,800 周安装