Rspec

From Mindrally/skills · View interactive version

Rspec is an AI agent skill from the GitHub repository Mindrally/skills. RSpec testing best practices for Ruby and Rails applications, covering test organization, data management, and isolation patterns.

How to use this skill

Skill file

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

Test Organization

Test Data Management

Test Isolation

Reduce Duplication

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
Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.