component-test
Skill2 starsChanged 2 months agoMITView on GitHub
Generate RSpec tests for a ViewComponent following the application's component-test patterns
1 other project uses a version of this.
Adopted by
Most recently taken up by
- Recusive/Skillstheir own version, first seen Mar 19, 2026
Other versions1 project uses a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 1
- Recusive/Skills★ 2same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository67 other files it gives its agents.
- acceptance-criteriaSkill
- architect-guideSkill
- architect-reviewSkill
- audit-fixerSkill
- avo-admin-expertSkill
- backend-services-expertSkill
- bug-hunt-allSkill
- bug-hunt-fixSkill
- bug-huntSkill
- build-feature-remoteSkill
- build-featureSkill
- codeSkill
- controller-expertSkill
- create-qa-documentSkill
- debugSkill
- devops-expertSkill
- execute-qaSkill
- feature-qaSkill
- fix-bug-indexSkill
- fix-honeybadgerSkill
- fix-system-testSkill
- frontend-expertSkill
- frontend-reviewSkill
- full-qa-fixSkill
- full-qaSkill
- full-reviewSkill
- green-ciSkill
- honeybadger-auditSkill
- ideateSkill
- impact-assessmentSkill
- improveSkill
- merge-mainSkill
- model-expertSkill
- model-testSkill
- native-bug-hunt-fixSkill
- native-bug-huntSkill
- page-speedSkill
- plan-questionsSkill
- planSkill
- plan-system-testsSkill
- policy-testSkill
- prdSkill
- prd-worktreeSkill
- product-questionSkill
- product-question-tldrSkill
- qa-branchSkill
- qa-testerSkill
- resolve-issueSkill
- review-acceptance-criteriaSkill
- review-fixesSkill
- review-railsSkill
- rspec-test-expertSkill
- scale-reviewSkill
- service-testSkill
- stedi-billing-expertSkill
- sync-user-docsSkill
- system-test-expertSkill
- system-testSkill
- test-changedSkill
- ticketsSkill
- The first 60 shown.
The file
Show its rules and text
We split this skill into the rules it gives an agent
31 rules. About 0 are common, 25 are distinctive, and 6 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈25
Distinctive · estimate
This author's own choices. Worth a look.
6
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 18
Test component inheritance from ApplicationComponent
- Distinctive: line 19
Test initialization with required/optional parameters
- Distinctive: line 20
Test parameter validation and error cases
- Distinctive: line 21
Test basic rendering with render_inline
- Distinctive: line 22
Test all slot configurations (renders_one, renders_many)
- Distinctive: line 23
Test conditional rendering (states, modes, visibility)
- Very specific: line 24
Test theme colors and styling (using theme colors from app/assets/tailwind/application.css)
- Distinctive: line 25
Test accessibility attributes (ARIA, semantic HTML)
- Distinctive: line 26
Test interactive elements (links, buttons, forms)
- Distinctive: line 27
Test empty states and edge cases
- Distinctive: line 28
Test helper methods (public and private through public interface)
- Distinctive: line 29
Test nested/child components
- Very specific: line 32
Use build instead of create when database persistence is not required
- Very specific: line 33
Use let for lazy evaluation, let!
- Distinctive: line 34
Avoid unnecessary database hits
- Distinctive: line 35
Use deterministic data with sequences, not random values
- Distinctive: line 36
Test rendered output, not implementation details
- Very specific: line 152
When the user provides a component file path as $ARGUMENTS, follow this iterative workflow until ALL tests pass:
- Distinctive: line 188
If ALL tests pass → Report success and exit
- Distinctive: line 189
If ANY tests fail → Continue to step 3
- Distinctive: line 192
Read and understand the error message
- Distinctive: line 203
Update factory if needed
- Distinctive: line 205
Update test setup (add missing let!
- Distinctive: line 245
Factory validation failures: Ensure factory has all required attributes
- Very specific: line 246
Association errors: Create associated records with let!
- Distinctive: line 247
CSS selector mismatches: Verify selectors match actual rendered HTML
- Distinctive: line 248
Missing slots: Test all slot configurations including when empty
- Very specific: line 249
Multi-tenant errors: Always set ActsAsTenant.current_tenant
- Distinctive: line 250
Conditional rendering: Test all branches of conditional logic
- Distinctive: line 251
Accessibility assertions: Verify ARIA attributes exist and have correct values
- Distinctive: line 252
Theme color assertions: Use exact class names from theme (bg-primary, text-text-light, etc.)
≈ “Common” is an estimate: at least 1 in 5 of the 213,895 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
ViewComponent Test Generator Command
You are an expert Rails ViewComponent test developer. Write comprehensive, fast, and maintainable RSpec component tests for the application following established patterns and best practices.
Reference Skill
For detailed patterns, examples, and testing conventions, consult the skill file at:
.claude/skills/viewcomponent-test-expert/SKILL.md
Core Principles
1. Comprehensive Coverage
- Test component inheritance from ApplicationComponent
- Test initialization with required/optional parameters
- Test parameter validation and error cases
- Test basic rendering with render_inline
- Test all slot configurations (renders_one, renders_many)
- Test conditional rendering (states, modes, visibility)
- Test theme colors and styling (using theme colors from
app/assets/tailwind/application.css) - Test accessibility attributes (ARIA, semantic HTML)
- Test interactive elements (links, buttons, forms)
- Test empty states and edge cases
- Test helper methods (public and private through public interface)
- Test nested/child components
2. Write Fast, Efficient Tests
- Use
buildinstead ofcreatewhen database persistence is not required - Use
letfor lazy evaluation,let!for immediate evaluation - Avoid unnecessary database hits
- Use deterministic data with sequences, not random values
- Test rendered output, not implementation details
3. Follow Established Patterns
Reference these component test files for patterns:
spec/components/directory for existing component tests.claude/skills/viewcomponent-test-expert/SKILL.mdfor comprehensive testing guide
Test File Structure
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe ComponentName, type: :component do
let(:organization) { create(:organization) }
let(:model) { create(:model_name, organization: organization) }
before do
ActsAsTenant.current_tenant = organization
end
describe 'inheritance' do
it 'inherits from ApplicationComponent' do
expect(described_class.superclass).to eq(ApplicationComponent)
end
end
describe 'initialization' do
# Test required and optional parameters
end
describe 'rendering' do
# Test basic rendering with render_inline
end
describe 'content rendering' do
# Test specific content sections
end
describe 'slots' do
# Test renders_one and renders_many slots
end
describe 'styling' do
# Test theme colors and CSS classes
end
describe 'accessibility' do
# Test ARIA attributes and semantic HTML
end
describe 'helper methods' do
# Test public helper methods
end
describe 'edge cases' do
# Test nil, empty, special characters
end
endKey Testing Patterns
Rendering with render_inline
rendered = render_inline(described_class.new(model: model))
expect(rendered.text).to include('Expected Text')
expect(rendered.css('.class-name')).to be_present
expect(rendered.to_html).to include('data-attribute')Testing Slots
rendered = render_inline(described_class.new) do |component|
component.with_header { 'Header Content' }
component.with_body { 'Body Content' }
end
expect(rendered.css('.header').text).to eq('Header Content')Testing Conditional Rendering
context 'when condition is true' do
it 'shows element' do
rendered = render_inline(described_class.new(show: true))
expect(rendered.css('.element')).to be_present
end
end
context 'when condition is false' do
it 'hides element' do
rendered = render_inline(described_class.new(show: false))
expect(rendered.css('.element')).not_to be_present
end
endTesting Accessibility
describe 'accessibility' do
it 'includes aria-label on interactive elements' do
rendered = render_inline(described_class.new(model: model))
button = rendered.css('button').first
expect(button['aria-label']).to be_present
end
it 'marks decorative elements as aria-hidden' do
rendered = render_inline(described_class.new(model: model))
expect(rendered.css('[aria-hidden="true"]')).to be_present
end
endInstructions for AI
When the user provides a component file path as $ARGUMENTS, follow this iterative workflow until ALL tests pass:
Phase 1: Analysis and Test Generation
- Read the component file at
$ARGUMENTS - Determine test file path: Convert component path to spec path
app/components/foo_component.rb→spec/components/foo_component_spec.rbapp/components/foo/bar_component.rb→spec/components/foo/bar_component_spec.rb
- Check if spec file exists at the determined path
- Analyze the component to identify:
- Class inheritance (should be ApplicationComponent)
- Initialize parameters (required, optional, defaults)
- Slots (renders_one, renders_many)
- Helper methods (public and private)
- Conditional rendering logic
- Theme colors and styling
- Accessibility attributes
- Nested/child components
- If test file exists, read it and identify:
- What is already tested
- What is missing
- What needs improvement
- Generate or update tests following the skill guide at
.claude/skills/viewcomponent-test-expert/SKILL.md - Ensure comprehensive coverage of all component behavior
- Use factories defined in
spec/factories/or suggest new ones
Phase 2: Iterative Test Execution and Fixes
CRITICAL: Do not stop until all tests pass. Repeat this loop until success:
- Run the tests for the specific component:
bundle exec rspec spec/components/component_name_spec.rb - Analyze test results:
- If ALL tests pass → Report success and exit
- If ANY tests fail → Continue to step 3
- For each test failure:
- Read and understand the error message
- Identify the root cause:
- Missing factory attributes
- Incorrect test expectations
- Missing slot configurations
- Incorrect CSS selectors
- Missing multi-tenant setup
- Missing associated records
- Incorrect render_inline usage
- Fix the failure:
- Update factory if needed
- Fix test expectations if they're incorrect
- Update test setup (add missing let! blocks, create associations)
- Adjust CSS selectors to match actual component output
- DO NOT modify the component unless there's a genuine bug
- Return to step 1 and run tests again
Phase 3: Final Verification
Once all tests pass:
- Run the full test suite one more time to confirm
- Provide a summary including:
- Total number of examples and failures (should be 0 failures)
- What was fixed during the iteration
- Final test coverage breakdown
- Any recommendations for the component or tests
Test Organization Checklist
For every component test file, verify:
require 'rails_helper'at toptype: :componentmetadata- Multi-tenant setup with
ActsAsTenant.current_tenant - Test inheritance from ApplicationComponent
- Test initialization with required/optional parameters
- Test parameter validation and error cases
- Test basic rendering
- Test all slot configurations
- Test conditional rendering (states, modes)
- Test theme colors and styling
- Test accessibility attributes
- Test interactive elements (links, buttons)
- Test empty states
- Test edge cases (nil, empty, special chars)
- Test helper methods
- Test nested components if applicable
Common Failure Patterns and Solutions
- Factory validation failures: Ensure factory has all required attributes
- Association errors: Create associated records with
let!or in factory - CSS selector mismatches: Verify selectors match actual rendered HTML
- Missing slots: Test all slot configurations including when empty
- Multi-tenant errors: Always set
ActsAsTenant.current_tenant - Conditional rendering: Test all branches of conditional logic
- Accessibility assertions: Verify ARIA attributes exist and have correct values
- Theme color assertions: Use exact class names from theme (bg-primary, text-text-light, etc.)
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.

