tables-and-dynamic-specs
하는 일
이 스킬은 입력값만 다른 여러 테스트를 하나의 Ginkgo 테스트 패턴으로 실행하는 방법을 보여 줍니다. 비슷한 Go 테스트가 많은 개발자를 위한 것입니다.
사용하는 경우
- ✓입력값만 다른 비슷한 Go 테스트가 많을 때.
- ✓테스트 사례 목록을 별도의 Ginkgo 테스트로 바꾸고 싶을 때.
- ✓Ginkgo 묶음이 시작하기 전에 파일에서 테스트 데이터를 불러와야 할 때.
스킬 링크
https://github.com/onsi/ginkgo/blob/master/plugins/ginkgo/skills/tables-and-dynamic-specs/SKILL.md복사해서 AI(Claude, ChatGPT, Cursor)에 붙여넣고 지침을 따르도록 요청하세요.
사용 방법
가장 쉬운 방법입니다. 메시지를 복사해 AI에 붙여넣으세요. AI가 스킬을 읽고 지침을 따릅니다.
바로 붙여넣을 수 있는 메시지
Claude Code, Codex, Cursor용입니다. 프로젝트 폴더에서 실행하면 스킬이 설치됩니다.
SKILL.md를 다운로드해 에이전트의 스킬 폴더에 넣으세요.
AI에게 요청하는 예시
“입력값만 다른 비슷한 Go 테스트가 스무 개 있습니다. 이것을 하나의 표 형식 Ginkgo 테스트로 합쳐 주세요.”
매주 새 스킬 5개. 읽는 데 1분.
작동 방식
이 스킬은 각 행이 고유한 입력값과 이름을 가진 하나의 테스트 사례인 표를 씁니다. 그래서 테스트 코드는 한 번만 작성됩니다.
기술 내용 (원본 SKILL.md)
작성자의 영어 원문을 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
자주 묻는 질문
표 테스트의 이름이 왜 작동하지 않나요?
각 행의 입력값이 테스트 함수의 입력과 맞아야 하며, 이 스킬은 행 이름을 붙이는 요령도 알려 줍니다.
표의 일부 행만 실행할 수 있나요?
네. 작업하는 동안 특정 행에 focus를 두거나 건너뛰도록 표시하는 방법을 다룹니다.
별도의 테스트보다 관리하기 쉬운가요?
네. 공통 설정을 한 곳에 두므로, 변경할 때 여러 번이 아니라 한 번만 고치면 됩니다.
상세 정보
작성자의 원본 설명
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
인기도
- GitHub 스타
- 9.1k
- 순위
- #12308
- 라이선스
- MIT
- 업데이트
- 2026. 10. 9.
댓글
- …
이 저장소의 다른 스킬
ci
9.1k에이전트가 지속적 통합에서 Ginkgo 테스트를 설정하도록 돕습니다. 남은 focus나 pending 표시와 불안정한 테스트를 잡아내는 권장 플래그를 씁니다.
debugging-failures
9.1k에이전트가 요약 줄을 읽고 JSON 보고서에서 실패한 정확한 테스트와 메시지를 꺼내서, Ginkgo 테스트가 왜 실패했는지 알아내도록 돕습니다.
decorators
9.1k에이전트가 Serial, Ordered, Label, Focus, 제한 시간 같은 Ginkgo 테스트 데코레이터를 바르게 쓰도록 각각의 역할을 설명해 돕습니다.
filtering
9.1k에이전트가 pending, skip, focus, 라벨, 버전 조건, 파일 필터를 올바른 우선순위에 따라 써서 Ginkgo 테스트의 일부만 실행하도록 돕습니다.
비슷한 스킬
test-driven-development
311k에이전트가 기능이나 수정을 만들기 전에 실패하는 테스트를 먼저 쓰고, 그것을 통과시키는 가장 작은 코드를 작성하도록 가르칩니다.
verification-before-completion
311k에이전트가 작업, 수정, 빌드가 완료되었거나 통과했다고 말하기 전에 실제 점검을 실행하고 결과를 읽도록 가르칩니다.
migrate-to-shoehorn
310k테스트 파일의 위험한 타입 캐스팅을 shoehorn 라이브러리로 바꿔, 테스트가 일부 데이터만 써도 타입 검사를 통과하도록 돕습니다.