franela / goblin

Minimal and Beautiful Go testing framework
MIT License
887 stars 79 forks source link

Assertion redeclared during import w/ Gomega #88

Closed speakingcode closed 4 years ago

speakingcode commented 4 years ago
package foo

import (
    "testing"
    . "github.com/onsi/gomega"
    . "github.com/franela/goblin"
)

trying to run go test produces the following error:

./foo_test.go:6:5: Assertion redeclared during import "github.com/franela/goblin"
        previous declaration during import "github.com/onsi/gomega"
FAIL    foo/foo [build failed]

go.mod

module foo/foo

go 1.14

require (
    github.com/franela/goblin v0.0.0-20200611003024-99f9a98191cf
    github.com/onsi/gomega v1.10.1
        ...
)
Neirpyc commented 4 years ago

Maybe it's an import alias issue. Does this code solves your problem?

package foo

import (
    "testing"
    "github.com/onsi/gomega"
    . "github.com/franela/goblin"
)
speakingcode commented 4 years ago

That works but then calls to all of the imported functions from Gomega (Expect, Equal, RegisterFailHandler, etc) must be prepended. What I ended up doing is:

package foo

import (
   "testing"
   . "github.com/onsi/gomega"
   gob "github.com/franela/goblin"
)

func TestFoo(t *testing.T) {
    g := gob.Goblin(t)
   ...

I'll make a PR with the doc fixed.