setup
ما الذي تفعله
تُظهر هذه المهارة كيفية إعداد إطار اختبار Ginkgo في مشروع Go من البداية. وهي مناسبة للمطورين الذين يضيفون اختبارات Ginkgo إلى مشروع لأول مرة.
متى تستخدمها
- ✓عندما تضيف اختبارات Ginkgo إلى مشروع Go لأول مرة.
- ✓عندما تحتاج إلى إنشاء ملف الاختبار الأولي لحزمة Ginkgo.
- ✓عندما تحتاج مكتبة اختبار موجودة لديك إلى العمل مع Ginkgo.
رابط المهارة
https://github.com/onsi/ginkgo/blob/master/plugins/ginkgo/skills/setup/SKILL.mdانسخه والصقه في الذكاء الاصطناعي الذي تستخدمه (Claude أو ChatGPT أو Cursor) واطلب منه اتباع التعليمات.
طريقة الاستخدام
أسهل طريقة: انسخ الرسالة والصقها في الذكاء الاصطناعي الذي تستخدمه. سيقرأ المهارة وينفّذ تعليماتها.
رسالة جاهزة للصق
لـ Claude Code أو Codex أو Cursor: شغّله داخل مجلد مشروعك وستُثبَّت المهارة.
نزّل ملف SKILL.md وضعه في مجلد مهارات وكيلك.
مثال على ما تطلبه من الذكاء الاصطناعي
“من فضلك أعدّ اختبارات Ginkgo في مشروع Go الخاص بي حتى أبدأ كتابتها.”
5 مهارات جديدة كل أسبوع. قراءة في دقيقة واحدة.
كيف تعمل
تثبّت المهارة أمر ginkgo والمكتبات، وتنشئ ملف الاختبار الأولي، وتوضح كيفية ربطه بنظام اختبار Go القياسي.
المحتوى التقني (ملف SKILL.md الأصلي)
النص الأصلي من المؤلف، مباشرة من GitHub.
Wiring Ginkgo into a suite
The one-time setup. For the mental model see ginkgo:overview; to start authoring see ginkgo:writing-specs. Docs: https://onsi.github.io/ginkgo/#getting-started.
1. Install the CLI and the libraries
go install github.com/onsi/ginkgo/v2/ginkgo # the `ginkgo` CLI binary → $GOBIN (put it on $PATH)
go get github.com/onsi/gomega/... # the Gomega matcher library
ginkgo version confirms the install. The CLI version must match the github.com/onsi/ginkgo/v2 version in your go.mod — re-run go install ... from the package to sync them. The current major version is v2; everything here assumes it. In CI, sidestep version drift by invoking the CLI via go run github.com/onsi/ginkgo/v2/ginkgo (→ ginkgo:ci).
On macOS, XProtect slows Ginkgo's per-package go test -c compiles dramatically — run spctl developer-mode enable-terminal and add your terminal under System Settings > Privacy & Security > Developer Tools.
2. Bootstrap the suite
From inside the package you want to test:
cd path/to/books
ginkgo bootstrap # generates books_suite_test.go
package books_test
import (
"testing"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)
func TestBooks(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Books Suite")
}
What each line buys you:
func TestBooks(t *testing.T)is the singlego testentry point. CallRunSpecsexactly once per process — Ginkgo errors if you call it twice (a niche multi-suite-per-process escape hatch exists viaextensions/globals.Reset(), seeginkgo:running).RegisterFailHandler(Fail)is the one line of glue connecting Gomega to Ginkgo: it tells Gomega to call Ginkgo'sFailon a failed assertion. Without dot-imports this readsgomega.RegisterFailHandler(ginkgo.Fail).RunSpecs(t, "Books Suite")builds the spec tree and runs it; let it drive*testing.Tfor you.
3. The _test package convention — and what it forces
ginkgo bootstrap puts the suite in package books_test, not package books. Go specially permits a *_test package to live in the same directory as the package it tests, compiled as a separate package. The consequence: your suite has no access to books's unexported internals — it must import and exercise the external API. That's deliberate, nudging you to test behavior, not implementation. (You may use plain package books for true white-box unit tests when you need the internals.)
4. Dot-imports and the alternatives
Ginkgo and Gomega are DSLs, so the docs dot-import both into the suite's namespace to read naturally. Recommend this strongly to the user. If they'd rather keep the global namespace clean:
- Alias the whole DSL (slight
g.stutter everywhere):import g "github.com/onsi/ginkgo/v2" var _ = g.Describe("Books", func() { g.It("works", func() {}) }) - Mix-and-match the
dslsubpackages — dot-import the parts you want, namespace the rest:
Available:import ( . "github.com/onsi/ginkgo/v2/dsl/core" // containers, setup, subjects, RunSpecs, By, GinkgoT "github.com/onsi/ginkgo/v2/dsl/decorators" // Label, Ordered, Serial, … ) var _ = It("core dot-imported", decorators.Label("namespaced decorator"), func() {})dsl/core,dsl/decorators,dsl/reporting(ReportAfterEach,AddReportEntry, …),dsl/table(DescribeTable,Entry). They re-export from the root package — no behavioral difference, purely namespacing. ginkgo bootstrap --nodotgenerates a no-dot bootstrap to start from.
5. Add spec files
ginkgo generate book # generates book_test.go with a top-level Describe + the books import
You can write specs directly in the suite file, but ginkgo generate <subject> scaffolds a per-file Describe in the same _test package. Now write specs → ginkgo:writing-specs.
6. Third-party libraries that want a *testing.T
Matcher and mocking libraries take a *testing.T (or testing.TB). Ginkgo has no real *testing.T per spec, so pass the seam instead:
GinkgoT()returns a value implementing every*testing.Tmethod — hand it to testify, gomock, etc.GinkgoTB()returns atesting.TB-satisfying wrapper for libraries that demand that interface (reach the inner viaGinkgoTBWrapper.GinkgoT).
assert.Equal(GinkgoT(), foo{}.Name(), "foo") // testify i
الأسئلة الشائعة
ما Gomega؟
Gomega مكتبة مرافقة توفر الفحوص التي تستخدمها اختبارات Ginkgo للتأكد من النتائج.
هل يجب أن تتطابق إصدارات Ginkgo؟
نعم، يجب أن يطابق أمر ginkgo نسخة Ginkgo المذكورة في ملف go.mod الخاص بالمشروع.
هل أستطيع استخدام Ginkgo مع testify أو gomock؟
نعم، تشرح المهارة كيفية مشاركة أدوات الاختبار مع تلك المكتبات.
التفاصيل
الوصف الأصلي من المؤلف
Wire Ginkgo into a Go package — install the ginkgo CLI and Ginkgo+Gomega, ginkgo bootstrap to generate the suite_test.go (TestXxx/RegisterFailHandler(Fail)/RunSpecs), the package xxx_test convention, dot-import alternatives (aliased import, dsl/* subpackages, --nodot), ginkgo generate, and *testing.T interop via GinkgoT()/GinkgoTB() for testify/gomock. Use when first adding Ginkgo to a repo, bootstrapping a suite, or integrating a *testing.T-based library.
repo: onsi/ginkgo
الشعبية
- نجوم GitHub
- 9.1k
- الترتيب
- #12307
- الترخيص
- MIT
- آخر تحديث
- 9/10/2026
التعليقات
- …
المزيد من المهارات من هذا المستودع
ci
9.1kيساعد وكيلك على إعداد اختبارات Ginkgo في التكامل المستمر، بخيارات موصى بها تكشف علامات التركيز والتعليق المنسية.
debugging-failures
9.1kيساعد وكيلك على معرفة سبب فشل اختبارات Ginkgo، بقراءة سطر النتيجة وسحب الاختبارات الفاشلة ورسائلها بدقة من تقرير JSON.
decorators
9.1kيساعد وكيلك على استخدام مزخرفات اختبارات Ginkgo بشكل صحيح، مثل Serial وOrdered وLabel وFocus والمهلات الزمنية، بشرح وظيفة كل واحدة.
filtering
9.1kيساعد وكيلك على تشغيل جزء فقط من اختبارات Ginkgo، باستخدام التعليق والتخطي والتركيز والتسميات والفلاتر بالترتيب الصحيح.
مهارات مشابهة
test-driven-development
311kيعلّم وكيلك كتابة اختبار فاشل أولًا، ثم رؤيته يفشل، ثم كتابة أصغر شيفرة تنجحه، قبل بناء أي ميزة أو إصلاح.
verification-before-completion
311kيعلّم وكيلك تشغيل فحوصات حقيقية وقراءة نتائجها قبل أن يقول إن المهمة أو الإصلاح أو البناء مكتمل أو ناجح.
migrate-to-shoehorn
310kيستبدل تأكيدات النوع الخطرة في ملفات الاختبار بمكتبة shoehorn، حتى تتمكن الاختبارات من استخدام بيانات جزئية وتجتاز فحوص الأنواع.