HSpec beforeAll - Haskell

Welcome to the Functional Programming Zulip Chat Archive. You can join the chat here.

Jonathan Lorimer

Hey everyone, I am working with Hspec and I am trying to nest beforeAll functions such that I get something like this:

describe "tests" $ do
  beforeAll getGlobalKeys $ do
    describe "tests that use global keys" $ do
      it "yada yada" $ \GlobalKeys k -> ...
    beforeAll getLocalKeys $ do
      describe "tests that use local keys" $ do
        it "yada yada" $ \LocalKeys k -> ...

the problem is that I am getting this error:

    • Couldn't match type '()' with 'GlobalKeys'
      Expected type: hspec-core-2.7.1:Test.Hspec.Core.Spec.Monad.SpecM
                       GlobalKeys ()
        Actual type: Spec

I assume this is because the type this type beforeAll :: IO a -> SpecWith a -> Spec
is there a common solution for this pattern i.e. every test depends on running an IO action and some result, but then a subset of the tests depend on running a different IO action and that result?

Jonathan Lorimer

Nevermind, just simplified my test setup instead!