Skip to content

Instantly share code, notes, and snippets.

@sleexyz
Created July 7, 2017 04:53
Show Gist options
  • Save sleexyz/bac73af84c5b723e24bc37616b7665de to your computer and use it in GitHub Desktop.
Save sleexyz/bac73af84c5b723e24bc37616b7665de to your computer and use it in GitHub Desktop.
hspec test isolation
#!/usr/bin/env stack
-- stack --resolver lts-8.0 --install-ghc runghc --package hspec -- -Wall -Werror
import Test.Hspec
import Data.IORef
-- * test should be isolated from other tests - Pass (expected: Pass) ✔
main :: IO ()
main = hspec $ do
describe "asdf" $ beforeWith (\() -> newIORef False) $ do
describe "inner" $ beforeWith (\ctx -> writeIORef ctx True >> return ctx) $ do
it "ctx should be true" $ \ctx -> do
readIORef ctx >>= shouldBe True
it "(setting ctx to False)" $ \ctx -> do
writeIORef ctx False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment