Skip to content

Commit

Permalink
Ensure generated test file names are underscored
Browse files Browse the repository at this point in the history
  • Loading branch information
Callisto13 authored and williammartin committed Dec 5, 2018
1 parent c195187 commit 505cc35
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
14 changes: 10 additions & 4 deletions ginkgo/generate_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,8 @@ func generateSpec(args []string, agouti, noDot, internal bool) {
func generateSpecForSubject(subject string, agouti, noDot, internal bool) error {
packageName, specFilePrefix, formattedName := getPackageAndFormattedName()
if subject != "" {
subject = strings.Split(subject, ".go")[0]
subject = strings.Split(subject, "_test")[0]
specFilePrefix = subject
formattedName = prettifyPackageName(subject)
specFilePrefix = formatSubject(subject)
formattedName = prettifyPackageName(specFilePrefix)
}

data := specData{
Expand Down Expand Up @@ -152,6 +150,14 @@ func generateSpecForSubject(subject string, agouti, noDot, internal bool) error
return nil
}

func formatSubject(name string) string {
name = strings.Replace(name, "-", "_", -1)
name = strings.Replace(name, " ", "_", -1)
name = strings.Split(name, ".go")[0]
name = strings.Split(name, "_test")[0]
return name
}

func getPackageImportPath() string {
workingDir, err := os.Getwd()
if err != nil {
Expand Down
15 changes: 15 additions & 0 deletions integration/subcommand_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,21 @@ var _ = Describe("Subcommand", func() {
})
})

Context("with an argument of the form: foo-test", func() {
It("should generate a test file named after the argument", func() {
session := startGinkgo(pkgPath, "generate", "baz-buzz-test")
Eventually(session).Should(gexec.Exit(0))
output := session.Out.Contents()

Ω(output).Should(ContainSubstring("baz_buzz_test.go"))

content, err := ioutil.ReadFile(filepath.Join(pkgPath, "baz_buzz_test.go"))
Ω(err).ShouldNot(HaveOccurred())
Ω(content).Should(ContainSubstring("package foo_bar_test"))
Ω(content).Should(ContainSubstring(`var _ = Describe("BazBuzz", func() {`))
})
})

Context("with an argument of the form: foo_test.go", func() {
It("should generate a test file named after the argument", func() {
session := startGinkgo(pkgPath, "generate", "baz_buzz_test.go")
Expand Down

0 comments on commit 505cc35

Please sign in to comment.