CodeSampleX

Exemplo

github.com/onsi/ginkgo/v2 v2.13.2: BDD testing suite with Describe, Context, and It using RunSpecs

Amostra verificada para golang github.com/onsi/ginkgo/v2 v2.13.2: BDD testing suite with Describe, Context, and It using RunSpecs. O contrato rodou em go…

sha256:6f67659227b93c1b6236a450a333f0e1fee18b970294570213aa34572a18c94a

Esta rede oferece uma coisa: uma amostra que compila. Ela a executou em um sandbox e guardou o recibo assinado. Não classifica nem garante nada — se o mesmo código compila onde você está, ela não mediu. Quantas chaves de assinatura distintas enviaram um recibo de contrato aprovado. Uma é só o autor; mais de uma significa que outra pessoa também o compilou. Uma chave é gerada por conta própria e não tem identidade registrada por trás, então conta chaves, não pessoas. MIT-0

Evidência de execução

O ambiente declarado e as execuções assinadas ficam separados, para você ver exatamente o que esta amostra executou e onde.

Base da evidência
Contrato assinado aprovado
Recibos de verificação
2
Chaves de assinatura que o compilaram
1
Ambiente declarado go 1.26 linux 24 · ubuntu · glibc 2.39 x64 go 1.26 go go 1

Ambientes das execuções de verificação

Ambiente Contrato Etapas Execução
go 1.26 · linux alpine/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · golang@1golang:1.26-alpine@sha256:28d89ee9cc0f…
2026-08-23
go 1.26 · linux debian/x64 · docker ed25519:c1973797be207ac4 FAIL compile:SKIPPED · contract:FAIL · load:SKIPPED · resolve:PASS
CONTAINER_RUN · golang@1golang:1.26@sha256:e30143be198a…
2026-09-07

Caso

HOW
Objetivo
BDD testing suite with Describe, Context, and It using RunSpecs
Pacotes
Símbolos
  • Describe
  • It
  • RunSpecs
Ambiente
go 1.26.6
Criado
2026-08-23T17:11:17Z

Contrato

  1. Describe and Context organize test suites hierarchically with isolated state
  2. It defines executable test specifications with By steps and assertions
  3. BeforeEach and AfterEach manage test lifecycle initialization and cleanup
  4. DeferCleanup registers callbacks executed in LIFO order upon test completion
  5. DescribeTable and Entry execute parameterized table specifications
  6. RunSpecs executes the test suite against a custom GinkgoTestingT runner

Arquivos

  • PROMPT.md
  • csx.json
  • go.mod
  • go.sum
  • spec.json
  • test/contract.go

Baixar o artefato de código-fonte (tar.gz)

Código-fonte

PROMPT.md
Clean-room public code sample — generation instructions

Write a brand-new, minimal, self-contained code sample in this clean-room directory.
Do not copy, paraphrase, or reference any existing project source. Work only from this spec.

A csx.json manifest scaffold already exists. Do not recreate it from memory. Preserve its case.goal, packages and symbols; fill its empty case.contract with exact assertions and correct its environment, commands and verifierAdapter for the files you generate.

Goal: BDD testing suite with Describe, Context, and It using RunSpecs
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:golang/github.com/onsi/ginkgo/v2@v2.13.2
Demonstrate these symbols/APIs:
  - Describe
  - It
  - RunSpecs
Constraints:
  - executionContext: node
Required runtime conditions:
  - ecosystem: npm
  - language: javascript
  - moduleSystem: cjs
  - packageManager: npm@10.9.8
  - runtime: node@22.23.2

Rules:
  - One focused purpose; the smallest project that proves the goal.
  - Include a contract test (test/contract.*) that runs OFFLINE and exits 0 exactly when the goal behavior works.
  - Pin every dependency with a lockfile so resolution is reproducible.
  - No secrets, credentials, or tokens. No real URLs (only example.com or localhost). No absolute paths.
  - No personal names, emails, company names, or project identifiers of any kind.
  - No binaries and no generated output (node_modules, dist, target, venv, .git, .env).
  - Keep it under 200 files and 256KB packed.
