gen-tests
Skill4 starsChanged 18 days agoMITView on GitHub
Generate RSpec request specs for untested controllers and service specs for untested services. Find controllers/services without corresponding specs: For each file to test, read: 1. The source file itself (understand methods, params, permissions) 2. The routes file (config/routes.rb) for endpoint paths 3. Existing factories in spec/factories/ relevant to the models used 4. Similar existing specs for pattern reference Before generating specs, query MCP for relevant learnings that may improve spec quality: Apply any relevant findings (required factory traits, tricky setup,…
The file
We split this skill into the rules it gives an agent
5 rules. About 0 are common, 5 are distinctive, and 0 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈5
Distinctive · estimate
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 44
Before generating specs, query MCP for relevant learnings that may improve spec quality:
- Distinctive: line 51
Graceful degradation: If MCP tools are unavailable or return errors, skip this step and proceed with standard spec generation.
- Distinctive: line 55
Use these mandatory patterns from the project:
- Distinctive: line 123
If tests fail, fix up to 3 times.
- Distinctive: line 135
If spec generation revealed a non-obvious pattern worth capturing for future test generation, create a learning:
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
/gen-tests — Generate Missing Test Specs
Generate RSpec request specs for untested controllers and service specs for untested services.
Usage
/gen-tests # List untested files, prompt for selection
/gen-tests controller # Generate specs for untested controllers
/gen-tests service # Generate specs for untested services
/gen-tests path/to/file.rb # Generate spec for a specific fileWorkflow
Step 1: Identify Untested Files
Find controllers/services without corresponding specs:
# Untested controllers
cd server && for f in $(find app/controllers/api/v1 -name '*_controller.rb'); do
spec="spec/requests/api/v1/$(basename "$f" .rb)_spec.rb"
[[ ! -f "$spec" ]] && echo "UNTESTED: $f"
done
# Untested services
cd server && for f in $(find app/services -name '*.rb' | grep -v concerns); do
spec="spec/services/$(echo "$f" | sed 's|app/services/||; s|\.rb$|_spec.rb|')"
[[ ! -f "$spec" ]] && echo "UNTESTED: $f"
doneStep 2: Read Source & Context
For each file to test, read:
- The source file itself (understand methods, params, permissions)
- The routes file (
config/routes.rb) for endpoint paths - Existing factories in
spec/factories/relevant to the models used - Similar existing specs for pattern reference
Step 2b: Query MCP for Test Patterns (if available)
Before generating specs, query MCP for relevant learnings that may improve spec quality:
platform.query_learnings— query:"<model/service name> test"(e.g.,"ai agent test","subscription service test")platform.query_learnings— query:"factory <model name>"(e.g.,"factory ai_agent","factory account")
Apply any relevant findings (required factory traits, tricky setup, known assertion patterns) to the spec generation approach.
Graceful degradation: If MCP tools are unavailable or return errors, skip this step and proceed with standard spec generation. MCP is additive, not required.
Step 3: Generate Spec
Use these mandatory patterns from the project:
Request specs (controllers):
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe "Api::V1::ResourceName", type: :request do
include_examples 'requires authentication', :get, '/api/v1/resources'
let(:user) { user_with_permissions('resource.read', 'resource.manage') }
let(:headers) { auth_headers_for(user) }
let(:account) { user.account }
describe "GET /api/v1/resources" do
it "returns resources for current account" do
resource = create(:resource, account: account)
get "/api/v1/resources", headers: headers
expect_success_response(json_response_data)
end
end
describe "POST /api/v1/resources" do
let(:valid_params) { { resource: { name: "Test" } } }
it "creates a resource" do
post "/api/v1/resources", params: valid_params, headers: headers
expect_success_response(json_response_data)
end
end
endService specs:
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe ServiceName, type: :service do
let(:account) { create(:account) }
let(:user) { user_with_permissions('relevant.permission') }
describe '#method_name' do
it 'does the expected behavior' do
result = described_class.new(account).method_name
expect(result).to be_present
end
end
endKey helpers to use:
user_with_permissions('perm.name')— creates user with permissionsauth_headers_for(user)— returns auth headersjson_response/json_response_data— parse response bodyexpect_success_response(data)/expect_error_response(msg, status)— response assertionsinclude_examples 'requires authentication'— shared auth checkinclude_examples 'requires permission'— shared permission check- AI specs: use factories from
spec/factories/ai/and helpers fromspec/support/ai_test_helpers.rb
Step 4: Run & Fix
cd server && bundle exec rspec spec/path/to/new_spec.rb --format progressIf tests fail, fix up to 3 times. After 3 failures, stop and report what needs manual attention.
Step 5: Report
Output a summary:
- Files tested
- Specs generated (with paths)
- Pass/fail status
- Any specs that need manual attention
Step 5b: Contribute Learning (conditional)
If spec generation revealed a non-obvious pattern worth capturing for future test generation, create a learning:
platform.create_learning(
title: "Test pattern: <concise description>",
content: "<what was non-obvious and how to handle it>",
category: "pattern"
)Create a learning when: required factory setup was non-trivial, mocking/stubbing required unusual configuration, assertions needed specific structure due to serializer behavior, or account-scoping had edge cases.
Skip for: straightforward CRUD controller specs, standard factory usage, obvious permission checks.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

