Hspec: A Testing Framework for Haskell


Running individual spec items

You can run individual spec items that match a given pattern by passing --match PATTERN to your test driver. The PATTERN is matched against

To understand what exactly this means let's look at an example.


-- Spec.hs
import           Test.Hspec

main :: IO ()
main = hspec $ do
  describe "Prelude" $ do
    describe "reverse" $ do
      it "reverses a list" False
    describe "show" $ do
      it "shows its argument" True
runhaskell Spec.hs

    reverses a list []
    shows its argument []


  1) Prelude.reverse reverses a list

  To rerun use: --match "/Prelude/reverse/reverses a list/"

Randomized with seed 921447365

Finished in 0.0005 seconds
2 examples, 1 failure

This spec contains one failing spec item.

The /-separated path of that spec item is:

Prelude/reverse/reverses a list

The pretty-printed path as it appears in the test output is:

Prelude.reverse reverses a list

You can rerun the failing spec item by either matching on the /-separated path or the pretty-printed path. Both of the following options lead to the same result:

runhaskell Spec.hs -m "Prelude/reverse/reverses a list"
runhaskell Spec.hs -m "Prelude.reverse reverses a list"

Or you can match on any substring of one of the above, e.g.:

runhaskell Spec.hs -m reverse

Note: Do not rely on the pretty-printed path for scripting purpose; use the /-separated path instead!