| Safe Haskell | None |
|---|---|
| Language | Haskell98 |
Snap.Snaplet.Test
Contents
Description
The Snap.Snaplet.Test module contains primitives and combinators for testing Snaplets.
- evalHandler :: MonadIO m => Maybe String -> RequestBuilder m () -> Handler b b a -> SnapletInit b b -> m (Either Text a)
- evalHandler' :: MonadIO m => Snaplet b -> InitializerState b -> RequestBuilder m () -> Handler b b a -> m (Either Text a)
- runHandler :: MonadIO m => Maybe String -> RequestBuilder m () -> Handler b b v -> SnapletInit b b -> m (Either Text Response)
- runHandler' :: MonadIO m => Snaplet b -> InitializerState b -> RequestBuilder m () -> Handler b b v -> m (Either Text Response)
- getSnaplet :: MonadIO m => Maybe String -> SnapletInit b b -> m (Either Text (Snaplet b, InitializerState b))
- closeSnaplet :: MonadIO m => InitializerState b -> m ()
- data InitializerState b
- withTemporaryFile :: FilePath -> IO () -> IO ()
Testing handlers
evalHandler :: MonadIO m => Maybe String -> RequestBuilder m () -> Handler b b a -> SnapletInit b b -> m (Either Text a) Source
Given a Snaplet Handler, a SnapletInit specifying the initial state,
and a RequestBuilder defining a test request, runs the handler,
returning the monadic value it produces.
Throws an exception if the Snap handler early-terminates with finishWith
or mzero.
Note that the output of this function is slightly different from
'evalHandler defined in Snap.Test, because due to the fact running
the initializer inside SnapletInit can throw an exception.
evalHandler' :: MonadIO m => Snaplet b -> InitializerState b -> RequestBuilder m () -> Handler b b a -> m (Either Text a) Source
A variant of evalHandler that takes the Snaplet and InitializerState as produced by getSnaplet, so those can be re-used across requests. It does not run cleanup actions, so closeSnaplet should be used when finished.
runHandler :: MonadIO m => Maybe String -> RequestBuilder m () -> Handler b b v -> SnapletInit b b -> m (Either Text Response) Source
Given a Snaplet Handler and a RequestBuilder defining
a test request, runs the Handler, producing an HTTP Response.
Note that the output of this function is slightly different from
runHandler defined in Snap.Test, because due to the fact running
the initializer inside SnapletInit can throw an exception.
runHandler' :: MonadIO m => Snaplet b -> InitializerState b -> RequestBuilder m () -> Handler b b v -> m (Either Text Response) Source
A variant of runHandler that takes the Snaplet and InitializerState as produced by getSnaplet, so those can be re-used across requests. It does not run cleanup actions, so closeSnaplet should be used when finished.
getSnaplet :: MonadIO m => Maybe String -> SnapletInit b b -> m (Either Text (Snaplet b, InitializerState b)) Source
Run the given initializer, yielding a tuple where the first element is
a Snaplet b, or an error message whether the initializer threw an
exception. This is only needed for runHandler'/evalHandler'.
closeSnaplet :: MonadIO m => InitializerState b -> m () Source
Run cleanup for an initializer. Should be run after finished using the state that getSnaplet returned. Only needed if using getSnaplet and evalHandler'/runHandler'.
data InitializerState b Source
Information about a partially constructed initializer. Used to automatically aggregate handlers and cleanup actions.
withTemporaryFile :: FilePath -> IO () -> IO () Source
Remove the given file before running an IO computation. Obviously it
can be used with Assertion.