{"id":21409830,"url":"https://github.com/stackbuilders/hspec-golden","last_synced_at":"2025-04-07T07:15:30.031Z","repository":{"id":41329905,"uuid":"166290903","full_name":"stackbuilders/hspec-golden","owner":"stackbuilders","description":"Golden tests with Hspec","archived":false,"fork":false,"pushed_at":"2024-10-15T14:43:50.000Z","size":69,"stargazers_count":27,"open_issues_count":2,"forks_count":9,"subscribers_count":23,"default_branch":"main","last_synced_at":"2025-03-31T06:05:04.217Z","etag":null,"topics":["golden-testing","hacktoberfest","hacktoberfest2024","haskell","hspec","snapshot-testing","testing"],"latest_commit_sha":null,"homepage":"","language":"Haskell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/stackbuilders.png","metadata":{"files":{"readme":"README.md","changelog":"ChangeLog.md","contributing":"docs/CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"docs/CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-01-17T20:19:07.000Z","updated_at":"2024-11-24T10:09:19.000Z","dependencies_parsed_at":"2023-02-10T07:31:16.670Z","dependency_job_id":"8b594796-5ec9-4574-be19-f13f61e8040f","html_url":"https://github.com/stackbuilders/hspec-golden","commit_stats":{"total_commits":38,"total_committers":10,"mean_commits":3.8,"dds":0.4473684210526315,"last_synced_commit":"f6ddf602ddfb31921817963bb94f9e21ba91dce5"},"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stackbuilders%2Fhspec-golden","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stackbuilders%2Fhspec-golden/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stackbuilders%2Fhspec-golden/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stackbuilders%2Fhspec-golden/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/stackbuilders","download_url":"https://codeload.github.com/stackbuilders/hspec-golden/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247608153,"owners_count":20965952,"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":["golden-testing","hacktoberfest","hacktoberfest2024","haskell","hspec","snapshot-testing","testing"],"created_at":"2024-11-22T17:34:31.857Z","updated_at":"2025-04-07T07:15:29.994Z","avatar_url":"https://github.com/stackbuilders.png","language":"Haskell","readme":"# hspec-golden\n[![Build and Test](https://github.com/stackbuilders/hspec-golden/actions/workflows/build-and-test.yml/badge.svg?branch=main)](https://github.com/stackbuilders/hspec-golden/actions/workflows/build-and-test.yml) [![Hackage](https://img.shields.io/hackage/v/hspec-golden.svg)](http://hackage.haskell.org/package/hspec-golden)\n\n## Description\nGolden tests store the expected output in a separated file. Each time a golden test\nis executed the output of the subject under test (SUT) is compared with the\nexpected output. If the output of the SUT changes then the test will fail until\nthe expected output is updated.\n\n`hspec-golden` allows you to write golden tests using the popular `hspec`.\n\n## Usage\n\nYou can write golden tests using `defaultGolden` helper:\n\n```haskell\ndescribe \"myFunc\" $\n  it \"generates the right output with the right params\" $\n     let output = show $ myFunc params\n       in defaultGolden \"myFunc\" output\n```\n\nThe first parameter of `defaultGolden` is the golden file name. I recommend you to use\n`show` and `'functionName` (enable `TemplateHaskellQuotes` for the quote) to\nalways have a unique name for your file. Example: `show 'myFunc == MyModule.myFunc`.\nAlthough, you can name it as you like.\n\nYou can write golden tests using `golden` helper:\n\n```haskell\ndescribe \"myFunc\" $\n  golden \"generates the right output with the right params\" $\n     let output = show $ myFunc params\n       in return output\n```\n\nIn case your output isn't a `String` you can define your own `Golden` test\nusing the `Golden` data type:\n\n```haskell\n{-# LANGUAGE TemplateHaskellQuotes #-}\n\nimport           Test.Hspec\nimport           Test.Hspec.Golden\nimport           Data.Text (Text)\nimport qualified Data.Text.IO as T\n\nmyGoldenTest :: String -\u003e Text -\u003e Golden Text\nmyGoldenTest name actualOutput =\n  Golden {\n    output = actualOutput,\n    encodePretty = prettyText,\n    writeToFile = T.writeFile,\n    readFromFile = T.readFile,\n    goldenFile = name,\n    actualFile = Just (name \u003c/\u003e \"-actual\"),\n    failFirstTime = False\n  }\n\nspec :: Spec\nspec =\n  describe \"myTextFunc\" $\n    it \"generates the right output with the right params\" $\n       let textOutput = myTextFunc params\n         in myGoldenTest (show 'myTextFunc) textOutput\n```\n\n## Install CLI\n\nYou can install the `hspec-golden` command line interface (CLI) with `stack`:\n\n```\n$ stack install hspec-golden\n```\n\nor `cabal`:\n\n\n```\n$ cabal install hspec-golden\n```\n\nThe CLI is called `hgold`:\n\n```\n$ hgold -h\n\nUpdate your golden files\n\nUsage: hgold [-u|--update [DIR]] [-v|--version]\n\nAvailable options:\n  -u,--update [DIR]        The testing directory where you're dumping your\n                           results. (default: \".golden\")\n  -v,--version             Show version\n  -h,--help                Show this help text\n```\n\nUpdate the golden tests under `.golden` directory:\n\n```\n$ hgold\n```\n\nUpdate the golden tests under `.myGoldenTest` directory:\n\n```\n$ hgold -u .myGoldenTest\n```\n\n## Contributors ✨\n\nThanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):\n\n\u003c!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section --\u003e\n\u003c!-- prettier-ignore-start --\u003e\n\u003c!-- markdownlint-disable --\u003e\n\u003ctable\u003e\n  \u003ctbody\u003e\n    \u003ctr\u003e\n      \u003ctd align=\"center\" valign=\"top\" width=\"14.28%\"\u003e\u003ca href=\"https://cristhianmotoche.github.io/\"\u003e\u003cimg src=\"https://avatars.githubusercontent.com/u/8370088?v=4?s=100\" width=\"100px;\" alt=\"Cristhian Motoche\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eCristhian Motoche\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"https://github.com/stackbuilders/hspec-golden/commits?author=CristhianMotoche\" title=\"Code\"\u003e💻\u003c/a\u003e\u003c/td\u003e\n      \u003ctd align=\"center\" valign=\"top\" width=\"14.28%\"\u003e\u003ca href=\"https://www.christian-wuensche.com/\"\u003e\u003cimg src=\"https://avatars.githubusercontent.com/u/3807237?v=4?s=100\" width=\"100px;\" alt=\"Christian Wünsche (ehem Heyn)\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eChristian Wünsche (ehem Heyn)\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"https://github.com/stackbuilders/hspec-golden/commits?author=christianwish\" title=\"Code\"\u003e💻\u003c/a\u003e\u003c/td\u003e\n      \u003ctd align=\"center\" valign=\"top\" width=\"14.28%\"\u003e\u003ca href=\"https://github.com/bitc\"\u003e\u003cimg src=\"https://avatars.githubusercontent.com/u/996487?v=4?s=100\" width=\"100px;\" alt=\"Bit Connor\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eBit Connor\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"https://github.com/stackbuilders/hspec-golden/commits?author=bitc\" title=\"Code\"\u003e💻\u003c/a\u003e\u003c/td\u003e\n      \u003ctd align=\"center\" valign=\"top\" width=\"14.28%\"\u003e\u003ca href=\"https://dbalseiro.github.io/\"\u003e\u003cimg src=\"https://avatars.githubusercontent.com/u/2053849?v=4?s=100\" width=\"100px;\" alt=\"Diego Balseiro\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eDiego Balseiro\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"https://github.com/stackbuilders/hspec-golden/commits?author=dbalseiro\" title=\"Code\"\u003e💻\u003c/a\u003e\u003c/td\u003e\n      \u003ctd align=\"center\" valign=\"top\" width=\"14.28%\"\u003e\u003ca href=\"https://github.com/Jagl257\"\u003e\u003cimg src=\"https://avatars.githubusercontent.com/u/27145248?v=4?s=100\" width=\"100px;\" alt=\"Jorge Guerra Landázuri\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eJorge Guerra Landázuri\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"https://github.com/stackbuilders/hspec-golden/commits?author=Jagl257\" title=\"Code\"\u003e💻\u003c/a\u003e\u003c/td\u003e\n      \u003ctd align=\"center\" valign=\"top\" width=\"14.28%\"\u003e\u003ca href=\"https://github.com/ChickenProp\"\u003e\u003cimg src=\"https://avatars.githubusercontent.com/u/57271?v=4?s=100\" width=\"100px;\" alt=\"Phil Hazelden\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003ePhil Hazelden\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"https://github.com/stackbuilders/hspec-golden/commits?author=ChickenProp\" title=\"Code\"\u003e💻\u003c/a\u003e\u003c/td\u003e\n      \u003ctd align=\"center\" valign=\"top\" width=\"14.28%\"\u003e\u003ca href=\"http://alexvieth.wordpress.com/\"\u003e\u003cimg src=\"https://avatars.githubusercontent.com/u/1420272?v=4?s=100\" width=\"100px;\" alt=\"Alexander Vieth\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eAlexander Vieth\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"https://github.com/stackbuilders/hspec-golden/commits?author=avieth\" title=\"Code\"\u003e💻\u003c/a\u003e\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd align=\"center\" valign=\"top\" width=\"14.28%\"\u003e\u003ca href=\"https://github.com/guibou\"\u003e\u003cimg src=\"https://avatars.githubusercontent.com/u/9705357?v=4?s=100\" width=\"100px;\" alt=\"Guillaume Bouchard\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eGuillaume Bouchard\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"https://github.com/stackbuilders/hspec-golden/commits?author=guibou\" title=\"Code\"\u003e💻\u003c/a\u003e\u003c/td\u003e\n      \u003ctd align=\"center\" valign=\"top\" width=\"14.28%\"\u003e\u003ca href=\"https://github.com/fefi95\"\u003e\u003cimg src=\"https://avatars.githubusercontent.com/u/12057338?v=4?s=100\" width=\"100px;\" alt=\"Stefani Castellanos\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eStefani Castellanos\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"https://github.com/stackbuilders/hspec-golden/commits?author=fefi95\" title=\"Code\"\u003e💻\u003c/a\u003e\u003c/td\u003e\n    \u003c/tr\u003e\n  \u003c/tbody\u003e\n  \u003ctfoot\u003e\n    \u003ctr\u003e\n      \u003ctd align=\"center\" size=\"13px\" colspan=\"7\"\u003e\n        \u003cimg src=\"https://raw.githubusercontent.com/all-contributors/all-contributors-cli/1b8533af435da9854653492b1327a23a4dbd0a10/assets/logo-small.svg\"\u003e\n          \u003ca href=\"https://all-contributors.js.org/docs/en/bot/usage\"\u003eAdd your contributions\u003c/a\u003e\n        \u003c/img\u003e\n      \u003c/td\u003e\n    \u003c/tr\u003e\n  \u003c/tfoot\u003e\n\u003c/table\u003e\n\n\u003c!-- markdownlint-restore --\u003e\n\u003c!-- prettier-ignore-end --\u003e\n\n\u003c!-- ALL-CONTRIBUTORS-LIST:END --\u003e\n\nThis project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!\n\n## License\n\nMIT, see the [LICENSE file](./LICENSE).\n\n## Contributing\n\nDo you want to contribute to this project? Please take a look at our [contributing guideline](/docs/CONTRIBUTING.md) to know how you can help us build it.\n\n---\n\u003cimg src=\"https://www.stackbuilders.com/media/images/Sb-supports.original.png\" alt=\"Stack Builders\" width=\"50%\"\u003e\u003c/img\u003e\n[Check out our libraries](https://github.com/stackbuilders/) | [Join our team](https://www.stackbuilders.com/join-us/)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstackbuilders%2Fhspec-golden","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstackbuilders%2Fhspec-golden","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstackbuilders%2Fhspec-golden/lists"}