Code Snippets¶
Quick templates for common BerryCrush patterns.
Using Snippets¶
- Type the snippet prefix
- Press Tab or Enter to expand
- Fill in the placeholder values
- Press Tab to move to the next placeholder
Available Snippets¶
Scenario Snippets¶
| Prefix | Description | Expands To |
|---|---|---|
scenario |
Basic scenario | Full scenario template |
feature |
Feature block | Feature with scenarios |
background |
Background block | Shared setup steps |
outline |
Scenario outline | Parameterized scenario |
examples |
Examples table | Examples for outline |
Step Snippets¶
| Prefix | Description | Expands To |
|---|---|---|
given |
Given step | given description |
when |
When step | when description |
then |
Then step | then description |
and |
And step | and description |
but |
But step | but description |
Directive Snippets¶
| Prefix | Description | Expands To |
|---|---|---|
call |
API call | call ^operationId |
callwith |
Call with params | Call with parameter table |
assert |
Basic assertion | assert status 200 |
assertpath |
JSON path assertion | assert $.path equals value |
extract |
Extract value | extract $.path => variable |
include |
Include fragment | include fragmentName |
body |
Request body | body: { } |
Fragment Snippets¶
| Prefix | Description | Expands To |
|---|---|---|
fragment |
Fragment definition | Full fragment template |
parameters |
Parameters block | Parameters section |
Snippet Examples¶
Scenario Snippet¶
Type scenario and press Tab:
scenario: ${1:scenario name}
given ${2:precondition}
${3:step}
when ${4:action}
${5:step}
then ${6:expected result}
${7:step}
Call with Parameters¶
Type callwith and press Tab:
Fragment with Parameters¶
Type fragment and press Tab:
JSON Path Assertion¶
Type assertpath and press Tab:
Custom Snippets¶
Create your own snippets:
- Open Command Palette
- Run Preferences: Configure User Snippets
- Select berrycrush-scenario or berrycrush-fragment
- Add your snippet
Example custom snippet:
{
"Auth Flow": {
"prefix": "authflow",
"body": [
"given user authenticates",
" include login"
],
"description": "Authentication flow include"
}
}
Tips¶
- Use Tab to cycle through placeholders
- Use Shift+Tab to go back
- Use Escape to exit snippet mode
- Placeholders can have default values:
${1:default} - Placeholders can have choices:
${1|option1,option2,option3|}
Related Features¶
- Completion - Auto-completion suggestions
- Formatting - Format snippet output