HORIZON HASKELLDocslts/ghc-9.10.xc74966e2026-09-27Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · c74966e · 2026-09-27

Modulehspec-golden-0.2.2.0Haskell2010

Test.Hspec.Golden

Golden tests store the expected output in a separated file. Each time a golden test is executed the output of the subject under test (SUT) is compared with the expected output. If the output of the SUT changes then the test will fail until the expected output is updated. We expose defaultGolden for output of type String. If your SUT has a different output, you can use Golden.

  • 1 type
  • 2 values
datadata Golden str
#

Golden tests parameters

import           Data.Text (Text)
import qualified Data.Text.IO as T

goldenText :: String -> Text -> Golden Text
goldenText name actualOutput =
  Golden {
    output = actualOutput,
    encodePretty = prettyText,
    writeToFile = T.writeFile,
    readFromFile = T.readFile,
    goldenFile = ".specific-golden-dir" / name / "golden",
    actualFile = Just (".specific-golden-dir" / name / "actual"),
    failFirstTime = False
  }

describe "myTextFunc" $
  it "generates the right output with the right params" $
    goldenText "myTextFunc" (myTextFunc params)

Constructors

Instances8Example, Arg, …
  • Eq str => Example (IO (Golden str))Defined in hspec-golden-0.2.2.0 · Test.Hspec.Golden
  • Eq str => Example (Golden str)Defined in hspec-golden-0.2.2.0 · Test.Hspec.Golden
  • Eq str => Example (arg -> IO (Golden str))Defined in hspec-golden-0.2.2.0 · Test.Hspec.Golden
  • Eq str => Example (arg -> Golden str)Defined in hspec-golden-0.2.2.0 · Test.Hspec.Golden
  • type Arg (IO (Golden str)) = ()Defined in hspec-golden-0.2.2.0 · Test.Hspec.Golden
  • type Arg (Golden str) = ()Defined in hspec-golden-0.2.2.0 · Test.Hspec.Golden
  • type Arg (arg -> IO (Golden str)) = argDefined in hspec-golden-0.2.2.0 · Test.Hspec.Golden
  • type Arg (arg -> Golden str) = argDefined in hspec-golden-0.2.2.0 · Test.Hspec.Golden

An example of Golden tests which output is String

 describe "html" $ do
   context "given a valid generated html" $
     it "generates html" $
       defaultGolden "html" someHtml
valuegolden
  1. :: String

    Test description

  2. -> IO String

    Content (return content for pure functions)

  3. -> Spec
#

A helper function to create a golden test.

 describe "function" $
   golden "some name" $
     return content