In my code snippet below or https://play.golang.org/p/tLld-zNF2zp, testValue was declared inside Describe block, changed in BeforeEach block. Then, used in.
ItExpect
The test passes as expected. From the debug log, It always shows testValue should be 0 instead of testValue should be 3
package awesomeProject1_test
import (
"fmt"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("AwesomeProject1", func() {
var testValue int
BeforeEach(func() {
testValue = 3
})
Context("Correctness of testValue", func() {
It(fmt.Sprintf("testValue should be %d", testValue), func() {
Expect(testValue).To(Equal(3))
})
})
})
Why is testValue not changed in It statement but inside it?
From ginkgo docs, another
DescribewrapsContextfunctions :