{"id":16631011,"url":"https://github.com/sclevine/spec","last_synced_at":"2025-04-06T06:09:24.474Z","repository":{"id":57479473,"uuid":"91225283","full_name":"sclevine/spec","owner":"sclevine","description":"Spec is a simple BDD-style test organizer for Go that does not replace the standard library testing package.","archived":false,"fork":false,"pushed_at":"2020-11-11T06:48:21.000Z","size":59,"stargazers_count":77,"open_issues_count":0,"forks_count":7,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-03-30T05:05:23.759Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sclevine.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-05-14T06:45:37.000Z","updated_at":"2025-02-15T20:15:02.000Z","dependencies_parsed_at":"2022-09-17T04:52:10.311Z","dependency_job_id":null,"html_url":"https://github.com/sclevine/spec","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sclevine%2Fspec","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sclevine%2Fspec/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sclevine%2Fspec/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sclevine%2Fspec/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sclevine","download_url":"https://codeload.github.com/sclevine/spec/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247441052,"owners_count":20939239,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-12T04:50:31.435Z","updated_at":"2025-04-06T06:09:24.448Z","avatar_url":"https://github.com/sclevine.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# spec\n\n[![Build Status](https://travis-ci.org/sclevine/spec.svg?branch=master)](https://travis-ci.org/sclevine/spec)\n[![GoDoc](https://godoc.org/github.com/sclevine/spec?status.svg)](https://godoc.org/github.com/sclevine/spec)\n\nSpec is a simple BDD test organizer for Go. It minimally extends the standard\nlibrary `testing` package by facilitating easy organization of Go 1.7+\n[subtests](https://blog.golang.org/subtests).\n\nSpec differs from other BDD libraries for Go in that it:\n- Does not reimplement or replace any functionality of the `testing` package\n- Does not provide an alternative test parallelization strategy to the `testing` package\n- Does not provide assertions\n- Does not encourage the use of dot-imports\n- Does not reuse any closures between test runs (to avoid test pollution)\n- Does not use global state, excessive interface types, or reflection\n\nSpec is intended for gophers who want to write BDD tests in idiomatic Go using\nthe standard library `testing` package. Spec aims to do \"one thing right,\"\nand does not provide a wide DSL or any functionality outside of test\norganization.\n\n### Features\n\n- Clean, simple syntax\n- Supports focusing and pending tests\n- Supports sequential, random, reverse, and parallel test order\n- Provides granular control over test order and subtest nesting\n- Provides a test writer to manage test output\n- Provides a generic, asynchronous reporting interface\n- Provides multiple reporter implementations\n\n### Notes\n\n- Use `go test -v` to see individual subtests.\n\n### Examples\n\n[Most functionality is demonstrated here.](spec_test.go#L238)\n\nQuick example:\n\n```go\nfunc TestObject(t *testing.T) {\n    spec.Run(t, \"object\", func(t *testing.T, when spec.G, it spec.S) {\n        var someObject *myapp.Object\n\n        it.Before(func() {\n            someObject = myapp.NewObject()\n        })\n\n        it.After(func() {\n            someObject.Close()\n        })\n\n        it(\"should have some default\", func() {\n            if someObject.Default != \"value\" {\n                t.Error(\"bad default\")\n            }\n        })\n\n        when(\"something happens\", func() {\n            it.Before(func() {\n                someObject.Connect()\n            })\n\n            it(\"should do one thing\", func() {\n                if err := someObject.DoThing(); err != nil {\n                    t.Error(err)\n                }\n            })\n\n            it(\"should do another thing\", func() {\n                if result := someObject.DoOtherThing(); result != \"good result\" {\n                    t.Error(\"bad result\")\n                }\n            })\n        }, spec.Random())\n\n        when(\"some slow things happen\", func() {\n            it(\"should do one thing in parallel\", func() {\n                if result := someObject.DoSlowThing(); result != \"good result\" {\n                    t.Error(\"bad result\")\n                }\n            })\n\n            it(\"should do another thing in parallel\", func() {\n                if result := someObject.DoOtherSlowThing(); result != \"good result\" {\n                    t.Error(\"bad result\")\n                }\n            })\n        }, spec.Parallel())\n    }, spec.Report(report.Terminal{}))\n}\n```\n\nWith less nesting:\n\n```go\nfunc TestObject(t *testing.T) {\n    spec.Run(t, \"object\", testObject, spec.Report(report.Terminal{}))\n}\n\nfunc testObject(t *testing.T, when spec.G, it spec.S) {\n    ...\n}\n```\n\nFor focusing/reporting across multiple files in a package:\n\n```go\nvar suite spec.Suite\n\nfunc init() {\n    suite = spec.New(\"my suite\", spec.Report(report.Terminal{}))\n    suite(\"object\", testObject)\n    suite(\"other object\", testOtherObject)\n}\n\nfunc TestObjects(t *testing.T) {\n\tsuite.Run(t)\n}\n\nfunc testObject(t *testing.T, when spec.G, it spec.S) {\n\t...\n}\n\nfunc testOtherObject(t *testing.T, when spec.G, it spec.S) {\n\t...\n}\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsclevine%2Fspec","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsclevine%2Fspec","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsclevine%2Fspec/lists"}