@@ -112,6 +112,36 @@ var _ = Describe("Subcommand", func() {
112
112
Ω (content ).Should (ContainSubstring (`"binary"` ))
113
113
Ω (content ).Should (ContainSubstring ("// This is a foo_test test" ))
114
114
})
115
+
116
+ It ("should generate a bootstrap file using a template that contains functions when told to" , func () {
117
+ templateFile := filepath .Join (pkgPath , ".bootstrap" )
118
+ ioutil .WriteFile (templateFile , []byte (`package {{.Package}}
119
+
120
+ import (
121
+ {{.GinkgoImport}}
122
+ {{.GomegaImport}}
123
+
124
+ "testing"
125
+ "binary"
126
+ )
127
+
128
+ func Test{{.FormattedName}}(t *testing.T) {
129
+ // This is a {{.Package | repeat 3}} test
130
+ }` ), 0666 )
131
+ session := startGinkgo (pkgPath , "bootstrap" , "--template" , ".bootstrap" )
132
+ Eventually (session ).Should (gexec .Exit (0 ))
133
+ output := session .Out .Contents ()
134
+
135
+ Ω (output ).Should (ContainSubstring ("foo_suite_test.go" ))
136
+
137
+ content , err := ioutil .ReadFile (filepath .Join (pkgPath , "foo_suite_test.go" ))
138
+ Ω (err ).ShouldNot (HaveOccurred ())
139
+ Ω (content ).Should (ContainSubstring ("package foo_test" ))
140
+ Ω (content ).Should (ContainSubstring (`. "github.com/onsi/ginkgo"` ))
141
+ Ω (content ).Should (ContainSubstring (`. "github.com/onsi/gomega"` ))
142
+ Ω (content ).Should (ContainSubstring (`"binary"` ))
143
+ Ω (content ).Should (ContainSubstring ("// This is a foo_testfoo_testfoo_test test" ))
144
+ })
115
145
})
116
146
117
147
Describe ("nodot" , func () {
@@ -182,10 +212,10 @@ var _ = Describe("Subcommand", func() {
182
212
import (
183
213
{{if .IncludeImports}}. "github.com/onsi/ginkgo"{{end}}
184
214
{{if .IncludeImports}}. "github.com/onsi/gomega"{{end}}
185
-
215
+
186
216
{{if .ImportPackage}}"{{.PackageImportPath}}"{{end}}
187
217
)
188
-
218
+
189
219
var _ = Describe("{{.Subject}}", func() {
190
220
// This is a {{.Package}} test
191
221
})` ), 0666 )
@@ -203,6 +233,34 @@ var _ = Describe("Subcommand", func() {
203
233
Ω (content ).Should (ContainSubstring (`/foo_bar"` ))
204
234
Ω (content ).Should (ContainSubstring ("// This is a foo_bar_test test" ))
205
235
})
236
+
237
+ It ("should generate a test file using a template that contains functions" , func () {
238
+ templateFile := filepath .Join (pkgPath , ".generate" )
239
+ ioutil .WriteFile (templateFile , []byte (`package {{.Package}}
240
+ import (
241
+ {{if .IncludeImports}}. "github.com/onsi/ginkgo"{{end}}
242
+ {{if .IncludeImports}}. "github.com/onsi/gomega"{{end}}
243
+
244
+ {{if .ImportPackage}}"{{.PackageImportPath}}"{{end}}
245
+ )
246
+
247
+ var _ = Describe("{{.Subject}}", func() {
248
+ // This is a {{.Package | repeat 3 }} test
249
+ })` ), 0666 )
250
+ session := startGinkgo (pkgPath , "generate" , "--template" , ".generate" )
251
+ Eventually (session ).Should (gexec .Exit (0 ))
252
+ output := session .Out .Contents ()
253
+
254
+ Ω (output ).Should (ContainSubstring ("foo_bar_test.go" ))
255
+
256
+ content , err := ioutil .ReadFile (filepath .Join (pkgPath , "foo_bar_test.go" ))
257
+ Ω (err ).ShouldNot (HaveOccurred ())
258
+ Ω (content ).Should (ContainSubstring ("package foo_bar_test" ))
259
+ Ω (content ).Should (ContainSubstring (`. "github.com/onsi/ginkgo"` ))
260
+ Ω (content ).Should (ContainSubstring (`. "github.com/onsi/gomega"` ))
261
+ Ω (content ).Should (ContainSubstring (`/foo_bar"` ))
262
+ Ω (content ).Should (ContainSubstring ("// This is a foo_bar_testfoo_bar_testfoo_bar_test test" ))
263
+ })
206
264
})
207
265
208
266
Context ("with an argument of the form: foo" , func () {
0 commit comments