-
Notifications
You must be signed in to change notification settings - Fork 1
/
lib_test.go
75 lines (62 loc) · 1.53 KB
/
lib_test.go
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
package ensure
import (
"context"
"github.com/stretchr/testify/require"
"testing"
)
type testPrinter struct {
entries []string
}
func (t *testPrinter) Write(s string) {
t.entries = append(t.entries, s)
}
func (t *testPrinter) Output() string {
var output string
for _, entry := range t.entries {
output += entry + "\n"
}
return output
}
func init() {
Printer = &testPrinter{}
}
func TestFullScenario(t *testing.T) {
var (
testCtx = context.Background()
aThing bool
anotherThing bool
tornDown = false
)
That("A full scenario runs as expected", func(s *Scenario) {
s.Given("a thing is false", func() {
aThing = false
})
s.And("another thing is true", func() {
anotherThing = true
}).Teardown("revert anotherThing", testCtx, func(ctx context.Context) {
anotherThing = false
})
s.When("I do the old swaperoo", func() {
aThing = true
anotherThing = false
})
s.Then("the a thing should be true", func() {
require.Equal(t, true, aThing)
})
s.And("anotherThing should be false", func() {
require.Equal(t, false, anotherThing)
}).Teardown("tearDown", testCtx, func(ctx context.Context) {
tornDown = true
})
}, t)
require.True(t, tornDown)
require.Equal(t, `Scenario: A full scenario runs as expected
Given a thing is false
And another thing is true
When I do the old swaperoo
Then the a thing should be true
And anotherThing should be false
Tearing down revert anotherThing
Tearing down tearDown
`, Printer.(*testPrinter).Output(), "output should be as expected")
}