unit testing - Access a value set up by `beforeAll` during tests -
here's i've got:
spec :: spec spec = manager <- runio newmanager "foo" $ -- code uses manager "bar" $ -- code usees manager
the docs runio
suggest should using beforeall
instead, since not need manager
construct spec tree, need run each test, , in use case it's better them share same manager rather creating new 1 each test.
if not need result of io action construct spec tree, beforeall may more suitable use case.
beforeall :: io -> specwith -> spec
but can't figure out how access manager tests.
spec :: spec spec = beforeall newmanager go go :: specwith manager go = "foo" $ -- needs "manager" in scope "bar" $ -- needs "manager" in scope
spec arguments passed blocks regular function arguments (look @ associated type of example
type class, if want understand what's going on). self-contained example be:
import test.hspec main :: io () main = hspec spec spec :: spec spec = beforeall (return "foo") $ describe "something" $ "some behavior" $ \xs -> xs `shouldbe` "foo" "some other behavior" $ \xs -> xs `shouldbe` "foo"
Comments
Post a Comment