hspec / hspec-hedgehog

A library to integrate hedgehog tests into your hspec test suite.
https://hackage.haskell.org/package/hspec-hedgehog
Other
28 stars 6 forks source link

Investigation: `instance Example (a -> TestT IO ())` #18

Open parsonsmatt opened 2 years ago

parsonsmatt commented 2 years ago
instance Example (a -> TestT IO ()) where
    type Arg (a -> TestT IO ()) = Gen a

    evaluateExample example = 
        evaluateExample (\gen ->
            a <- forAll gen
            test (example a)

This puts the Gen into the hspec hooks.

beforeGen :: Gen a -> SpecWith (Gen a) -> Spec
beforeGen gen = beforeAll (pure gen)

beforeWithGen :: (a -> Gen b) -> SpecWith (Gen b) -> SpecWith (Gen a)
beforeWithGen mkGen =
    beforeAllWith $ \genA -> pure (genA >>= mkGen) 

But it also forbids you from providing "normal" values in to TestT. That's probably fine. After all you can always do pure :: a -> Gen a.