HORIZON HASKELLDocslts/ghc-9.10.xc74966e2026-09-27Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · c74966e · 2026-09-27

Modulehspec-meta-2.11.14Haskell2010

Test.Hspec.Meta

  • 6 types
  • 1 class
  • 57 values
typetype Spec = SpecWith ()
#

A SpecWith that can be evaluated directly by the hspec function as it does not require any parameters.

valuehspec :: Spec -> IO ()
#

Run a given spec and write a report to stdout. Exit with exitFailure if at least one spec item fails.

Note: hspec handles command-line options and reads config files. This is not always desirable. Use evalSpec and runSpecForest if you need more control over these aspects.

typetype SpecWith a = SpecM a ()
#

A SpecWith a represents a test or group of tests that require an a value to run.

In the common case, a Spec is a SpecWith () which requires () and can thus be executed with hspec.

To supply an argument to SpecWith tests to turn them into Spec, use functions from Test.Hspec.Core.Hooks such as around, before, mapSubject and similar.

Values of this type are created by it, describe and similar.

classclass Example e where
#

A type class for examples, that is to say, test bodies as used in it and similar functions.

Associated types

  • type family Arg e

    The argument type that is needed to run this Example. If Arg is (), no argument is required and the Example can be run as-is.

    The value of Arg is the difference between Test.Hspec.Core.Spec.Spec (aka Test.Hspec.Core.Hspec.SpecWith ()), which can be executed, and Test.Hspec.Core.Spec.SpecWith a, which cannot be executed without turning it into Test.Hspec.Core.Spec.Spec first.

    To supply an argument to examples, use the functions in Test.Hspec.Core.Hooks such as around, before, mapSubject and similar.

Instances8Example, …
  • Example PropertyDefined in hspec-meta-2.11.14 · Test.Hspec.Core.QuickCheck · orphan
  • Example BoolDefined in hspec-meta-2.11.14 · Test.Hspec.Core.Example
  • Example ExpectationDefined in hspec-meta-2.11.14 · Test.Hspec.Core.Example
  • Example ResultDefined in hspec-meta-2.11.14 · Test.Hspec.Core.Example
  • Example (a -> Property)Defined in hspec-meta-2.11.14 · Test.Hspec.Core.QuickCheck · orphan
  • Example (a -> Bool)Defined in hspec-meta-2.11.14 · Test.Hspec.Core.Example
  • Example (a -> Expectation)Defined in hspec-meta-2.11.14 · Test.Hspec.Core.Example
  • Example (a -> Result)Defined in hspec-meta-2.11.14 · Test.Hspec.Core.Example
familytype family Arg e
#

The argument type that is needed to run this Example. If Arg is (), no argument is required and the Example can be run as-is.

The value of Arg is the difference between Test.Hspec.Core.Spec.Spec (aka Test.Hspec.Core.Hspec.SpecWith ()), which can be executed, and Test.Hspec.Core.Spec.SpecWith a, which cannot be executed without turning it into Test.Hspec.Core.Spec.Spec first.

To supply an argument to examples, use the functions in Test.Hspec.Core.Hooks such as around, before, mapSubject and similar.

Instances8Arg, …
  • type Arg Property = ()Defined in hspec-meta-2.11.14 · Test.Hspec.Core.QuickCheck · orphan
  • type Arg Bool = ()Defined in hspec-meta-2.11.14 · Test.Hspec.Core.Example
  • type Arg Expectation = ()Defined in hspec-meta-2.11.14 · Test.Hspec.Core.Example
  • type Arg Result = ()Defined in hspec-meta-2.11.14 · Test.Hspec.Core.Example
  • type Arg (a -> Property) = aDefined in hspec-meta-2.11.14 · Test.Hspec.Core.QuickCheck · orphan
  • type Arg (a -> Bool) = aDefined in hspec-meta-2.11.14 · Test.Hspec.Core.Example
  • type Arg (a -> Expectation) = aDefined in hspec-meta-2.11.14 · Test.Hspec.Core.Example
  • type Arg (a -> Result) = aDefined in hspec-meta-2.11.14 · Test.Hspec.Core.Example
valueit :: (HasCallStack, Example a) => String -> a -> SpecWith (Arg a)
#

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

Example a optionally accepts an argument Arg a, which is then given to the test body. This is useful for provisioning resources for a test which are created and cleaned up outside the test itself. See Arg for details.

Note that this function is often on the scene of nasty type errors due to GHC failing to infer the type of do notation in the test body. It can be helpful to use TypeApplications to explicitly specify the intended Example type.

example 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
valuerunIO :: IO r -> SpecM a r
#

Run an IO action while constructing the spec tree.

SpecM is a monad to construct a spec tree, without executing any spec items itself. 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.

pending can be used to mark a spec item as 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
typetype ActionWith a = a -> IO ()
#

An IO action that expects an argument of type a.

This type is what Examples are ultimately unlifted into for execution.

valuearound
  1. :: (ActionWith a -> IO ())

    Function provided with an action to run the spec item as argument. It should return the action to actually execute the item.

  2. -> SpecWith a

    Spec to modify

  3. -> Spec
#

Run a custom action before and/or after every spec item, supplying it with an argument obtained via IO.

This is useful for tasks like creating a file handle or similar resource before a test and destroying it after the test.

valuemapSubject :: (b -> a) -> SpecWith a -> SpecWith b
#

Modify the subject under test.

Note that this resembles a contravariant functor on the first type parameter of SpecM. This is because the subject is passed inwards, as an argument to the spec item.

typetype HasCallStack = IP "callStack" CallStack
#

Request a CallStack.

NOTE: The implicit parameter ?callStack :: CallStack is an implementation detail and should not be considered part of the CallStack API, we may decide to change the implementation in the future.

typetype Selector a = a -> Bool
#

A Selector is a predicate; it can simultaneously constrain the type and value of an exception.

valuehspecResult :: Spec -> IO Summary
#

Run given spec and returns a summary of the test run.

Note: hspecResult does not exit with exitFailure on failing spec items. If you need this, you have to check the Summary yourself and act accordingly.