packages feed

hspec-golden 0.2.0.1 → 0.2.1.0

raw patch · 4 files changed

+23/−3 lines, 4 files

Files

ChangeLog.md view
@@ -1,4 +1,8 @@ # Changelog for hspec-golden+## 0.2.1.0+#### Add+* Instance for IO Golden type. Kudos to @dbalseiro+ ## 0.2.0.1 #### Add * Update docs.
hspec-golden.cabal view
@@ -3,11 +3,9 @@ -- This file has been generated from package.yaml by hpack version 0.35.2. -- -- see: https://github.com/sol/hpack------ hash: bcde352005f41eaf1fe5597862d833a68d980c6b6c7c9f26d0a098a334a9e343  name:           hspec-golden-version:        0.2.0.1+version:        0.2.1.0 synopsis:       Golden tests for hspec description:    .                 Golden tests store the expected output in a separated file. Each time a golden test
src/Test/Hspec/Golden.hs view
@@ -69,6 +69,19 @@   type Arg (Golden str) = ()   evaluateExample e = evaluateExample (\() -> e) +instance Eq str => Example (IO (Golden str)) where+  type Arg (IO (Golden str)) = ()+  evaluateExample e = evaluateExample (\() -> e)++instance Eq str => Example (arg -> IO (Golden str)) where+  type Arg (arg -> IO (Golden str)) = arg+  evaluateExample golden _ action _ = do+    ref <- newIORef (Result "" Success)+    action $ \arg -> do+      r <- runGolden =<< golden arg+      writeIORef ref (fromGoldenResult r)+    readIORef ref+ instance Eq str => Example (arg -> Golden str) where   type Arg (arg -> Golden str) = arg   evaluateExample golden _ action _ = do
test/Test/Hspec/GoldenSpec.hs view
@@ -65,6 +65,11 @@            goldenFileContent <- readFile goldenFilePath            goldenFileContent `shouldBe` fixtureContent +    context "when IO actions are needed in the test case" $+      it "enables `defaultGolden` to be accessible from the test case" $ do+        void $ runSpec $ fixtureTest fixtureContent+        result <- readFile goldenFilePath+        pure $ defaultGolden "io-test" result      context "when the output is not updated" $       context "when the test is executed a second time" $