snap-0.11.2: Top-level package for the Snap Web Framework

Safe Haskell | None

Snap.Snaplet.Test

Contents

- Testing handlers

Description

The Snap.Snaplet.Test module contains primitives and combinators for testing Snaplets.

Synopsis

- evalHandler :: MonadIO m => RequestBuilder m () -> Handler b b a -> SnapletInit b b -> m (Either Text a)
- runHandler :: MonadIO m => RequestBuilder m () -> Handler b b a -> SnapletInit b b -> m (Either Text Response)
- withTemporaryFile :: FilePath -> IO () -> IO ()

## Testing handlers

evalHandler :: MonadIO m => RequestBuilder m () -> Handler b b a -> SnapletInit b b -> m (Either Text a)

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.

runHandler :: MonadIO m => RequestBuilder m () -> Handler b b a -> SnapletInit b b -> m (Either Text Response)

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.

withTemporaryFile :: FilePath -> IO () -> IO ()

Remove the given file before running an IO computation. Obviously it can be used with `Assertion`.