# Minitest Testing

> Write, review, and improve Minitest tests for Ruby on Rails applications. Covers model tests, controller tests, system tests, fixtures, and best practices from Rails Testing Guide.

- **Type:** Skill
- **Install:** `agentstack add skill-shoebtamboli-rails-claude-skills-minitest-testing`
- **Verified:** Yes — security-reviewed for prompt injection and unsafe behavior
- **Seller:** [Shoebtamboli](https://agentstack.voostack.com/s/shoebtamboli)
- **Installs:** 0
- **Category:** [Agent Skills](https://agentstack.voostack.com/c/agent-skills)
- **Latest version:** 0.1.0
- **License:** MIT
- **Upstream author:** [Shoebtamboli](https://github.com/Shoebtamboli)
- **Source:** https://github.com/Shoebtamboli/rails_claude_skills/tree/main/lib/generators/claude/skills_library/minitest-testing
- **Website:** https://rubygems.org/gems/rails_claude_skills

## Install

```sh
agentstack add skill-shoebtamboli-rails-claude-skills-minitest-testing
```

Requires the [AgentStack CLI](https://agentstack.voostack.com/docs/cli). Works with Claude Code, Cursor, and any MCP-compatible agent.

## About

# Minitest Testing for Rails

Write comprehensive, maintainable Minitest tests following Rails conventions and best practices. This skill provides patterns for model tests, controller tests, system tests with Capybara, and fixture usage.

- Writing new tests for models, controllers, or system workflows
- Reviewing existing test coverage and improving quality
- Fixing failing tests or debugging test issues
- Setting up test fixtures and test helpers
- Writing system tests for end-to-end user workflows
- Testing Hotwire/Turbo behavior in system tests

- **Built-in Framework** - No additional gems needed, part of Rails
- **Fast Execution** - Lightweight and performant test suite
- **Rails Integration** - First-class support in Rails framework
- **Fixture Support** - Simple YAML-based test data
- **System Tests** - Built-in Capybara integration for browser testing
- **Parallel Testing** - Run tests in parallel with `bin/rails test:parallel`

Before completing testing work:
- ✅ Tests follow Minitest naming convention: `test "descriptive name"`
- ✅ Fixtures used appropriately for test data
- ✅ System tests cover critical user workflows
- ✅ Assertions are specific and descriptive
- ✅ Tests are independent and can run in any order
- ✅ All tests passing: `bin/rails test`

- Use descriptive test names: `test "creates post with valid attributes"`
- One assertion concept per test (may use multiple assert calls)
- Use specific assertions: `assert_equal`, `assert_redirected_to`, not just `assert`
- Reference fixtures with symbols: `posts(:published_post)`
- Use `setup` and `teardown` for test lifecycle management
- Use `assert_difference` for counting changes
- System tests for critical workflows, controller/model tests for details
- Run tests before committing code

---

## Core Testing Principles

### 1. Test Structure
Organize tests with clear phases:

```ruby
test "creates article with valid attributes" do
  # Arrange - set up test data
  user = users(:alice)

  # Act - perform the action
  article = Article.create(
    title: "Test Article",
    body: "Content here",
    user: user
  )

  # Assert - verify the outcome
  assert article.persisted?
  assert_equal "Test Article", article.title
end
```

### 2. Test Independence
Each test should be independent and able to run in any order. Use `setup` for common initialization:

```ruby
class ArticleTest 

draft:
  user: bob
  title: Draft Article
  body: Work in progress
  status: draft
```

### Using Fixtures in Tests

```ruby
test "finds published articles" do
  published = articles(:published)
  draft = articles(:draft)

  results = Article.published

  assert_includes results, published
  assert_not_includes results, draft
end
```

---

## Test Helpers

### Authentication Helper

```ruby
# test/test_helper.rb
class ActionDispatch::IntegrationTest
  def sign_in_as(user)
    post login_path, params: { email: user.email, password: "password" }
  end
end
```

### Custom Assertions

```ruby
# test/test_helper.rb
module ActiveSupport
  class TestCase
    def assert_valid(record)
      assert record.valid?, "Expected #{record.class} to be valid, errors: #{record.errors.full_messages}"
    end
  end
end
```

---

## Running Tests

```bash
# Run all tests
bin/rails test

# Run specific test file
bin/rails test test/models/article_test.rb

# Run specific test by line number
bin/rails test test/models/article_test.rb:12

# Run tests by pattern
bin/rails test test/models/*_test.rb

# Run system tests only
bin/rails test:system

# Run tests in parallel
bin/rails test:parallel

# Run with verbose output
bin/rails test -v

# Run and show coverage
COVERAGE=true bin/rails test
```

---

- rails-models - ActiveRecord patterns for database models
- rails-controllers - Controller patterns and RESTful design
- rails-hotwire - Testing Turbo Frames/Streams and Stimulus
- rails-jobs - Testing background jobs with SolidQueue
- rails-mailers - Testing email delivery with ActionMailer

**Official Documentation:**
- [Rails Testing Guide](https://guides.rubyonrails.org/testing.html) - Comprehensive Rails testing guide
- [Minitest Documentation](https://docs.seattlerb.org/minitest/) - Minitest framework docs
- [Capybara Cheat Sheet](https://devhints.io/capybara) - System test selectors

**Tools:**
- [SimpleCov](https://github.com/simplecov-ruby/simplecov) - Code coverage for Ruby
- [shoulda-matchers](https://github.com/thoughtbot/shoulda-matchers) - Additional matchers for Rails

## Source & license

This open-source skill is cataloged on AgentStack and links to its original source — we do not rehost the code.

- **Author:** [Shoebtamboli](https://github.com/Shoebtamboli)
- **Source:** [Shoebtamboli/rails_claude_skills](https://github.com/Shoebtamboli/rails_claude_skills)
- **License:** MIT
- **Homepage:** https://rubygems.org/gems/rails_claude_skills

Install and usage instructions live in the source repository linked above.

## Pricing

- **Free** — Free

## Security capabilities

Automated source analysis of v0.1.0 — what this tool can access:

- **Network access:** no
- **Filesystem access:** no
- **Shell / process execution:** no
- **Environment & secrets:** no
- **Dynamic code execution:** no

*"Yes" means the capability is present in the source — more access means more to trust, not that it is unsafe.*


## Versions

- **0.1.0** — security scan: passed — Imported from the upstream source.

## Links

- Listing page: https://agentstack.voostack.com/l/skill-shoebtamboli-rails-claude-skills-minitest-testing
- Seller: https://agentstack.voostack.com/s/shoebtamboli
- Browse the marketplace: https://agentstack.voostack.com/browse

---
Listed on AgentStack — the marketplace for AI agent skills and MCP servers. Every listing is security-reviewed. Creators keep 70%.
