Skip to content

Commit 1f37e2b

Browse files
After each (#6)
1 parent d26a3ae commit 1f37e2b

File tree

4 files changed

+43
-2
lines changed

4 files changed

+43
-2
lines changed

nuunit.nu

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ export def discover-tests [module testImportScript] {
5555
before each
5656
}
5757
| ($it.item)
58+
| if (scope commands | where name == "after each" | is-empty) {
59+
null
60+
} else {
61+
after each
62+
}
5863
} catch {|err|
5964
print -e $err.debug
6065
exit 1

test-spec.nu

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,14 @@ export def "test that the before each passes context to a test" [] {
106106
| verify json results
107107
}
108108

109+
export def "test that the after each passes context to a test" [] {
110+
use tests/test-spec-with-after-each.nu "verify json results"
111+
let specFile = "tests/test-spec-with-after-each.nu"
112+
113+
run-test-spec $specFile
114+
| verify json results
115+
}
116+
109117
def run-test-spec [specFile] {
110118
(^$nu.current-exe --no-config-file nuunit.nu --test-spec-module-name $specFile --as-json)
111119
| from json

tests/test-spec-with-after-each.nu

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
2+
export def "test that after each gets context from test" [] {
3+
let context = { some: stuff, that: is, useful: for, multiple: tests }
4+
$context
5+
}
6+
7+
export def "test that after each context gets passed to multiple tests" [] {
8+
let context = { some: stuff, that: is, useful: for, multiple: tests }
9+
$context
10+
}
11+
12+
export def "after each" [] {
13+
let actual = $in
14+
let expected = { some: stuff, that: is, useful: for, multiple: tests }
15+
use std assert
16+
17+
print "after each happened"
18+
19+
assert equal $expected $actual
20+
}
21+
22+
export def "verify json results" [] {
23+
let results = $in
24+
use std assert
25+
26+
assert ($results | get exit_code | all {|it| $it == 0})
27+
assert ($results | get stdout | all {|it| $it =~ "after each happened"})
28+
}
29+

tests/test-spec-with-before-each.nu

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ export def "verify json results" [] {
2424
let results = $in
2525
use std assert
2626

27-
print ($results | get stdout)
28-
assert equal 0 ($results | get exit_code | first)
27+
assert ($results | get exit_code | all {|it| $it == 0})
2928
}
3029

0 commit comments

Comments
 (0)