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 = SpecM ()
- class Example a
- module Test.Hspec.Expectations
- describe :: String -> Spec -> Spec
- context :: String -> Spec -> Spec
- it :: Example a => String -> a -> Spec
- example :: Expectation -> Expectation
- pending :: Expectation
- pendingWith :: String -> Expectation
- before :: IO () -> Spec -> Spec
- after :: IO () -> Spec -> Spec
- around :: (IO () -> IO ()) -> Spec -> Spec
- parallel :: Spec -> Spec
- hspec :: Spec -> IO ()
A type class for examples.
Defining a spec
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
This is a type restricted version of
id. It can be used to get better
error messages on type mismatches.
it "exposes some behavior" $ example $ do putStrLn
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
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"
Run a custom action before and/or after every spec item.