hspec-0.3.0: Behavior Driven Development for Haskell

Test.Hspec.Internal

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 [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 [Spec]] -> 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")
   ]

documentSpecs :: [Spec] -> [String]Source

Create a document of the given specs.

documentGroup :: [String] -> [Spec] -> ([String], [String])Source

Create a document of the given group of specs.

documentSpec :: [String] -> Spec -> ([String], String)Source

Create a document of the given spec.

timingSummary :: Double -> StringSource

Create a summary of how long it took to run the examples.

successSummary :: [Spec] -> StringSource

Create a summary of how many specs exist and how many examples failed.

pureHspecSource

Arguments

:: [Spec]

The specs you are interested in.

-> [String] 

Create a document of the given specs. This does not track how much time it took to check the examples. If you want a description of each spec and don't need to know how long it tacks to check, use this.

pureHspecBSource

Arguments

:: [Spec]

The specs you are interested in.

-> ([String], Bool) 

hspec :: IO [Spec] -> IO ()Source

Create a document of the given specs and write it to stdout. This does track how much time it took to check the examples. Use this if you want a description of each spec and do need to know how long it tacks to check the examples or want to write to stdout.

hspecB :: IO [Spec] -> IO BoolSource

Same as hspec except it returns a bool indicating if all examples ran without failures

hspecX :: IO [Spec] -> IO aSource

Same as hspec except the program exits successfull if all examples ran without failures or with an errorcode of 1 if any examples failed.

hHspecSource

Arguments

:: Handle

A handle for the stream you want to write to.

-> IO [Spec]

The specs you are interested in.

-> IO Bool 

Create a document of the given specs and write it to the given handle. This does track how much time it took to check the examples. Use this if you want a description of each spec and do need to know how long it tacks to check the examples or want to write to a file or other handle.

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

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

Create a more readable display of a quantity of something.