hspec-1.1.3: Behavior Driven Development for Haskell

Safe HaskellSafe-Infered

Test.Hspec.Core

Contents

Description

This module contains the core types, constructors, classes, instances, and utility functions common to hspec.

Synopsis

Types

type Specs = [Spec]Source

class Example a whereSource

A type class for examples.

To use an HUnit Test or an Assertion as an example you need to import Test.Hspec.HUnit.

To use a QuickCheck Property as an example you need to import Test.Hspec.QuickCheck.

Defining a spec

it :: Example a => String -> a -> SpecSource

Create a set of specifications for a specific type being described. Once you know what you want specs for, use this.

 describe "abs" [
   it "returns a positive number given a negative number"
     (abs (-1) == 1)
   ]

pending :: String -> PendingSource

A pending example.

If you want to report on a behavior but don't have an example yet, use this.

 describe "fancyFormatter" [
   it "can format text in a way that everyone likes" $
     pending
 ]

You can give an optional reason for why it's pending.

 describe "fancyFormatter" [
   it "can format text in a way that everyone likes" $
     pending "waiting for clarification from the designers"
 ]

Running a spec

hspec :: Specs -> IO [EvaluatedSpec]Source

Create a document of the given specs and write it to stdout.

hspecB :: Specs -> IO BoolSource

Use in place of hspec to also give a Bool success indication

hspecX :: Specs -> IO aSource

Use in place of hspec to also exit the program with an ExitCode

hHspec :: Handle -> Specs -> IO [EvaluatedSpec]Source

Create a document of the given specs and write it to the given handle.

 writeReport filename specs = withFile filename WriteMode (\h -> hHspec h specs)

Internals

data SpecTree a Source

Internal representation of a spec.

This will be made abstract with the next release. If you still need access to any constructors, open an issue and describe your use case: https://github.com/hspec/hspec/issues

data Result Source

The result of running an example.

quantify :: (Show a, Num a, Eq a) => a -> String -> StringSource

Create a more readable display of a quantity of something.

Deprecated types and functions

The following types and functions are deprecated and will be removed with the next release.

If you still need any of those, please open an issue and describe your use case: https://github.com/hspec/hspec/issues

descriptions :: Specs -> SpecsSource

DEPRECATED: This is no longer needed (it's just an alias for id now).