hspec-core-2.10.9: A Testing Framework for Haskell
Stability unstable
Safe Haskell None
Language Haskell2010

Test.Hspec.Core.Spec

Description

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!

Synopsis

Defining a spec

it :: ( HasCallStack , 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

describe :: HasCallStack => String -> SpecWith a -> SpecWith a Source #

The describe function combines a list of specs into a larger spec.

pending :: HasCallStack => Expectation Source #

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

pendingWith :: HasCallStack => 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 the spec item is pending.

xit :: ( HasCallStack , Example a) => String -> a -> SpecWith ( Arg a) Source #

Changing it to xit marks the corresponding spec item as pending.

This can be used to temporarily disable a spec item.

xdescribe :: HasCallStack => String -> SpecWith a -> SpecWith a Source #

Changing describe to xdescribe marks all spec items of the corresponding subtree as pending.

This can be used to temporarily disable spec items.

focus :: SpecWith a -> SpecWith a Source #

focus focuses all spec items of the given spec.

Applying focus to a spec with focused spec items has no effect.

fit :: ( HasCallStack , Example a) => String -> a -> SpecWith ( Arg a) Source #

fit is an alias for fmap focus . it

fdescribe :: HasCallStack => String -> SpecWith a -> SpecWith a Source #

fdescribe is an alias for fmap focus . describe

parallel :: SpecWith a -> SpecWith a Source #

parallel marks all spec items of the given spec to be safe for parallel evaluation.

sequential :: SpecWith a -> SpecWith a Source #

sequential marks all spec items of the given spec to be evaluated sequentially.

The SpecM monad

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.

getSpecDescriptionPath :: SpecM a [ String ] Source #

Get the path of describe labels, from the root all the way in to the call-site of this function.

Example

Expand
>>> :{
runSpecM $ do
  describe "foo" $ do
    describe "bar" $ do
      getSpecDescriptionPath >>= runIO . print
:}
["foo","bar"]

Since: 2.10.0

A type class for examples

class Example e where Source #

A type class for examples

Associated Types

type Arg e Source #

type Arg e = ()

Instances

Instances details
Example Bool Source #
Instance details

Defined in Test.Hspec.Core.Example

Associated Types

type Arg Bool Source #

Example Property Source #
Instance details

Defined in Test.Hspec.Core.Example

Associated Types

type Arg Property Source #

Example Expectation Source #
Instance details

Defined in Test.Hspec.Core.Example

Example Result Source #
Instance details

Defined in Test.Hspec.Core.Example

Associated Types

type Arg Result Source #

Example (a -> Property ) Source #
Instance details

Defined in Test.Hspec.Core.Example

Associated Types

type Arg (a -> Property ) Source #

Example (a -> Expectation ) Source #
Instance details

Defined in Test.Hspec.Core.Example

Associated Types

type Arg (a -> Expectation ) Source #

Example (a -> Bool ) Source #
Instance details

Defined in Test.Hspec.Core.Example

Associated Types

type Arg (a -> Bool ) Source #

Example (a -> Result ) Source #
Instance details

Defined in Test.Hspec.Core.Example

Associated Types

type Arg (a -> Result ) Source #

type ActionWith a = a -> IO () Source #

An IO action that expects an argument of type a

Internal representation of a spec tree

type SpecTree a = Tree ( IO ()) ( Item a) Source #

A tree is used to represent a spec internally. The tree is parameterized over the type of cleanup actions and the type of the actual spec items.

data Tree c a Source #

Internal tree data structure

Instances

Instances details
Functor ( Tree c) Source #
Instance details

Defined in Test.Hspec.Core.Tree

Methods

fmap :: (a -> b) -> Tree c a -> Tree c b Source #

(<$) :: a -> Tree c b -> Tree c a Source #

Foldable ( Tree c) Source #
Instance details

Defined in Test.Hspec.Core.Tree

Traversable ( Tree c) Source #
Instance details

Defined in Test.Hspec.Core.Tree

Methods

traverse :: Applicative f => (a -> f b) -> Tree c a -> f ( Tree c b) Source #

sequenceA :: Applicative f => Tree c (f a) -> f ( Tree c a) Source #

mapM :: Monad m => (a -> m b) -> Tree c a -> m ( Tree c b) Source #

sequence :: Monad m => Tree c (m a) -> m ( Tree c a) Source #

( Eq c, Eq a) => Eq ( Tree c a) Source #
Instance details

Defined in Test.Hspec.Core.Tree

( Show c, Show a) => Show ( Tree c a) Source #
Instance details

Defined in Test.Hspec.Core.Tree

data Item a Source #

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.

Constructors

Item

Fields

specGroup :: HasCallStack => String -> [ SpecTree a] -> SpecTree a Source #

The specGroup function combines a list of specs into a larger spec.

specItem :: ( HasCallStack , Example e) => String -> e -> SpecTree ( Arg e) Source #

The specItem function creates a spec item.

bimapTree :: (a -> b) -> (c -> d) -> Tree a c -> Tree b d Source #

bimapForest :: (a -> b) -> (c -> d) -> [ Tree a c] -> [ Tree b d] Source #

Re-exports

type HasCallStack = ?callStack :: CallStack Source #

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.

Since: base-4.9.0.0