con un clic
rails-system-test-analyzer
// Analyze Rails system tests to identify which ones could be converted to faster controller tests. Use when optimizing test suites, reviewing system tests, or when asked about test performance.
// Analyze Rails system tests to identify which ones could be converted to faster controller tests. Use when optimizing test suites, reviewing system tests, or when asked about test performance.
| name | rails-system-test-analyzer |
| description | Analyze Rails system tests to identify which ones could be converted to faster controller tests. Use when optimizing test suites, reviewing system tests, or when asked about test performance. |
| argument-hint | [test/system/file_test.rb] |
| disable-model-invocation | true |
| allowed-tools | ["Bash","Glob","Grep","Read"] |
Analyze Rails system tests to determine if they truly require browser-based testing or could be converted to faster controller/integration tests.
System tests should ONLY be used when testing functionality that absolutely requires a real browser:
If a test only verifies server-rendered HTML, form submissions, and redirects, it should be a controller test.
If $ARGUMENTS is provided, analyze those specific files. Otherwise, find all system tests:
find test/system -name "*_test.rb" -type f 2>/dev/null || find spec/system -name "*_spec.rb" -type f 2>/dev/null
For each test file, analyze each test case:
Extract the test actions: Look for visit, click_on, click_link, click_button, fill_in, select, check, uncheck, choose, attach_file
Identify routes/controllers: Map visit some_path to controller actions using config/routes.rb
Find views rendered: From the controller action, identify:
app/views/controller/action.html.erb)render partial:, render @collection)app/helpers/)data-controller attributes (check app/javascript/controllers/)Check for JavaScript dependencies in each view/partial/helper:
Scan views, partials, and layouts for:
Stimulus/Hotwire (REQUIRES system test):
data-controller=data-action=data-*-target=<turbo-frame<turbo-streamdata-turbo-method=data-turbo-confirm=data-turbo-frame=Traditional JavaScript (REQUIRES system test):
<script> tags with logic (not just analytics)onclick=, onchange=, onsubmit=, onfocus=, onblur=javascript: linksremote: true in form helpers (legacy Rails UJS)Capybara JS assertions (suggests JS dependency):
have_css with visible: optionhave_selector with wait: optionaccept_alert, accept_confirm, dismiss_confirmexecute_script, evaluate_scriptwithin_window, switch_to_windowFor each test, determine:
KEEP AS SYSTEM TEST if:
CONVERT TO CONTROLLER TEST if:
For each test file analyzed, output:
## [test_file_name.rb]
### Test: "test description"
- **Code path**: UsersController#create -> views/users/new.html.erb
- **JavaScript detected**: None / [list findings]
- **Recommendation**: CONVERT / KEEP
- **Confidence**: High / Medium / Low
- **Reason**: [brief explanation]
[If CONVERT, provide controller test skeleton]
When recommending conversion, provide a skeleton:
# test/controllers/[controller]_test.rb
class [Controller]Test < ActionDispatch::IntegrationTest
test "[original test name]" do
# Setup
user = users(:one)
# Exercise
get new_user_path
assert_response :success
post users_path, params: { user: { name: "Test" } }
# Verify
assert_redirected_to user_path(User.last)
follow_redirect!
assert_select "h1", "Test"
end
end
At the end, provide:
## Summary
- Total system tests analyzed: X
- Tests requiring system test (JS detected): Y
- Tests convertible to controller tests: Z
- Potential time savings: ~Z * 2-5 seconds per test run
### Quick Wins (High confidence conversions)
1. test_file.rb - test_name
2. ...
### Needs Review (Medium confidence)
1. ...