vendredi 29 mai 2015

Access a value set up by `beforeAll` during tests

Here's what I've got:

spec :: Spec
spec = do
  manager <- runIO newManager

  it "foo" $ do
    -- code that uses manager

  it "bar" $ do
    -- code that usees manager

The docs for runIO suggest that I should probably be using beforeAll instead, since I do not need manager to construct the spec tree, I just need it to run each test, and in my use case it's better for them to all share the same manager rather than creating a new one for each test.

If you do not need the result of the IO action to construct the spec tree, beforeAll may be more suitable for your use case.

beforeAll :: IO a -> SpecWith a -> Spec

But I can't figure out how to access the manager from the tests.

spec :: Spec
spec = beforeAll newManager go

go :: SpecWith Manager
go = do
  it "foo" $ do
    -- needs "manager" in scope
  it "bar" $ do
    -- needs "manager" in scope

Aucun commentaire:

Enregistrer un commentaire