| Stability | unstable |
|---|---|
| Safe Haskell | Safe-Inferred |
| Language | Haskell2010 |
Test.Hspec.Core.Extension
Description
Warning: This API is experimental.
Synopsis
- runIO :: IO r -> SpecM a r
- modifyConfig :: (Config -> Config) -> SpecWith a
- data Option
- registerOptions :: HasCallStack => [Option] -> SpecWith a
- registerTransformation :: (Config -> [SpecTree] -> [SpecTree]) -> SpecWith a
- data Config
- data Item a
- data SpecM a r
- type SpecWith a = SpecM a ()
- type SpecTree = SpecTree ()
Lifecycle of a test run
A test run goes through four distinct phases:
- A tree of spec items and a default
Configare constructed inSpecM. - Command-line options are parsed. This transforms the default
Configthat was constructed in phase 1. - The tree of spec items is transformed in various ways, depending on specific
Configvalues. - Each spec item is executed and its result is reported to the user.
An extension can directly influence phase 1, and indirectly influence phases 2-4.
When writing extensions the following imports are recommended:
import Test.Hspec.Core.Extension import Test.Hspec.Core.Extension.Config qualified as Config import Test.Hspec.Core.Extension.Option qualified as Option import Test.Hspec.Core.Extension.Item qualified as Item import Test.Hspec.Core.Extension.Spec qualified as Spec import Test.Hspec.Core.Extension.Tree qualified as Tree
Phase 1: Constructing a spec tree
An extension can use
Spec.to transform spec items in phase 1.mapItemsItem.can be used to add custom metadata to a specsetAnnotationItem.
An extension can use
modifyConfigto modify the default config.Config.can be used to add custom metadata to the defaultsetAnnotationConfig.
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.
Phase 2: Parsing command-line options
An extension can use registerOptions during phase 1 to register custom command-line options, and as a consequence indirectly influence this phase.
- Options can use
Config.to add custom metadata to thesetAnnotationConfig.
registerOptions :: HasCallStack => [Option] -> SpecWith a Source #
Phase 3: Transforming the spec tree
An extension can use registerTransformation during phase 1 to indirectly influence this phase.
registerTransformation :: (Config -> [SpecTree] -> [SpecTree]) -> SpecWith a Source #
Register a transformation that transforms the spec tree in phase 3.
The registered transformation can use:
Tree.to modify spec itemsmapItemsTree.to discard spec itemsfilterItemsConfig.to access custom config metadatagetAnnotationItem.to access custom item metadatagetAnnotation
Phase 4: Reporting results
An extension can register a custom formatter in phase 1 to indirectly influence this phase.
Types
Operations on these types are provided by the following modules respectively:
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.