onsi / ginkgo

A Modern Testing Framework for Go
http://onsi.github.io/ginkgo/
MIT License
8.22k stars 650 forks source link

Passing GinkgoT to GoMock results in an error #1239

Open caldempsey opened 1 year ago

caldempsey commented 1 year ago

Yo,

When using Gomock with Ginkgo and calling ctrl := gomock.NewController(GinkgoT()) I get:

golang/mock@v1.6.0/gomock/controller.go:137
  You must call DeferCleanup inside a setup node (e.g. BeforeEach, BeforeSuite,
  AfterAll...) or a subject node (i.e. It).  You can't call DeferCleanup at the
  top-level or in a container node - use the After* family of setup nodes
  instead.

As a result I am doing ctrl := gomock.NewController(&testing.T{}) for now but this does mean that Ginkgo isn't passing the same test reporter to the Gomock controller.

Is there a fix for this?

onsi commented 1 year ago

The docs touch on how to use gomock with ginkgo here: https://onsi.github.io/ginkgo/#using-third-party-libraries

can you share some more detail? where are you calling gomock.NewController? can you share some more code/context?

caldempsey commented 1 year ago

hi onsi

thanks for getting back!

i will post some code when im in work next week

the cool thing about chatgpt is i can anonymise our code with ease, fancy that eh