-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcore.bats
More file actions
72 lines (52 loc) · 1.77 KB
/
Copy pathcore.bats
File metadata and controls
72 lines (52 loc) · 1.77 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
#!/usr/bin/env bats
load ../../test_helper.bash
setup() {
setup_test_environment
eval "$(declare -f run | sed '1s/^run /bats_run /')"
source_libs stepdef/pattern stepdef/parse user_helpers/run user_helpers/fail step/core
STEPDEF_TYPES=()
STEPDEF_PATTERNS=()
STEPDEF_REGEXES=()
STEPDEF_TOKENS_LIST=()
STEPDEF_BODIES=()
LAST_EXIT_CODE=
LAST_STDOUT=
LAST_STDERR=
FAIL_MESSAGE=
STEP_RESULT=
}
teardown() {
teardown_test_environment
}
@test "step_run matches a step definition and runs its body" {
stepdef_parse "@When I run '{command}'"
stepdef_register 'run "$command"'
step_run When "I run 'printf hello'"
[ "$LAST_EXIT_CODE" -eq 0 ]
[ "$LAST_STDOUT" = "hello" ]
[ -z "$LAST_STDERR" ]
}
@test "step_run binds multiple tokens in declaration order" {
stepdef_parse "@When I copy {source} to {destination}"
stepdef_register 'STEP_RESULT="$source:$destination"'
step_run When "I copy left.txt to right.txt"
[ "$STEP_RESULT" = "left.txt:right.txt" ]
}
@test "step_run returns non-zero when no step definition matches" {
stepdef_parse "@When I run '{command}'"
stepdef_register 'run "$command"'
! step_run Then "the file 'somefile' should exist"
[ "$FAIL_MESSAGE" = $'No matching step definition for:\nThen the file '\''somefile'\'' should exist' ]
}
@test "step_run returns the body status when the body fails" {
stepdef_parse "@Then the command should fail"
stepdef_register 'return 7'
bats_run step_run Then "the command should fail"
[ "$status" -eq 7 ]
}
@test "step_run exposes a custom failure message from fail" {
stepdef_parse "@Then the output should include '{text}'"
stepdef_register 'fail "invalid output detected"'
! step_run Then "the output should include 'hello'"
[ "$FAIL_MESSAGE" = "invalid output detected" ]
}