tasty-hspec-1.2.0.4: Hspec support for the Tasty test framework.

Safe Haskell | Safe-Inferred
Language | Haskell2010

Test.Tasty.Hspec

Contents

- Tests
- Options
- Examples

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

- testSpec :: TestName -> Spec -> IO TestTree
- testSpecs :: Spec -> IO [TestTree]
- data TreatPendingAs
  - = TreatPendingAsFailure
  - | TreatPendingAsSuccess

# Tests

testSpec :: TestName -> Spec -> IO TestTree Source #

Create a tasty `TestTree` from an hspec `Spec`.

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)`.

Constructors

TreatPendingAsFailure | Default.
TreatPendingAsSuccess |

#### Instances

Instances details

IsOption TreatPendingAs Source # |
Instance details Defined in Test.Tasty.Hspec Methods defaultValue :: TreatPendingAs Source # parseValue :: String -> Maybe TreatPendingAs Source # optionName :: Tagged TreatPendingAs String Source # optionHelp :: Tagged TreatPendingAs String Source # showDefaultValue :: TreatPendingAs -> Maybe String Source # optionCLParser :: Parser TreatPendingAs Source #

# 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)
          , ...
          ])