-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshellspec-cheatsheet.txt
More file actions
77 lines (62 loc) · 2.41 KB
/
shellspec-cheatsheet.txt
File metadata and controls
77 lines (62 loc) · 2.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# 📑 ShellSpec Syntax Reference
# Comments
# Comment (visible in output)
$. cmd args # Trailing comment on commands
# Test Cases
> Test case description
# Snippets
>@ snippet_name # define reusable snippet
:. @ snippet_name # invoke snippet
# Shell Commands
$. cmd args # run command, expect success (exit 0)
$! cmd args # run command, expect failure (non-zero exit)
# Pexpect Process Interaction
$< expected text # expect("expected test") - text is a regex, escape special chars
$> input text # sendline("input test")
# Assertions
?. stdout "text" # stdout must contain "text"
?! stdout "text" # stdout must NOT contain "text"
?. stderr "text" # stderr must contain "text"
?! stderr "text" # stderr must NOT contain "text"
?. file "path" # file must exist
?! file "path" # file must not exist
?. file "path" "content" # file must contain substring
# Exact file content check:
?. file "path"
.. line one
.. line two
# Variable Operations
:. stdout @var # store stdout in variable @var
:. stderr @var # store stderr in variable @var
?. == @var "value" # check variable equals value
?. != @var1 @var2 # check variables are different
?. startswith @var "prefix"
?. endswith @var "suffix"
?. contains @var "substring"
# File Creation
:. file "path" [mode] # create file with optional octal mode
.. line content # append line to file
.. another line # append another line
# Environment Variables
:. env FOO "bar" # set environment variable FOO to "bar"
:. env FOO @my_var # set environment variable from @my_var
# Content Lines
# .. content append to previous :. command
# used for file content or exact assertions
# Example Usage
>@ setup_user
$. age-store.py init-user --unencrypted
$. age-store.py admin bootstrap user1
> Test file operations with variables
:. @ setup_user # invoke setup snippet
$. age-store.py show-pubkey
:. stdout @user_pubkey # store pubkey in @user_pubkey variable
:. file test.txt # create test file
.. Hello world
.. Second line
$. age-store.py add test.txt # add file with comment
?. file "test.txt.enc" # verify encrypted file exists
$. age-store.py view test.txt
?. stdout "Hello world" # verify content
$. age-store.py admin add-user newuser @user_pubkey # use variable in command
?. == @user_pubkey @user_pubkey # compare variables