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
|
package internal_test
import (
"context"
. "github.com/onsi/ginkgo/v2"
"github.com/onsi/ginkgo/v2/internal"
. "github.com/onsi/gomega"
)
var _ = Describe("SpecContext", func() {
It("allows access to the current spec report", func(c SpecContext) {
Ω(c.SpecReport().LeafNodeText).Should(Equal("allows access to the current spec report"))
})
It("can be wrapped and still retrieved", func(c SpecContext) {
Ω(c.Value("GINKGO_SPEC_CONTEXT")).Should(Equal(c))
wrappedC := context.WithValue(c, "foo", "bar")
_, ok := wrappedC.(SpecContext)
Ω(ok).Should(BeFalse())
Ω(wrappedC.Value("GINKGO_SPEC_CONTEXT").(SpecContext).SpecReport().LeafNodeText).Should(Equal("can be wrapped and still retrieved"))
})
It("can attach and detach progress reporters", func(c SpecContext) {
type CompleteSpecContext interface {
AttachProgressReporter(func() string) func()
QueryProgressReporters(ctx context.Context, failer *internal.Failer) []string
}
wrappedC := context.WithValue(c, "foo", "bar")
ctx := wrappedC.Value("GINKGO_SPEC_CONTEXT").(CompleteSpecContext)
Ω(ctx.QueryProgressReporters(context.Background(), nil)).Should(BeEmpty())
cancelA := ctx.AttachProgressReporter(func() string { return "A" })
Ω(ctx.QueryProgressReporters(context.Background(), nil)).Should(Equal([]string{"A"}))
cancelB := ctx.AttachProgressReporter(func() string { return "B" })
Ω(ctx.QueryProgressReporters(context.Background(), nil)).Should(Equal([]string{"A", "B"}))
cancelC := ctx.AttachProgressReporter(func() string { return "C" })
Ω(ctx.QueryProgressReporters(context.Background(), nil)).Should(Equal([]string{"A", "B", "C"}))
cancelB()
Ω(ctx.QueryProgressReporters(context.Background(), nil)).Should(Equal([]string{"A", "C"}))
cancelA()
Ω(ctx.QueryProgressReporters(context.Background(), nil)).Should(Equal([]string{"C"}))
cancelC()
Ω(ctx.QueryProgressReporters(context.Background(), nil)).Should(BeEmpty())
})
})
|