Refactoring¶
The BerryCrush plugin provides refactoring support to safely rename and delete elements while keeping references in sync.
Rename Fragment¶
Rename a fragment and automatically update all include references.
How to Use¶
- Place cursor on a fragment definition or reference
- Press
Shift+F6(or right-click → Refactor → Rename) - Type the new name
- Press
Enterto apply
Example¶
Before:
# login.fragment
fragment: login-steps
given I have credentials
call ^login
# test.scenario
scenario: Test
given I am logged in
include login-steps
After renaming to auth-steps:
# login.fragment
fragment: auth-steps
given I have credentials
call ^login
# test.scenario
scenario: Test
given I am logged in
include auth-steps
What Gets Updated¶
- Fragment definition line
- All
includedirectives in.scenariofiles - All
includedirectives in other.fragmentfiles
Preview Changes¶
Press Shift+F6 twice to open the rename dialog with preview.
The preview shows: - All affected files - Exact changes to be made - Option to exclude specific occurrences
Rename Variable¶
Rename a variable placeholder across the file.
How to Use¶
- Place cursor on a variable (e.g.,
{{userId}}) - Press
Shift+F6 - Type the new name
- Press
Enter
Example¶
Before:
scenario: Test
given I have an ID
id = "123"
when I retrieve the user
call ^getUser
userId: {{id}}
then I verify the ID
assert $.id equals {{id}}
After renaming id to userId:
scenario: Test
given I have an ID
userId = "123"
when I retrieve the user
call ^getUser
userId: {{userId}}
then I verify the ID
assert $.id equals {{userId}}
Scope¶
Variable rename is limited to the current file. Variables with the same name in other files are not affected.
Safe Delete¶
Delete a fragment or fragment file while checking for usages.
How to Use¶
- Select the fragment element or file
- Press
Cmd+Delete(Mac) orDeletewithSafe Deleteoption - If usages exist, review them in the dialog
- Choose to delete anyway or cancel
From File Tree¶
- Right-click on a
.fragmentfile - Select Refactor → Safe Delete
- Review usages if any
- Confirm deletion
From Editor¶
- Place cursor on
fragment:definition line - Press
Cmd+Delete(Mac) or equivalent - Review usages
- Confirm deletion
Usage Warning¶
When usages exist, you'll see:
Fragment 'login-steps' is included in:
- test.scenario
- integration.scenario
- smoke.scenario
Delete anyway?
Options¶
- View Usages: Open Find Usages to see details
- Delete Anyway: Proceed (will leave broken references)
- Cancel: Abort deletion
Rename File¶
Rename a scenario or fragment file.
How to Use¶
- Right-click on file in Project view
- Select Refactor → Rename
- Type new name (extension will be preserved)
- Press
Enter
Important Notes¶
- Renaming a
.fragmentfile does NOT rename fragments inside it - Fragment names are independent of file names
- Consider also renaming internal fragments to match
Best Practices¶
Before Renaming¶
- Save all files
- Commit current changes to version control
- Preview changes before applying
After Renaming¶
- Run tests to verify nothing broke
- Check version control diff
- Commit the rename
Naming Conventions¶
| Element | Convention | Example |
|---|---|---|
| Fragment names | lowercase-with-dashes | login-steps, create-user |
| Variable names | camelCase | userId, authToken |
| File names | lowercase-with-dashes | user-tests.scenario |
Troubleshooting¶
Rename Not Finding All Usages¶
- Ensure project is fully indexed
- Check files are in source roots
- Run File → Invalidate Caches / Restart
Safe Delete Not Showing Usages¶
- Verify include directives match exactly
- Check for typos in fragment names
- Ensure index is up to date
Refactoring Option Disabled¶
- Check cursor is on a renameable element
- Ensure file is not read-only
- Verify plugin is enabled
Keyboard Shortcuts¶
| Action | Mac | Windows/Linux |
|---|---|---|
| Rename | Shift+F6 |
Shift+F6 |
| Safe Delete | Cmd+Delete |
Delete (with option) |
| Undo | Cmd+Z |
Ctrl+Z |
| Redo | Cmd+Shift+Z |
Ctrl+Shift+Z |