Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
parsonsmatt opened this issue Apr 15, 2022 · 0 comments
Open

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

parsonsmatt opened this issue Apr 15, 2022 · 0 comments

Comments

@parsonsmatt
Copy link
Collaborator

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant