hspec-2.4.8: A Testing Framework for Haskell

Stabilitystable
Safe HaskellNone
LanguageHaskell2010

Test.Hspec

Contents

Description

Hspec is a testing framework for Haskell.

This is the library reference for Hspec. The User's Manual contains more in-depth documentation.

Synopsis

Types

type Spec = SpecWith () #

type SpecWith a = SpecM a () #

type family Arg e :: * #

Instances

type Arg Bool 
type Arg Bool = ()
type Arg Property 
type Arg Property = ()
type Arg Expectation 
type Arg Expectation = ()
type Arg Result 
type Arg Result = ()
type Arg (a -> Property) 
type Arg (a -> Property) = a
type Arg (a -> Expectation) 
type Arg (a -> Expectation) = a
type Arg (a -> Bool) 
type Arg (a -> Bool) = a
type Arg (a -> Result) 
type Arg (a -> Result) = a

class Example e #

Minimal complete definition

evaluateExample

Associated Types

type Arg e :: * #

Instances

Example Bool 

Associated Types

type Arg Bool :: * #

Methods

evaluateExample :: Bool -> Params -> (ActionWith (Arg Bool) -> IO ()) -> ProgressCallback -> IO Result

Example Property 

Associated Types

type Arg Property :: * #

Methods

evaluateExample :: Property -> Params -> (ActionWith (Arg Property) -> IO ()) -> ProgressCallback -> IO Result

Example Expectation 

Associated Types

type Arg Expectation :: * #

Methods

evaluateExample :: Expectation -> Params -> (ActionWith (Arg Expectation) -> IO ()) -> ProgressCallback -> IO Result

Example Result 

Associated Types

type Arg Result :: * #

Methods

evaluateExample :: Result -> Params -> (ActionWith (Arg Result) -> IO ()) -> ProgressCallback -> IO Result

Example (a -> Result) 

Associated Types

type Arg (a -> Result) :: * #

Methods

evaluateExample :: (a -> Result) -> Params -> (ActionWith (Arg (a -> Result)) -> IO ()) -> ProgressCallback -> IO Result

Example (a -> Bool) 

Associated Types

type Arg (a -> Bool) :: * #

Methods

evaluateExample :: (a -> Bool) -> Params -> (ActionWith (Arg (a -> Bool)) -> IO ()) -> ProgressCallback -> IO Result

Example (a -> Expectation) 

Associated Types

type Arg (a -> Expectation) :: * #

Methods

evaluateExample :: (a -> Expectation) -> Params -> (ActionWith (Arg (a -> Expectation)) -> IO ()) -> ProgressCallback -> IO Result

Example (a -> Property) 

Associated Types

type Arg (a -> Property) :: * #

Methods

evaluateExample :: (a -> Property) -> Params -> (ActionWith (Arg (a -> Property)) -> IO ()) -> ProgressCallback -> IO Result

Setting expectations

Defining a spec

it :: (HasCallStack, Example a) => String -> a -> SpecWith (Arg a) #

example :: Expectation -> Expectation Source #

example is a type restricted version of id. It can be used to get better error messages on type mismatches.

Compare e.g.

it "exposes some behavior" $ example $ do
  putStrLn

with

it "exposes some behavior" $ do
  putStrLn

runIO :: IO r -> SpecM a r #

Pending spec items

During a test run a pending spec item is:

  1. not executed
  2. reported as "pending"

xit :: (HasCallStack, Example a) => String -> a -> SpecWith (Arg a) #

Hooks

type ActionWith a = a -> IO () #

before :: IO a -> SpecWith a -> Spec #

before_ :: IO () -> SpecWith a -> SpecWith a #

beforeWith :: (b -> IO a) -> SpecWith a -> SpecWith b #

beforeAll :: IO a -> SpecWith a -> Spec #

beforeAll_ :: IO () -> SpecWith a -> SpecWith a #

after_ :: IO () -> SpecWith a -> SpecWith a #

afterAll_ :: IO () -> SpecWith a -> SpecWith a #

around :: (ActionWith a -> IO ()) -> SpecWith a -> Spec #

around_ :: (IO () -> IO ()) -> SpecWith a -> SpecWith a #

Running a spec

hspec :: Spec -> IO () #