How do I get the text of describe during runtime?
For example, I have a code like this
var _ = Describe("Foo Bar test", func() {
JustBeforeEach(func() {
fmt.Println(<name of the text in describe>) // Foo Bar test
}
}
How do I extract Foo Bar test whenever I need it during runtime, so that I can use it in the logs to print it.
Hey you can do this:
var _ = Describe("Foo Bar test", func() {
JustBeforeEach(func() {
report := CurrentSpecReport()
fmt.Println(report.ContainerHierarchyTexts[0]) // Foo Bar test
}
}
More details here:
https://pkg.go.dev/github.com/onsi/ginkgo/[email protected]/types#SpecReport
note that report.FullText() will give you the fully concatenated text (i.e. all containers + the It text). and ContainerHierarchyTexts is a slice of strings for each container
Thank you @onsi. Can you please point me to similar thing in v1.16.5
You can use CurrentGinkgoTestDescription() - but I strongly recommend upgrading to V2. V1 is no longer supported and V2 has improved in many many ways. The migration guide is here and I'd be happy to help answer questions and resolve any issues you hit.