csx.json
{"case":{"caseId":"case:sha256:197675afa347d20c93af89b36eda844838f906c30219ef7a3e250bc64b32c790","contract":["Describe and Context organize test suites hierarchically with isolated state","It defines executable test specifications with By steps and assertions","BeforeEach and AfterEach manage test lifecycle initialization and cleanup","DeferCleanup registers callbacks executed in LIFO order upon test completion","DescribeTable and Entry execute parameterized table specifications","RunSpecs executes the test suite against a custom GinkgoTestingT runner"],"goal":"BDD testing suite with Describe, Context, and It using RunSpecs","kind":"HOW","packages":["pkg:golang/github.com/onsi/ginkgo/v2@v2.13.2"],"schemaVersion":1,"symbols":["Describe","It","RunSpecs"]},"contractCommand":["go","run","./test"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"golang","language":"go","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"go","packageManagerVersion":"1.26.6","runtime":"go","runtimeVersion":"1.26.6","schemaVersion":1},"license":"MIT-0","packages":["pkg:golang/github.com/onsi/ginkgo/v2@v2.13.2"],"schemaVersion":1,"subject":"pkg:golang/github.com/onsi/ginkgo/v2@v2.13.2","symbols":["Describe","It","RunSpecs"],"verifierAdapter":"golang@1"}
go.mod
module sample

go 1.21

require github.com/onsi/ginkgo/v2 v2.13.2

require (
	github.com/go-logr/logr v1.3.0 // indirect
	github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 // indirect
	github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38 // indirect
	golang.org/x/net v0.17.0 // indirect
	golang.org/x/sys v0.14.0 // indirect
	golang.org/x/tools v0.14.0 // indirect
)
go.sum
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/go-logr/logr v1.3.0 h1:2y3SDp0ZXuc6/cjLSZ+Q3ir+QB9T/iG5yYRXqsagWSY=
github.com/go-logr/logr v1.3.0/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 h1:tfuBGBXKqDEevZMzYi5KSi8KkcZtzBcTgAUUtapy0OI=
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572/go.mod h1:9Pwr4B2jHnOSGXyyzV8ROjYa2ojvAY6HCGYYfMoC3Ls=
github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg=
github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38 h1:yAJXTCF9TqKcTiHJAE8dj7HMvPfh66eeA2JYW7eFpSE=
github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE=
github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
github.com/onsi/ginkgo/v2 v2.13.2 h1:Bi2gGVkfn6gQcjNjZJVO8Gf0FHzMPf2phUei9tejVMs=
github.com/onsi/ginkgo/v2 v2.13.2/go.mod h1:XStQ8QcGwLyF4HdfcZB8SFOS/MWCgDuXMSBe6zrvLgM=
github.com/onsi/gomega v1.29.0 h1:KIA/t2t5UBzoirT4H9tsML45GEbo3ouUnBHsCfD2tVg=
github.com/onsi/gomega v1.29.0/go.mod h1:9sxs+SwGrKI0+PWe4Fxa9tFQQBG5xSsSbMXOI8PPpoQ=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
golang.org/x/mod v0.13.0 h1:I/DsJXRlw/8l/0c24sM9yb0T4z9liZTduXvdAWYiysY=
golang.org/x/mod v0.13.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM=
golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE=
golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.14.0 h1:Vz7Qs629MkJkGyHxUlRHizWJRG2j8fbQKjELVSNhy7Q=
golang.org/x/sys v0.14.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k=
golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
golang.org/x/tools v0.14.0 h1:jvNa2pY0M4r62jkRQ6RwEZZyPcymeL9XZMLBbV7U2nc=
golang.org/x/tools v0.14.0/go.mod h1:uYBEerGOWcJyEORxN+Ek8+TT266gXkNlHdJBwexUsBg=
google.golang.org/protobuf v1.28.0 h1:w43yiav+6bVFTBQFZX0r7ipe9JQ1QsbMgHwbBziscLw=
google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
spec.json
{
  "schemaVersion": 1,
  "goal": "BDD testing suite with Describe, Context, and It using RunSpecs",
  "kind": "HOW",
  "packages": [
    "pkg:golang/github.com/onsi/ginkgo/v2@v2.13.2"
  ],
  "symbols": [
    "Describe",
    "It",
    "RunSpecs"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@10.9.8",
    "runtime": "node@22.23.2"
  }
}
test/contract.go
package main

import (
	"fmt"
	"os"

	. "github.com/onsi/ginkgo/v2"
)

type contractTestingT struct {
	failed bool
}

func (t *contractTestingT) Fail() {
	t.failed = true
}

func (t *contractTestingT) Fatalf(format string, args ...interface{}) {
	t.failed = true
	fmt.Fprintf(os.Stderr, format+"\n", args...)
}

var _ = Describe("Ginkgo BDD Framework", func() {
	var state int

	BeforeEach(func() {
		state = 10
	})

	AfterEach(func() {
		state = 0
	})

	Context("when executing hierarchical specs", func() {
		It("maintains isolated state within BeforeEach and It blocks", func() {
			By("modifying initial state")
			state += 5
			if state != 15 {
				Fail(fmt.Sprintf("expected state to be 15, got %d", state))
			}

			By("applying additional modification")
			state *= 2
			if state != 30 {
				Fail(fmt.Sprintf("expected state to be 30, got %d", state))
			}
		})

		It("resets state for subsequent specifications", func() {
			if state != 10 {
				Fail(fmt.Sprintf("expected state reset to 10 in fresh test, got %d", state))
			}
		})
	})

	Context("when managing resource lifecycle with DeferCleanup", func() {
		It("registers and executes cleanup callbacks in LIFO order", func() {
			var order []string

			DeferCleanup(func() {
				order = append(order, "first-cleanup")
				if len(order) != 2 || order[0] != "second-cleanup" || order[1] != "first-cleanup" {
					Fail("defer cleanup executed in unexpected order")
				}
			})

			DeferCleanup(func() {
				order = append(order, "second-cleanup")
			})

			if state != 10 {
				Fail("state was corrupted before cleanup test")
			}
		})
	})

	DescribeTable("parameterized table specifications",
		func(input int, multiplier int, expected int) {
			result := input * multiplier
			if result != expected {
				Fail(fmt.Sprintf("expected %d * %d = %d, got %d", input, multiplier, expected, result))
			}
		},
		Entry("multiplies positive integers", 3, 4, 12),
		Entry("handles multiplication by zero", 7, 0, 0),
		Entry("handles negative values", -3, 5, -15),
	)
})

func main() {
	t := &contractTestingT{}
	passed := RunSpecs(t, "Ginkgo v2 Contract Verification Suite")
	if !passed || t.failed {
		fmt.Fprintf(os.Stderr, "Contract test suite failed execution\n")
		os.Exit(1)
	}
	fmt.Println("All Ginkgo v2 contract assertions passed.")
}

Seeder de origem

anônimo