minitest
This skill should be used when the user asks about "Minitest", "Rails testing", "test/", "fixtures", "ActiveSupport::TestCase", "ActionDispatch::IntegrationTest", "system tests", "functional tests", "assert", "assert_equal", "assert_difference", "test_helper", "rails test", or needs guidance on testing Rails applications with the default Minitest framework.
What this skill does
# Minitest for Rails
Comprehensive guide to testing Rails applications with Minitest, the default Rails testing framework.
## Test Case Classes
Rails provides specialized test case base classes:
| Base Class | Purpose | Location |
|------------|---------|----------|
| `ActiveSupport::TestCase` | Model and unit tests | `test/models/` |
| `ActionDispatch::IntegrationTest` | Multi-controller workflow tests | `test/integration/` |
| `ActionDispatch::SystemTestCase` | Browser-based end-to-end tests | `test/system/` |
| `ActionController::TestCase` | Functional controller tests | `test/controllers/` |
| `ActionView::TestCase` | View and helper tests | `test/helpers/` |
| `ActionMailer::TestCase` | Mailer tests | `test/mailers/` |
| `ActiveJob::TestCase` | Background job tests | `test/jobs/` |
## Configuration
```ruby
# test/test_helper.rb
ENV["RAILS_ENV"] ||= "test"
require_relative "../config/environment"
require "rails/test_help"
class ActiveSupport::TestCase
# Run tests in parallel
parallelize(workers: :number_of_processors)
# Load fixtures
fixtures :all
# Add helper methods here
end
```
## Directory Structure
```
test/
├── controllers/ # Functional controller tests
├── fixtures/
│ ├── files/ # Upload test files
│ ├── users.yml
│ └── articles.yml
├── helpers/ # View helper tests
├── integration/ # Multi-controller tests
├── jobs/ # ActiveJob tests
├── mailers/ # Email tests
├── models/ # Model unit tests
├── system/ # Browser tests (Capybara)
├── application_system_test_case.rb
└── test_helper.rb
```
## Model Tests
```ruby
# test/models/article_test.rb
require "test_helper"
class ArticleTest < ActiveSupport::TestCase
# Setup runs before each test
setup do
@article = articles(:published)
end
# Associations
test "belongs to user" do
assert_respond_to @article, :user
assert_instance_of User, @article.user
end
test "has many comments" do
assert_respond_to @article, :comments
end
# Validations
test "is invalid without title" do
article = Article.new(body: "Content", user: @user)
assert_not article.valid?
assert_includes article.errors[:title], "can't be blank"
end
test "is invalid with title over 255 characters" do
article = Article.new(title: "a" * 256, body: "Content", user: @user)
assert_not article.valid?
end
test "is valid with all attributes" do
article = Article.new(title: "Test", body: "Content", user: @user)
assert article.valid?
end
# Scopes
test ".published returns only published articles" do
assert_includes Article.published, articles(:published)
assert_not_includes Article.published, articles(:draft)
end
test ".recent orders by created_at descending" do
recent = Article.recent.first
assert_equal articles(:published), recent
end
# Instance methods
test "#publish! changes status to published" do
article = articles(:draft)
article.publish!
assert_equal "published", article.status
assert_not_nil article.published_at
end
test "#published? returns true for published articles" do
assert articles(:published).published?
assert_not articles(:draft).published?
end
end
```
## Controller Tests (Functional)
```ruby
# test/controllers/articles_controller_test.rb
require "test_helper"
class ArticlesControllerTest < ActionDispatch::IntegrationTest
setup do
@article = articles(:published)
@user = users(:one)
end
test "should get index" do
get articles_url
assert_response :success
end
test "should get show" do
get article_url(@article)
assert_response :success
end
test "should get new" do
get new_article_url
assert_response :success
end
test "should create article" do
assert_difference("Article.count") do
post articles_url, params: {
article: { title: "New Article", body: "Content" }
}
end
assert_redirected_to article_url(Article.last)
end
test "should not create article with invalid params" do
assert_no_difference("Article.count") do
post articles_url, params: { article: { title: "" } }
end
assert_response :unprocessable_entity
end
test "should update article" do
patch article_url(@article), params: {
article: { title: "Updated Title" }
}
assert_redirected_to article_url(@article)
@article.reload
assert_equal "Updated Title", @article.title
end
test "should destroy article" do
assert_difference("Article.count", -1) do
delete article_url(@article)
end
assert_redirected_to articles_url
end
end
```
## Integration Tests
```ruby
# test/integration/user_flows_test.rb
require "test_helper"
class UserFlowsTest < ActionDispatch::IntegrationTest
test "user can create article" do
get new_article_url
assert_response :success
post articles_url, params: {
article: { title: "My First Article", body: "Content" }
}
follow_redirect!
assert_select "h1", "My First Article"
end
test "browsing articles as guest" do
get articles_url
assert_response :success
assert_select "article", minimum: 1
get article_url(articles(:published))
assert_response :success
assert_select "h1", articles(:published).title
end
end
```
## System Tests
```ruby
# test/application_system_test_case.rb
require "test_helper"
class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
driven_by :selenium, using: :headless_chrome, screen_size: [1400, 1400]
end
```
```ruby
# test/system/articles_test.rb
require "application_system_test_case"
class ArticlesTest < ApplicationSystemTestCase
setup do
@article = articles(:published)
end
test "visiting the index" do
visit articles_url
assert_selector "h1", text: "Articles"
end
test "creating an article" do
visit new_article_url
fill_in "Title", with: "System Test Article"
fill_in "Body", with: "This is test content."
click_on "Create Article"
assert_text "Article was successfully created"
assert_text "System Test Article"
end
test "updating an article" do
visit article_url(@article)
click_on "Edit"
fill_in "Title", with: "Updated Title"
click_on "Update Article"
assert_text "Article was successfully updated"
assert_text "Updated Title"
end
test "destroying an article" do
visit article_url(@article)
click_on "Delete", match: :first
assert_text "Article was successfully destroyed"
end
test "adding comment with Turbo" do
visit article_url(@article)
fill_in "comment_body", with: "Great article!"
click_on "Add Comment"
within "#comments" do
assert_text "Great article!"
end
end
end
```
## Fixtures
```yaml
# test/fixtures/users.yml
one:
email: [email protected]
name: Test User
admin:
email: [email protected]
name: Admin User
role: admin
# test/fixtures/articles.yml
published:
title: Published Article
body: This is published content.
status: published
user: one
published_at: <%= 1.day.ago %>
created_at: <%= 2.days.ago %>
draft:
title: Draft Article
body: This is draft content.
status: draft
user: one
created_at: <%= 1.day.ago %>
# With associations
# test/fixtures/comments.yml
one:
body: Great article!
article: published
user: one
```
## Assertions Reference
### Basic Assertions
```ruby
assert value # truthy
assert_not value # falsy (Rails)
refute value # falsy (Minitest)
assert_equal expected, actual # ==
assert_not_equal unexpected, actual
assert_same expected, actual # same object
assert_nil value
assert_not_nil value
assert_empty collection
assert_not_empty collection
assert_includes collection, item
assert_not_includes collection, item
assert_instance_of Class, object
assert_kind_of Class, object
assert_resRelated in Code Review
gstack
IncludedFast headless browser for QA testing and site dogfooding. Navigate pages, interact with elements, verify state, diff before/after, take annotated screenshots, test responsive layouts, forms, uploads, dialogs, and capture bug evidence. Use when asked to open or test a site, verify a deployment, dogfood a user flow, or file a bug with screenshots. (gstack)
startup-due-diligence
IncludedLegal due diligence review for seed-stage and Series A startups (US, Delaware C-Corp focus). Supports both investor and founder perspectives. Capabilities include: (1) Interactive document review and issue spotting; (2) Document request list generation; (3) Cap table and SAFE/convertible note analysis; (4) Red flag identification with severity ratings; (5) Diligence report generation. TRIGGERS: due diligence, DD, startup investment, cap table review, Series A, seed round, investor diligence, legal review startup, SAFE analysis, convertible note, 409A, founder vesting.
interview-master
IncludedThis skill should be used when the user asks to "generate interview questions", "prepare for interview", "optimize resume", "conduct mock interview", "analyze git commits for resume", "generate resume from code", "review my resume", or mentions interview preparation, career assistance, or extracting project experience from git history. Provides comprehensive interview and career development guidance for both job seekers and interviewers.
fix-issue
IncludedFixes GitHub issues using parallel analysis agents for root cause investigation, code exploration, and regression detection. Reads issue context from gh CLI, searches codebase and memory for related patterns, generates a fix with tests, and links the resolution back to the issue via PR. Includes prevention analysis to avoid recurrence. Use when debugging errors, resolving regressions, fixing bugs, or triaging issues.
sf-apex
IncludedGenerates and reviews Salesforce Apex code with 150-point scoring. TRIGGER when: user writes, reviews, or fixes Apex classes, triggers, test classes, batch/queueable/schedulable jobs, or touches .cls/.trigger files. DO NOT TRIGGER when: LWC JavaScript (use sf-lwc), Flow XML (use sf-flow), SOQL-only queries (use sf-soql), or non-Salesforce code.
swift-development
IncludedComprehensive Swift development for building, testing, and deploying iOS/macOS applications. Use when Claude needs to: (1) Build Swift packages or Xcode projects from command line, (2) Run tests with XCTest or Swift Testing framework, (3) Manage iOS simulators with simctl, (4) Handle code signing, provisioning profiles, and app distribution, (5) Format or lint Swift code with SwiftFormat/SwiftLint, (6) Work with Swift Package Manager (SPM), (7) Implement Swift 6 concurrency patterns (async/await, actors, Sendable), (8) Create SwiftUI views with MVVM architecture, (9) Set up Core Data or SwiftData persistence, or any other Swift/iOS/macOS development tasks.