Skip to content

Instantly share code, notes, and snippets.

@davisford
Last active December 21, 2018 22:34
Show Gist options
  • Save davisford/972a5bbb160575bd7efba144b001ab43 to your computer and use it in GitHub Desktop.
Save davisford/972a5bbb160575bd7efba144b001ab43 to your computer and use it in GitHub Desktop.
ginkgo cheatsheet

FYI: I install ginkgo into $HOME/gocode. My .bash_profile does this:

export GOPATH=$HOME/gocode
export PATH=$PATH:$GOPATH/bin

And I do a custom GOPATH per project. I don't like global GOPATH for all projects. So on projectx, I have to cd projectx && export GOPATH=$(pwd):$GOPATH for example. It is a minor inconvenience, but I think it is cleaner.

This means, I want to install binaries like ginkgo into my global GOPATH and not necessarily my project path. Hope that makes sense.

Anyway, ginkgo has a lot of switches and options. Almost everything it does is directory context dependent (remember that).

It looks for suites in a dir to run

To generate a new suite

cd projectx/src/packagey && ginkgo bootstrap

This will generate a new packagey_test_suite.go

To generate a new test file for a go file

Do this after you create the suite above. For example the file foo.go

ginkgo generate foo

This will generate the file foo_test.go

To run packagey tests

In the packagey dir

ginkgo

Alternatively, have more verbose output (I use this)

ginkgo -v

Sometimes I add the race detector

ginkgo -v -race

To have it watch file saves and run on change

All the same above except you give it the watch command, e.g.:

ginkgo watch -v

To run only the foo.go tests in packagey

Sometimes you want to watch just your file tests in a loop as you develop:

This assumes you have the following suite named "Foo" in foo_test.go

Describe("Foo", func() {

})
ginkgo watch -v -focus Foo  # it matches the name on regex

To run all tests recursively downward

Step up to the top level dir, of project, for instance and want to run all package tests

gingkgo -R .
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment