Stability | unstable |
---|---|
Safe Haskell | None |
Language | Haskell2010 |
This module provides access to Hspec's internals. It is less stable than
other parts of the API. For most users Test.Hspec
is more suitable!
- describe :: String -> SpecWith a -> SpecWith a
- it :: Example a => String -> a -> SpecWith (Arg a)
- pending :: Expectation
- pendingWith :: String -> Expectation
- parallel :: SpecWith a -> SpecWith a
- type Spec = SpecWith ()
- type SpecWith a = SpecM a ()
- newtype SpecM a r = SpecM (WriterT [SpecTree a] IO r)
- runSpecM :: SpecWith a -> IO [SpecTree a]
- fromSpecList :: [SpecTree a] -> SpecWith a
- runIO :: IO r -> SpecM a r
- mapSpecTree :: (SpecTree a -> SpecTree b) -> SpecWith a -> SpecWith b
- mapSpecItem :: (ActionWith a -> ActionWith b) -> (Item a -> Item b) -> SpecWith a -> SpecWith b
- mapSpecItem_ :: (Item a -> Item a) -> SpecWith a -> SpecWith a
- modifyParams :: (Params -> Params) -> SpecWith a -> SpecWith a
- class Example e where
- type Arg e
- evaluateExample :: e -> Params -> (ActionWith (Arg e) -> IO ()) -> ProgressCallback -> IO Result
- data Params = Params {}
- defaultParams :: Params
- type ActionWith a = a -> IO ()
- type Progress = (Int, Int)
- type ProgressCallback = Progress -> IO ()
- data Result
- data Location = Location {}
- data LocationAccuracy
- type SpecTree a = Tree (ActionWith a) (Item a)
- data Tree c a
- data Item a = Item {
- itemRequirement :: String
- itemLocation :: Maybe Location
- itemIsParallelizable :: Bool
- itemExample :: Params -> (ActionWith a -> IO ()) -> ProgressCallback -> IO Result
- specGroup :: String -> [SpecTree a] -> SpecTree a
- specItem :: Example a => String -> a -> SpecTree (Arg a)
Defining a spec
describe :: String -> SpecWith a -> SpecWith a Source
The describe
function combines a list of specs into a larger spec.
it :: Example a => String -> a -> SpecWith (Arg a) Source
The it
function creates 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
pending
can be used to indicate that an example is pending.
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
pendingWith
is similar to pending
, but it takes an additional string
argument that can be used to specify the reason for why it's pending.
parallel :: SpecWith a -> SpecWith a Source
parallel
marks all spec items of the given spec to be safe for parallel
evaluation.
The SpecM
monad
A writer monad for SpecTree
forests
runIO :: IO r -> SpecM a r 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).
If you do not need the result of the IO action to construct the spec tree,
beforeAll
may be more suitable for your use case.
mapSpecItem :: (ActionWith a -> ActionWith b) -> (Item a -> Item b) -> SpecWith a -> SpecWith b Source
A type class for examples
A type class for examples
evaluateExample :: e -> Params -> (ActionWith (Arg e) -> IO ()) -> ProgressCallback -> IO Result Source
type ActionWith a = a -> IO () Source
An IO
action that expects an argument of type a
type ProgressCallback = Progress -> IO () Source
The result of running an example
Location
is used to represent source locations.
data LocationAccuracy Source
A marker for source locations
ExactLocation | The source location is accurate |
BestEffort | The source location was determined on a best-effort basis and my be wrong or inaccurate |
Internal representation of a spec tree
type SpecTree a = Tree (ActionWith a) (Item a) Source
A tree is used to represent a spec internally. The tree is parametrize over the type of cleanup actions and the type of the actual spec items.
Internal tree data structure
Item
is used to represent spec items internally. A spec item consists of:
- a textual description of a desired behavior
- an example for that behavior
- additional meta information
Everything that is an instance of the Example
type class can be used as an
example, including QuickCheck properties, Hspec expectations and HUnit
assertions.
Item | |
|