Reset tmpDir in gexec.CleanupBuildArtifacts If tmpDir is not being reset, subsequent calls to gexec.Build will fail. This is a problem when Build and CleanupBuildArtifacts are being used in BeforeEach and AfterEach blocks that are being executed multiple times.
diff --git a/gexec/build.go b/gexec/build.go index 3e9bf9f..25b7d51 100644 --- a/gexec/build.go +++ b/gexec/build.go
@@ -62,6 +62,7 @@ func CleanupBuildArtifacts() { if tmpDir != "" { os.RemoveAll(tmpDir) + tmpDir = "" } }
diff --git a/gexec/build_test.go b/gexec/build_test.go new file mode 100644 index 0000000..7bd62fe --- /dev/null +++ b/gexec/build_test.go
@@ -0,0 +1,37 @@ +package gexec_test + +import ( + . "github.com/onsi/ginkgo" + . "github.com/onsi/gomega" + "github.com/onsi/gomega/gexec" +) + +var _ = Describe(".Build", func() { + var packagePath = "./_fixture/firefly" + + Context("when there have been previous calls to Build", func() { + BeforeEach(func() { + _, err := gexec.Build(packagePath) + Ω(err).ShouldNot(HaveOccurred()) + }) + + It("compiles the specified package", func() { + compiledPath, err := gexec.Build(packagePath) + Ω(err).ShouldNot(HaveOccurred()) + Ω(compiledPath).Should(BeAnExistingFile()) + }) + + Context("and CleanupBuildArtifacts has been called", func() { + BeforeEach(func() { + gexec.CleanupBuildArtifacts() + }) + + It("compiles the specified package", func() { + var err error + fireflyPath, err = gexec.Build(packagePath) + Ω(err).ShouldNot(HaveOccurred()) + Ω(fireflyPath).Should(BeAnExistingFile()) + }) + }) + }) +})