Stability | stable |
---|---|
Safe Haskell | None |
Hspec is a testing library for Haskell.
This is the library reference for Hspec. The User's Manual contains more in-depth documentation.
- type Spec = SpecWith ()
- type SpecWith a = SpecM a ()
- type ActionWith a = a -> IO ()
- class Example e where
- type Arg e
- module Test.Hspec.Expectations
- describe :: String -> SpecWith a -> SpecWith a
- context :: String -> SpecWith a -> SpecWith a
- it :: Example e => String -> e -> SpecWith (Arg e)
- example :: Expectation -> Expectation
- pending :: Expectation
- pendingWith :: String -> Expectation
- before :: IO a -> SpecWith a -> Spec
- beforeWith :: (b -> IO a) -> SpecWith a -> SpecWith b
- beforeAll :: IO a -> SpecWith a -> SpecWith ()
- beforeAllWith :: (b -> IO a) -> SpecWith a -> SpecWith b
- after :: ActionWith a -> SpecWith a -> SpecWith a
- after_ :: IO () -> Spec -> Spec
- around :: (ActionWith a -> IO ()) -> SpecWith a -> Spec
- around_ :: (IO () -> IO ()) -> Spec -> Spec
- aroundWith :: (ActionWith a -> ActionWith b) -> SpecWith a -> SpecWith b
- parallel :: SpecWith a -> SpecWith a
- runIO :: IO r -> SpecM a r
- hspec :: Spec -> IO ()
Types
type ActionWith a = a -> IO ()Source
An IO
action that expects an argument of type a
.
A type class for examples.
Setting expectations
module Test.Hspec.Expectations
Defining a spec
it :: Example e => String -> e -> SpecWith (Arg e)Source
Create a spec item.
A spec item consists of:
- a textual description of a desired behavior
- an example for that behavior
describe "absolute" $ do it "returns a positive number when given a negative number" $ absolute (-1) == 1
example :: Expectation -> ExpectationSource
This 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
Specifies a pending example.
If you want to textually specify a behavior but do not have an example yet, use this:
describe "fancyFormatter" $ do it "can format text in a way that everyone likes" $ pending
pendingWith :: String -> ExpectationSource
Specifies a pending example with a reason for why it's pending.
describe "fancyFormatter" $ do it "can format text in a way that everyone likes" $ pendingWith "waiting for clarification from the designers"
beforeWith :: (b -> IO a) -> SpecWith a -> SpecWith bSource
Run a custom action before every spec item.
beforeAllWith :: (b -> IO a) -> SpecWith a -> SpecWith bSource
Run a custom action before all spec items.
after :: ActionWith a -> SpecWith a -> SpecWith aSource
Run a custom action after every spec item.
around :: (ActionWith a -> IO ()) -> SpecWith a -> SpecSource
Run a custom action before and/or after every spec item.
around_ :: (IO () -> IO ()) -> Spec -> SpecSource
Run a custom action before and/or after every spec item.
aroundWith :: (ActionWith a -> ActionWith b) -> SpecWith a -> SpecWith bSource
Run a custom action before and/or after every spec item.