testing

Guide Minitest-based Rails testing with fixtures, VCR, Capybara, and SimpleCov.

Updated Dec 13, 2024
One-click install
npx skills add https://github.com/apdarr/lace --skill testing-apdarr
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: testing
Source: https://github.com/apdarr/lace/tree/main/.github/skills/testing
Command: npx skills add https://github.com/apdarr/lace --skill testing-apdarr

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Rails testing can be complex; this skill provides a structured guide for Minitest-based testing in Rails apps, covering setup, conventions, and best practices to improve reliability and maintainability.

Core Features & Use Cases

  • TDD cycle: Red-Green-Refactor workflow to drive test-driven development.
  • Minitest & fixtures: Guidance on writing model, controller, and integration tests using fixtures.
  • Test doubles & tooling: Use of VCR + WebMock for HTTP interactions, Capybara + Selenium for system tests, and SimpleCov for coverage.
  • Practical examples: Ready-to-run snippets and test structure conventions to accelerate adoption in Rails projects.

Quick Start

Run the standard Rails test suite to verify code changes and system tests via rails test and rails test:system; follow the Red-Green-Refactor cycle as you work.

Frequently Asked Questions about testing

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I structure Rails tests with Minitest, fixtures, and system tests?

Rails testing with Minitest is structured by following standard conventions for model, controller, and system tests, using fixtures for data and Capybara for system tests to ensure reliable suites.

What is the Red-Green-Refactor cycle for test-driven development in Rails?

The Red-Green-Refactor cycle drives test-driven development by writing a failing test, making it pass, and then refactoring the code to maintain reliability while accelerating implementation.

Can I use VCR and WebMock for HTTP interactions in Minitest?

Yes, VCR and WebMock are used for HTTP interactions in Minitest to record and stub external API requests, ensuring reliable and deterministic test suites across Rails versions.

Does Rails testing with Capybara and Selenium support system tests?

Yes, Rails system testing supports Capybara and Selenium to simulate user interactions, enabling comprehensive end-to-end testing when running rails test:system.

What's the best way to measure code coverage in a Minitest Rails application?

The best way to measure code coverage in a Minitest Rails application is using SimpleCov, which integrates into the test suite to report reliable coverage metrics across your models and controllers.

Do I need fixtures to write controller tests in Rails?

Fixtures are used in Rails controller and model tests to provide predefined sample data in the database, establishing a reliable baseline state for validating application behavior.