hspec-0.6.1: Behavior Driven Development for Haskell

Test.Hspec.Core

Description

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

Synopsis

Documentation

data Result Source

The result of running an example.

Constructors

Success 
Fail String 
Pending String 

data Spec Source

Everything needed to specify and show a specific behavior.

Constructors

Spec 

Fields

name :: String

What is being tested, usually the name of a type.

requirement :: String

The specific behavior being tested.

result :: Result

The status of this behavior.

describeSource

Arguments

:: String

The name of what is being described, usually a function or type.

-> [IO (String, Result)]

A list of behaviors and examples, created by a list of it.

-> IO [IO Spec] 

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)
   ]

descriptions :: [IO [IO Spec]] -> IO [IO Spec]Source

Combine a list of descriptions.

safely :: Result -> IO ResultSource

Evaluate a Result. Any exceptions (undefined, etc.) are treated as failures.

class SpecVerifier a whereSource

Anything that can be used as an example of a behavior.

Methods

itSource

Arguments

:: String

A description of this behavior.

-> a

An example for this behavior.

-> IO (String, Result) 

Create a description and example of a behavior, a list of these is used by describe. Once you know what you want to specify, use this.

 describe "closeEnough" [
   it "is true if two numbers are almost the same"
     (1.001 `closeEnough` 1.002),

   it "is false if two numbers are not almost the same"
     (not $ 1.001 `closeEnough` 1.003)
   ]

Instances

pendingSource

Arguments

:: String

An explanation for why this behavior is pending.

-> Result 

Declare an example as not successful or failing but pending some other work. 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 "waiting for clarification from the designers")
   ]

quantify :: Num a => a -> String -> StringSource

Create a more readable display of a quantity of something.