tables-and-dynamic-specs
What it does
This skill shows how to write one Ginkgo test pattern that runs with many different sets of input values. It is for developers who have many similar tests in Go.
When to use it
- βWhen you have many similar Go tests that differ only by their input values.
- βWhen you want to turn a list of test cases into separate Ginkgo tests.
- βWhen you need to load test data from files before a Ginkgo suite starts.
Skill link
https://github.com/onsi/ginkgo/blob/master/plugins/ginkgo/skills/tables-and-dynamic-specs/SKILL.mdCopy it and paste it into your AI (Claude, ChatGPT or Cursor), asking it to follow the instructions.
How to use
The easiest way: copy the message and paste it into your AI. It reads the skill and follows the instructions.
Ready-to-paste message
For Claude Code, Codex or Cursor: run it in your project folder and the skill gets installed.
Download the SKILL.md and drop it into your agentβs skills folder.
Example of what to ask your AI
βI have twenty similar Go tests with different inputs, can you combine them into one table-style Ginkgo test?β
5 new skills a week. 1 minute to read.
How it works
It uses a table where each row is one test case with its own inputs and name, so the test code is written only once.
Technical content (original SKILL.md)
Original text by the author, straight from GitHub.
Table specs and dynamically generated specs
Ginkgo gives you a DSL for table-driven specs plus idioms for generating specs from loops and data. All of it is syntactic sugar that runs during the tree-construction phase (ginkgo:overview) β the gotchas all follow from that.
Perfer DescrtibeTable/DescribeTableSubtree with shared configuration over multiple repeated Its.
Docs: https://onsi.github.io/ginkgo/#table-specs.
DescribeTable + Entry
DescribeTable(desc, specFunc, ...Entry) generates one container holding one It per Entry. Entry(desc, params...) β its params are passed to specFunc at run time and must match specFunc's signature (you get a clear runtime message if they don't).
DescribeTable("Extracting the author's first and last name",
func(author string, isValid bool, firstName, lastName string) {
book := &books.Book{Title: "My Book", Author: author, Pages: 10}
Expect(book.IsValid()).To(Equal(isValid))
Expect(book.AuthorFirstName()).To(Equal(firstName))
Expect(book.AuthorLastName()).To(Equal(lastName))
},
Entry("both names", "Victor Hugo", true, "Victor", "Hugo"),
Entry("one name", "Hugo", true, "", "Hugo"),
Entry("no name", "", false, "", ""),
)
A DescribeTable is just a container, so nest it inside Describe/Context and surround it with BeforeEach β setup runs fresh before each entry's spec.
THE gotcha: Entry params are evaluated at construction time
Entry(...) arguments are evaluated when the tree is built β before any BeforeEach has run. So an Entry cannot read a variable initialized in BeforeEach; it will see the zero value (a nil map/pointer).
var shelf map[string]*books.Book
BeforeEach(func() { shelf = loadShelf() }) // runs at RUN time
// WRONG β shelf is nil when Entry is evaluated at construction time
DescribeTable("category", func(b *books.Book, c books.Category) { ... },
Entry("novel", shelf["Les Miserables"], books.CategoryNovel), // nil pointer!
)
// RIGHT β pass a key, dereference shelf inside the spec closure (run time)
DescribeTable("category", func(key string, c books.Category) {
Expect(shelf[key].Category()).To(Equal(c))
},
Entry("novel", "Les Miserables", books.CategoryNovel),
)
The four ways to describe an Entry
| Mechanism | How |
|---|---|
| Explicit string | Entry("both names", ...) |
nil |
Entry(nil, 1, 2, 3) β auto-named from params: Entry: 1, 2, 3 |
| Table-level description closure | pass func(a,b,c int) string {...} as 3rd arg to DescribeTable; renders every nil entry |
EntryDescription(fmt) |
EntryDescription("%d + %d = %d") as 3rd arg to DescribeTable, or per-entry |
The description closure must return string and accept the same params as specFunc. Per-entry, the first arg may itself be a closure or EntryDescription (overrides the table default):
DescribeTable("addition", func(a, b, c int) { Expect(a + b).To(Equal(c)) },
EntryDescription("%d + %d = %d"), // table default
Entry(nil, 1, 2, 3), // "1 + 2 = 3"
Entry("zeros", 0, 0, 0), // explicit
Entry(EntryDescription("%[3]d = %[1]d + %[2]d"), 10, 100, 110), // per-entry override
Entry(func(a, b, c int) string { return fmt.Sprintf("%d = %d", a+b, c) }, 4, 3, 7),
)
Decorating entries
Entry and DescribeTable accept every decorator (β ginkgo:decorators): Entry("flaky case", FlakeAttempts(3), ...), Entry(..., Label("slow")). Focus/pending shortcuts: FEntry / PEntry / XEntry (and FDescribeTable / PDescribeTable). PEntry needs no params; focus/pending obey the same precedence as everywhere else (β ginkgo:filtering).
DescribeTableSubtree β many Its per row
When you want a whole subtree (multiple Its, their own setup) per entry, use DescribeTableSubtree. Its body runs at construction time, once per entry, inside a fresh container β you must place Its inside it or no specs are generated:
DescribeTableSubtree("handling requests",
func(url string, code int, message string) {
var resp *http.Response
BeforeEach(func() {
var err error
resp, err = http.Get(url)
Expect(err).NotTo(HaveOccurred())
DeferCleanup(resp.Body.Close)
})
It("returns the status code", func() { Expect(resp.StatusCode).To(Equal(code)) })
It("returns the message", func() {
body, _ := io.ReadAll(resp.Body)
Expect(string(body)).To(E
FAQ
Why are my table test names not working?
The skill explains that each row's inputs must match the test function's inputs, and it gives tips on naming rows.
Can I run only some rows of a table?
Yes, the skill covers marking rows to focus on or to skip while you work.
Is this easier to maintain than separate tests?
It keeps the shared setup in one place, so changes are made once instead of many times.
Details
Original description by the author
Parameterize and generate Ginkgo specs β DescribeTable/Entry table-driven specs, Entry descriptions (string, nil, closure, EntryDescription), PEntry/FEntry and per-Entry decorators, DescribeTableSubtree, generating specs in a construction-time loop, loading fixtures in TestXxx before RunSpecs, and shared-behavior closures. Use when you have repetitive specs differing only by inputs, want data-driven or generated specs, or are extracting reusable It blocks across Contexts.
repo: onsi/ginkgo
Popularity
- GitHub stars
- 9.1k
- Ranking position
- #12308
- License
- MIT
- Updated
- 10/9/2026
Comments
- β¦
More skills from this repository
ci
9.1kHelps your agent set up Ginkgo tests for continuous integration, with recommended flags that catch leftover focus or pending markers and flaky tests.
debugging-failures
9.1kHelps your agent find out why Ginkgo tests failed by reading the summary line and pulling the exact failing tests and messages from a JSON report.
decorators
9.1kHelps your agent use Ginkgo test decorators correctly, such as Serial, Ordered, Label, Focus and timeouts, by explaining what each one does.
filtering
9.1kHelps your agent run only some Ginkgo tests, using pending, skip, focus, labels, version constraints and file filters in the right order of precedence.
Similar skills
test-driven-development
311kTeaches your agent to write a failing test first, watch it fail, then write the smallest code that passes, before building any feature or fix.
verification-before-completion
311kTeaches your agent to run real checks and read their output before claiming that a task, fix, or build is complete or passing.
migrate-to-shoehorn
310kReplaces risky type casts in your test files with the shoehorn library, so tests can use partial data and still pass type checks.