Skip to content

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

@parsonsmatt

Description

@parsonsmatt
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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions