-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexpectation.repeat_test.go
152 lines (140 loc) · 3.26 KB
/
expectation.repeat_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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
package testkit_test
import (
"github.com/dogmatiq/dogma"
. "github.com/dogmatiq/enginekit/enginetest/stubs"
"github.com/dogmatiq/testkit"
. "github.com/dogmatiq/testkit"
"github.com/dogmatiq/testkit/internal/testingmock"
g "github.com/onsi/ginkgo/v2"
gm "github.com/onsi/gomega"
)
var _ = g.Describe("func ToRepeatedly()", func() {
var (
testingT *testingmock.T
app dogma.Application
test *Test
)
g.BeforeEach(func() {
testingT = &testingmock.T{
FailSilently: true,
}
app = &ApplicationStub{
ConfigureFunc: func(c dogma.ApplicationConfigurer) {
c.Identity("<app>", "259ae495-fcef-43e2-986a-ea6b82f65fcd")
},
}
test = testkit.Begin(testingT, app)
})
g.DescribeTable(
"expectation behavior",
func(
e Expectation,
ok bool,
rm reportMatcher,
) {
test.Expect(noop, e)
rm(testingT)
gm.Expect(testingT.Failed()).To(gm.Equal(!ok))
},
g.Entry(
"it passes when all of the repeated expectations pass",
ToRepeatedly(
"<description>",
2,
func(i int) Expectation {
switch i {
case 0:
return pass
case 1:
return pass
default:
panic("unexpected index")
}
},
),
expectPass,
expectReport(
`✓ <description>`,
),
),
g.Entry(
"it fails when any of the repeated expectations fail",
ToRepeatedly(
"<description>",
2,
func(i int) Expectation {
switch i {
case 0:
return pass
case 1:
return fail
default:
panic("unexpected index")
}
},
),
expectFail,
expectReport(
`✗ <description> (1 of 2 iteration(s) failed, iteration #1 shown)`,
` ✗ <always fail>`,
),
),
g.Entry(
"it fails when all of the repeated expectations fail",
ToRepeatedly(
"<description>",
2,
func(i int) Expectation {
switch i {
case 0:
return fail
case 1:
return fail
default:
panic("unexpected index")
}
},
),
expectFail,
expectReport(
`✗ <description> (2 of 2 iteration(s) failed, iteration #0 shown)`,
` ✗ <always fail>`,
),
),
)
g.It("produces the expected caption", func() {
test.Expect(
noop,
ToRepeatedly(
"<description>",
1,
func(i int) Expectation {
return pass
},
),
)
gm.Expect(testingT.Logs).To(gm.ContainElement(
"--- expect [no-op] to <description> ---",
))
})
g.It("panics if the description is empty", func() {
gm.Expect(func() {
ToRepeatedly("", 1, func(i int) Expectation { return nil })
}).To(gm.PanicWith(`ToRepeatedly("", 1, <func>): description must not be empty`))
})
g.It("panics if the count is zero", func() {
gm.Expect(func() {
ToRepeatedly("<description>", 0, func(i int) Expectation { return nil })
}).To(gm.PanicWith(`ToRepeatedly("<description>", 0, <func>): n must be 1 or greater`))
})
g.It("panics if the count is negative", func() {
gm.Expect(func() {
ToRepeatedly("<description>", -1, func(i int) Expectation { return nil })
}).To(gm.PanicWith(`ToRepeatedly("<description>", -1, <func>): n must be 1 or greater`))
})
g.It("panics if the function is nil", func() {
gm.Expect(func() {
ToRepeatedly("<description>", 1, nil)
}).To(gm.PanicWith(`ToRepeatedly("<description>", 1, <nil>): function must not be nil`))
})
})