Search code examples
haskellhspec

Is it possible to skip tests in HSpec test suite?


In most programming languages it is easy to skip a test in some circumstances. Is there a proper way to do that in haskell HSpec based test suite?


Solution

  • If I understand correctly, Core of HSpec doesn't have a special solution for this case. But you can skip tests without verbosity about it. For example:

    main = hspec $ do
        ...
        when isDatabaseServerRunning $ do
            describe "database" $ do
                it "test some one" $ do
                    ...
    

    Another solution maybe to use the function like mapSpecItem_ for changing result of test to Pending with a message about why was skipped. For example:

    skip :: String -> Bool -> SpecWith a -> SpecWith a
    skip   _ False = id
    skip why True  = mapSpecItem_ updateItem
      where
        updateItem x = x{itemExample = \_ _ _ -> return . Pending . Just $ why}