petergtz / pegomock

Pegomock is a powerful, yet simple mocking framework for the Go programming language
Apache License 2.0
253 stars 28 forks source link

Usage with Ginkgo should be simpler #71

Closed petergtz closed 5 years ago

petergtz commented 5 years ago

Right now, using dot-imports with both pegomock and Ginkgo leads to a name collision for the When function. To solve the issue, one can use Ginkgo's --nodot option which will make Describe/Context/It/When and friends available without dot-importing Ginkgo. Afterwards, it's easy to remove all the When aliases from test files. However, it's still an annoying extra step.

Proposals

Providing another name for When in pegomock

We'd introduce a Whenever function which does exactly the same as When, just has a different name. It would look like this:

package some_test

import (
    . github.com/petergtz/pegomock/ginkgo_compatible
)

...

Whenever(mymock.SomeFunc(EqString("some param")).ThenReturn("some value")

Use package selector for When, but not for pegomock matchers

package some_test

import (
    . github.com/petergtz/pegomock/ginkgo_compatible/matchers
    github.com/petergtz/pegomock/ginkgo_compatible/mock
)

...

mock.When(mymock.SomeFunc(EqString("some param"))).ThenReturn("some value")
MissingRoberto commented 5 years ago

You found the right word 👍