packages feed

hspec-monad-control-0.1.0.0: Test/Hspec/Control.hs

{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE TypeFamilies #-}
module Test.Hspec.Control where

import Control.Monad.Base
import Control.Monad.Trans.Control
import Control.Monad.Trans.Writer
import Data.Functor (($>))
import Test.Hspec.Core.Spec

instance MonadBase IO (SpecM a) where
  liftBase = runIO

instance MonadBaseControl IO (SpecM a) where
  type StM (SpecM a) r = (r, [SpecTree a])
  liftBaseWith f = runIO (f runSpecM')
    where runSpecM' (SpecM specs) = runWriterT specs
  restoreM (r, specs) = fromSpecList specs $> r