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

Safe HaskellNone

Snap.Snaplet.Test

Contents

Description

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

Synopsis

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.

runHandler :: MonadIO m => Maybe String -> RequestBuilder m () -> Handler b b a -> 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.

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

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