Copilot instructions
.github/instructions/rails-testing.instructions.mdRails Testing Guide
Copilot instructions
Quality
56/100
Scores the file, not the repository.Length
804 words
26 headings · 0 code blocksRepository
54
— · pushed 410 days agoLast changed
3 days ago
First indexed 3 days ago.123456# Rails Testing Guide78## Core Philosophy910- Test-Driven Development (TDD) as default practice11- Use Minitest and fixtures, not RSpec or factories12- Test behavior, not implementation details13- Keep tests fast, focused, and reliable14- Write tests that serve as documentation1516## Testing Principles1718- Write tests first, then implementation19- One assertion per test when possible20- Test the happy path and edge cases21- Keep test data realistic and minimal22- Make tests independent and repeatable2324## Test Organization2526- Mirror app structure in test directory27- Group related tests in the same file28- Use descriptive test names29- Keep test files focused and manageable30- Organize tests by feature or behavior3132## Fixtures Best Practices3334- Use fixtures for test data, not factories35- Keep fixtures simple and realistic36- Reference fixtures by meaningful names37- Share fixtures across related tests38- Update fixtures when models change3940## Model Testing4142- Test all validations thoroughly43- Verify associations work correctly44- Test scopes with various data sets45- Check business logic and calculations46- Ensure callbacks behave properly4748## Controller Testing4950- Focus on HTTP concerns only51- Test authentication and authorization52- Verify response formats and status codes53- Check parameter filtering54- Test error handling scenarios5556## System Testing5758- Test complete user workflows59- Use Capybara for browser automation60- Test JavaScript interactions61- Verify Turbo Frame updates62- Check responsive behavior6364## Service Object Testing6566- Test services in complete isolation67- Mock external dependencies68- Verify success and failure paths69- Test edge cases and error conditions70- Ensure proper transaction handling7172## Integration Testing7374- Test API endpoints thoroughly75- Verify request/response cycles76- Test authentication flows77- Check cross-controller workflows78- Validate data consistency7980## Test Data Management8182- Keep test data minimal and focused83- Use fixtures for common scenarios84- Create data in tests for specific cases85- Clean up after tests when needed86- Avoid test data dependencies8788## Mocking and Stubbing8990- Mock external services only91- Avoid mocking your own objects92- Use stubs for time-dependent code93- Keep mocks simple and obvious94- Document why mocking is necessary9596## Test Performance9798- Keep individual tests under 1 second99- Use parallel testing for speed100- Profile slow tests regularly101- Optimize database operations102- Cache expensive test setup103104## Test Coverage105106- Aim for high coverage without obsessing107- Focus on critical business logic108- Test error paths thoroughly109- Don't test framework code110- Use coverage as a guide, not a goal111112## Continuous Integration113114- Run tests on every commit115- Keep CI builds fast116- Fix broken tests immediately117- Test multiple Ruby versions118- Monitor test reliability119120## Test Helpers121122- Create helpers for common test patterns123- Keep helpers focused and reusable124- Document helper methods clearly125- Share helpers across test types126- Avoid complex helper logic127128## Testing JavaScript129130- Use system tests for JavaScript behavior131- Test Stimulus controllers thoroughly132- Verify Turbo interactions work133- Check progressive enhancement134- Test without JavaScript enabled135136## API Testing137138- Test all endpoints and methods139- Verify authentication requirements140- Check response formats and schemas141- Test rate limiting and throttling142- Validate error responses143144## Background Job Testing145146- Test job logic separately from queuing147- Verify job parameters and execution148- Test retry and failure scenarios149- Check job side effects150- Ensure idempotency151152## Email Testing153154- Test email delivery and content155- Verify recipient and sender details156- Check email templates render correctly157- Test attachments and multipart emails158- Validate email queueing159160## Security Testing161162- Test authorization for all actions163- Verify parameter filtering works164- Check for SQL injection vulnerabilities165- Test CSRF protection166- Validate input sanitization167168## Performance Testing169170- Profile critical code paths171- Test with realistic data volumes172- Monitor query counts173- Check memory usage174- Benchmark important operations175176## Test Maintenance177178- Refactor tests alongside code179- Remove obsolete tests promptly180- Keep tests DRY but readable181- Update tests when requirements change182- Review test quality regularly183184## Common Anti-Patterns185186- Testing implementation instead of behavior187- Overly complex test setup188- Brittle tests dependent on order189- Testing framework functionality190- Slow test suites that discourage TDD191192## Debugging Tests193194- Use byebug for test debugging195- Add descriptive failure messages196- Check test logs for details197- Isolate failing tests198- Verify test environment setup199200## Best Practices Summary201202- Write tests first203- Keep tests simple and fast204- Use fixtures over factories205- Test behavior, not implementation206- Maintain tests like production code207208Remember: Tests are your safety net and documentation. Write them first, keep them simple, and maintain them well.209
Also in levifig/rails-instructions
Diff this repo’s formatsOne repository carrying more than one format is the comparison this product exists for: does anyone actually write different content in each file, or is one a copy of the other?
| Repository | Format | Stack | Covers | Score | Changed |
|---|---|---|---|---|---|
| levifig/rails-instructions.github/instructions/rails-core.instructions.md · 54 | Copilot instructions | teststylearchtesting-strategy+5 | 68/100 | 3 days ago | |
| levifig/rails-instructions.cursor/rules/guidelines.mdc · 54 | Cursor rules | teststyletesting-strategysecurity+4 | 71/100 | 3 days ago | |
| levifig/rails-instructions.cursor/rules/rails-rules.mdc · 54 | Cursor rules | testlint-formatstylearch+9 | 84/100 | 3 days ago | |
| levifig/rails-instructions.github/copilot-instructions.md · 54 | Copilot instructions | teststyletesting-strategysecurity+4 | 71/100 | 3 days ago | |
| levifig/rails-instructions.github/instructions/rails-api.instructions.md · 54 | Copilot instructions | testlint-formatstyletesting-strategy+7 | 67/100 | 3 days ago | |
| levifig/rails-instructions.github/instructions/rails-background-jobs.instructions.md · 54 | Copilot instructions | teststyletesting-strategydatabase+2 | 63/100 | 3 days ago | |
| levifig/rails-instructions.github/instructions/rails-controllers.instructions.md · 54 | Copilot instructions | teststylesecurityapi+1 | 56/100 | 3 days ago | |
| levifig/rails-instructions.github/instructions/rails-deployment.instructions.md · 54 | Copilot instructions | setupstylesecuritydatabase+2 | 52/100 | 3 days ago | |
| levifig/rails-instructions.github/instructions/rails-hotwire.instructions.md · 54 | Copilot instructions | teststylesecurityperformance+1 | 56/100 | 3 days ago | |
| levifig/rails-instructions.github/instructions/rails-importmaps.instructions.md · 54 | Copilot instructions | teststylesecuritydatabase+2 | 56/100 | 3 days ago | |
| levifig/rails-instructions.github/instructions/rails-mobile.instructions.md · 54 | Copilot instructions | styleuiperformance | 66/100 | 3 days ago | |
| levifig/rails-instructions.github/instructions/rails-models.instructions.md · 54 | Copilot instructions | teststylearchtypes+4 | 60/100 | 3 days ago | |
| levifig/rails-instructions.github/instructions/rails-performance.instructions.md · 54 | Copilot instructions | teststylegitdatabase+2 | 56/100 | 3 days ago | |
| levifig/rails-instructions.github/instructions/rails-security.instructions.md · 54 | Copilot instructions | teststylesecuritydependencies+3 | 63/100 | 3 days ago | |
| levifig/rails-instructions.github/instructions/rails-services.instructions.md · 54 | Copilot instructions | teststylearchtesting-strategy+4 | 75/100 | 3 days ago | |
| levifig/rails-instructions.github/instructions/rails-styling.instructions.md · 54 | Copilot instructions | styledatabaseuiperformance+3 | 59/100 | 3 days ago | |
| levifig/rails-instructions.github/instructions/rails-views.instructions.md · 54 | Copilot instructions | teststylearchsecurity+3 | 60/100 | 3 days ago | |
| levifig/rails-instructions.github/instructions/rails.instructions.md · 54 | Copilot instructions | testlint-formatstylearch+9 | 84/100 | 3 days ago |
Diff against .github/instructions/rails-core.instructions.md Diff against .cursor/rules/guidelines.mdc Diff against .cursor/rules/rails-rules.mdc Diff against .github/copilot-instructions.md Diff against .github/instructions/rails-api.instructions.md Diff against .github/instructions/rails-background-jobs.instructions.md Diff against .github/instructions/rails-controllers.instructions.md Diff against .github/instructions/rails-deployment.instructions.md Diff against .github/instructions/rails-hotwire.instructions.md Diff against .github/instructions/rails-importmaps.instructions.md Diff against .github/instructions/rails-mobile.instructions.md Diff against .github/instructions/rails-models.instructions.md Diff against .github/instructions/rails-performance.instructions.md Diff against .github/instructions/rails-security.instructions.md Diff against .github/instructions/rails-services.instructions.md Diff against .github/instructions/rails-styling.instructions.md Diff against .github/instructions/rails-views.instructions.md Diff against .github/instructions/rails.instructions.md
