rails-testing-rspec

Write Rails tests with RSpec, FactoryBot, and mocking patterns. Use when creating tests, writing specs for models/controllers/requests, setting up test fixtures, or mocking external services.

Safety Notice

This listing is imported from skills.sh public index metadata. Review upstream SKILL.md and repository scripts before running.

Copy this and send it to your AI assistant to learn

Install skill "rails-testing-rspec" with this command: npx skills add shivamsinghchahar/rails-skills/shivamsinghchahar-rails-skills-rails-testing-rspec

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

Source Transparency

This detail page is rendered from real SKILL.md content. Trust labels are metadata-based hints, not a safety guarantee.

Related Skills

Related by shared tags or category signals.

General

rails-active-storage

No summary provided by upstream source.

Repository SourceNeeds Review
Security

rails-security-audits

No summary provided by upstream source.

Repository SourceNeeds Review
General

rails-action-mailer

No summary provided by upstream source.

Repository SourceNeeds Review
General

rails-action-cable

No summary provided by upstream source.

Repository SourceNeeds Review