tasty-hspec-1.2.0.1: Hspec support for the Tasty test framework.
Safe HaskellNone
LanguageHaskell2010

Test.Tasty.Hspec

Description

hspec and tasty serve similar purposes; consider using one or the other.

However, in a pinch, this module allows you to run an hspec Spec as a tasty TestTree.

Synopsis

Tests

testSpecs :: Spec -> IO [TestTree] Source #

Create a list of tasty TestTree from an hspec Spec. This returns the same tests as testSpec but doesn't create a tasty test group from them.

Options

data TreatPendingAs Source #

How to treat hspec pending tests.

tasty does not have the concept of pending tests, so we must map them to either successes or failures. By default, they are treated as failures.

Set via the command line flag --treat-pending-as (success|failure).

Examples

The simplest usage of this library involves first creating a TestTree in IO, then running it with defaultMain.

main = do
  spec <- testSpec "spec" mySpec
  defaultMain
    (testGroup "tests"
      [ spec
      , ...
      ])

You can treat an pending/pendingWith test as a success instead of a failure (the default):

tests :: TestTree
tests =
  localOption TreatPendingAsSuccess $ testGroup "My Hspec TestTree"
    [ unsafePerformIO (testSpec "My first Hspec test" spec_firstHspecTest)
    , ...
    ]

If you don't do any IO during Spec creation, or the IO need not be performed at any particular time relative to other IO actions, it's perfectly fine to use unsafePerformIO.

main = do
  defaultMain
    (testGroup "tests"
      [ unsafePerformIO (testSpec "spec" mySpec)
      , ...
      ])