{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE CPP #-}
module Test.Hspec.Wai.Internal (
WaiExpectation
, WaiSession(..)
, runWaiSession
, withApplication
, getApp
, formatHeader
) where
import Prelude ()
import Prelude.Compat
import Control.Monad.IO.Class
import Control.Monad.Trans.Reader
import Network.Wai (Application)
import Network.Wai.Test hiding (request)
import Test.Hspec.Core.Spec
import Test.Hspec.Wai.Util (formatHeader)
#if MIN_VERSION_base(4,9,0)
import Control.Monad.Fail
#endif
type WaiExpectation = WaiSession ()
newtype WaiSession a = WaiSession {unWaiSession :: Session a}
deriving (Functor, Applicative, Monad, MonadIO
#if MIN_VERSION_base(4,9,0)
, MonadFail
#endif
)
runWaiSession :: WaiSession a -> Application -> IO a
runWaiSession = runSession . unWaiSession
withApplication :: Application -> WaiSession a -> IO a
withApplication = flip runWaiSession
instance Example WaiExpectation where
type Arg WaiExpectation = Application
evaluateExample e p action = evaluateExample (action $ runWaiSession e) p ($ ())
getApp :: WaiSession Application
getApp = WaiSession ask