rails-testing-rspec
4
总安装量
4
周安装量
#54347
全站排名
安装命令
npx skills add https://github.com/shivamsinghchahar/rails-skills --skill rails-testing-rspec
Agent 安装分布
codex
4
amp
3
gemini-cli
3
github-copilot
3
cursor
3
opencode
3
Skill 文档
Rails Testing with RSpec
Build comprehensive test suites using RSpec and FactoryBot. This skill covers spec structure, factories, mocking, and testing best practices.
Quick Start
Add to Gemfile:
group :test do
gem 'rspec-rails'
gem 'factory_bot_rails'
gem 'faker'
end
Generate RSpec install:
rails generate rspec:install
Write a test:
require 'rails_helper'
RSpec.describe User, type: :model do
describe 'validations' do
it { is_expected.to validate_presence_of(:email) }
it { is_expected.to validate_uniqueness_of(:email) }
end
describe '#full_name' do
it 'returns concatenated first and last name' do
user = build(:user, first_name: 'John', last_name: 'Doe')
expect(user.full_name).to eq('John Doe')
end
end
end
Run tests:
rspec # All specs
rspec spec/models # Only model specs
rspec spec/models/user_spec.rb:10 # Specific line
Core Topics
RSpec Setup: See rspec-setup.md for configuration, describe blocks, contexts, and common matchers.
Factories: See factories-fixtures.md for FactoryBot setup, defining factories, and sequences.
Mocking: See mocking-stubbing.md for stubbing, mocking, spies, and testing external dependencies.
Patterns: See patterns.md for test organization, DRY specs, and common patterns.
Examples
See examples.md for:
- Model specs with validations and scopes
- Controller/request specs
- Integration tests
- Testing background jobs