Safe Haskell | None |
---|---|
Language | Haskell2010 |
- type Spec = SpecM ()
- class Example a
- module Test.Hspec.Expectations
- describe :: String -> Spec -> Spec
- context :: String -> Spec -> Spec
- it :: Example a => String -> a -> Spec
- specify :: Example a => String -> a -> Spec
- example :: Expectation -> Expectation
- pending :: Expectation
- pendingWith :: String -> Expectation
- before :: IO () -> Spec -> Spec
- beforeAll :: IO () -> Spec -> Spec
- after :: IO () -> Spec -> Spec
- afterAll :: IO () -> Spec -> Spec
- around :: (IO () -> IO ()) -> Spec -> Spec
- parallel :: Spec -> Spec
- runIO :: IO a -> SpecM a
- hspec :: Spec -> IO ()
- type Spec = SpecM ()
- hspec :: Spec -> IO ()
- hspecWithFormatter :: IsFormatter a => a -> Spec -> IO ()
- postProcessSpec :: FilePath -> Spec -> Spec
- describe :: String -> Spec -> Spec
Types
A type class for examples.
evaluateExample
Setting expectations
module Test.Hspec.Expectations
Defining a spec
it :: Example a => String -> a -> Spec 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 -> Expectation Source
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 -> Expectation Source
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"
around :: (IO () -> IO ()) -> Spec -> Spec Source
Run a custom action before and/or after every spec item.
runIO :: IO a -> SpecM a Source
Run an IO action while constructing the spec tree.
SpecM
is a monad to construct a spec tree, without executing any spec
items. runIO
allows you to run IO actions during this construction phase.
The IO action is always run when the spec tree is constructed (e.g. even
when --dry-run
is specified).
Running a spec
Run given spec and write a report to stdout
.
Exit with exitFailure
if at least one spec item fails.
Run given spec and write a report to stdout
.
Exit with exitFailure
if at least one spec item fails.
hspecWithFormatter :: IsFormatter a => a -> Spec -> IO () Source
postProcessSpec :: FilePath -> Spec -> Spec Source