Search

PythonReactSEOPDF
GitHub Skill

test-gen

Generate comprehensive Minitest suites for Rails models and controllers. Use when user wants to add tests, improve coverage, fill empty test files, or says "test [model/controller]", "add tests", "write tests for", "test coverage", "generate tests".

GangWooLee☆ 0 Repository stars0 Repository forks

Installation

Follow the repository instructions for this skill and your agent. Review the files and dependencies before adding it to your workflow.

View source ↗Guides

Skill instructions

Test Generator

Fill empty test files with comprehensive Minitest suites based on existing code.

Quick Start

Task Progress (copy and check off):
- [ ] 1. Analyze model/controller code
- [ ] 2. Generate association tests
- [ ] 3. Generate validation tests
- [ ] 4. Generate enum/scope tests
- [ ] 5. Generate controller CRUD tests
- [ ] 6. Create realistic fixtures
- [ ] 7. Add test helpers
- [ ] 8. Run tests and verify

Current State

All test files are empty stubs. This skill transforms them into working test suites.

# Current state
class UserTest < ActiveSupport::TestCase
  # test "the truth" do
  #   assert true
  # end
end

Generation Strategy

  1. Read the model/controller to identify:

    • Associations
    • Validations
    • Enums
    • Scopes
    • Instance methods
    • Controller actions
  2. Generate tests for each element found

  3. Create fixtures with valid, realistic data

  4. Run tests to verify they pass

Test Patterns

See detailed examples:

Quick Examples

Association test:

test "should belong to user" do
  post = posts(:one)
  assert_instance_of User, post.user
end

Validation test:

test "should validate presence of title" do
  post = Post.new
  assert_not post.valid?
  assert_includes post.errors[:title], "can't be blank"
end

Enum test:

test "should transition between statuses" do
  post = posts(:one)
  post.draft!
  assert post.draft?

  post.published!
  assert post.published?
end

Controller authorization test:

test "should not update when unauthorized" do
  log_in_as users(:two)
  patch post_path(@post), params: { post: { title: "Hacked" } }

  assert_redirected_to root_path
  assert_not_equal "Hacked", @post.reload.title
end

Fixture Pattern

one:
  user: one
  email: user1@example.com
  password_digest: <%= BCrypt::Password.create('password', cost: 4) %>
  name: Test User One
  created_at: <%= 2.days.ago %>

Key points:

  • BCrypt cost 4 for faster tests
  • Valid associations
  • Realistic data
  • Proper timestamps

Test Helper

Add to test/test_helper.rb:

def log_in_as(user)
  session[:user_id] = user.id
end

Coverage Goals

  • Core models (User, Post): 90%+
  • Feature models (JobPost, Comment): 85%+
  • Simple models (Like, Bookmark): 80%+

After Generation

# Run all tests
rails test

# Run specific file
rails test test/models/user_test.rb

# With coverage (if SimpleCov installed)
COVERAGE=true rails test

Common Test Types

For models:

  • Associations
  • Validations (presence, format, uniqueness, length)
  • Enums (transitions, i18n)
  • Scopes (ordering, filtering)
  • Instance methods
  • Counter caches

For controllers:

  • Index (public access)
  • Show (public access, view increment)
  • New/Create (require login, authorization)
  • Edit/Update/Destroy (require ownership)
  • Invalid data handling
  • Flash messages

Project Patterns

From existing codebase:

  • Use Minitest (not RSpec)
  • Use Fixtures (not FactoryBot)
  • Flash messages in Korean
  • Auth via session[:user_id]
  • BCrypt cost 4 in fixtures
  • ActiveSupport::TestCase for models
  • ActionDispatch::IntegrationTest for controllers

Checklist

  • All associations tested
  • All validations tested (valid + invalid cases)
  • Enum transitions tested
  • Scopes tested
  • Controller auth tested
  • CRUD operations tested
  • Fixtures have realistic data
  • Test helper methods added
  • All tests pass
  • Coverage >= 80%

Examples

Read the usage examples in the source repository.

View source ↗

Source history

Indexed on
2026-01-20
Index updated
2026-01-26
Branch
main

Index and sync dates describe this directory. View the source repository for code history.

GitHub ↗

chat Comments (0)

chat_bubble_outline

No comments yet. Be the first to share your thoughts!