| Copyright | (c) 2026 Institute for Digital Autonomy |
|---|---|
| License | EUPL-1.2 |
| Maintainer | IDA |
| Safe Haskell | Trustworthy |
| Language | Haskell2010 |
Effectful.Hspec
Description
Effectful bindings for the Hspec library
built on top of hunit-effectful.
Overview
This library provides Hspec's test combinators expressed in terms of the Hspec effect.
This effect allows you to intersperse test assertions with arbitrary other effects.
Example usage
Suppose we wish to test stateful operations on an account balance:
deposit :: (State Int :> es) => Int -> Eff es () deposit amount = modify (+ amount) balance :: (State Int :> es) => Eff es Int balance = get
withdraw :: (State Int :> es) => Int -> Eff es Bool
withdraw amount = do
funds <- balance
if funds < amount
then pure False
else do
put $ funds - amount
pure TrueUse describe to group related examples, it to state individual expectations
and setup/teardown combinators such as before_, after_, or around_ to
run the examples from a known initial state:
accountSpec :: (State Int :> es, Hspec :> es) => Eff es ()
accountSpec = describe "account" . before_ (put @Int 0) $ do
it "accumulates deposits" $ do
deposit 100
deposit 50
balance `shouldReturn` 150
it "checks for sufficient funds before withdrawing" $ do
deposit 100
withdraw 30 `shouldReturn` True
withdraw 1000 `shouldReturn` False
balance `shouldReturn` 70Finally, run the spec with runHspec, which also resolves the underlying HUnit effect:
main :: IO () main = runEff . runHspec . evalState @Int 0 $ accountSpec
Synopsis
- data Hspec (a :: Type -> Type) b
- type Expectation (es :: [Effect]) = Assertion es
- runHspecWith' :: forall (es :: [Effect]) a. (IOE :> es, HUnit :> es) => Config -> Eff (Hspec ': es) a -> Eff es a
- runHspecWith :: forall (es :: [Effect]) a. IOE :> es => Config -> Eff (Hspec ': es) a -> Eff es a
- runHspec' :: forall (es :: [Effect]) a. (IOE :> es, HUnit :> es) => Eff (Hspec ': es) a -> Eff es a
- runHspec :: forall (es :: [Effect]) a. IOE :> es => Eff (Hspec ': es) a -> Eff es a
- runHUnit :: forall (es :: [Effect]) a. IOE :> es => Eff (HUnit ': es) a -> Eff es a
- describe :: forall (es :: [Effect]) a. (HasCallStack, Hspec :> es) => String -> Eff es a -> Eff es a
- context :: forall (es :: [Effect]) a. (HasCallStack, Hspec :> es) => String -> Eff es a -> Eff es a
- it :: forall (es :: [Effect]). (HasCallStack, Hspec :> es) => String -> Eff es () -> Eff es ()
- specify :: forall (es :: [Effect]). (HasCallStack, Hspec :> es) => String -> Eff es () -> Eff es ()
- pending :: forall (es :: [Effect]). (HasCallStack, Hspec :> es) => Eff es ()
- pendingWith :: forall (es :: [Effect]). (HasCallStack, Hspec :> es) => String -> Eff es ()
- xit :: forall (es :: [Effect]). (HasCallStack, Hspec :> es) => String -> Eff es () -> Eff es ()
- xspecify :: forall (es :: [Effect]). (HasCallStack, Hspec :> es) => String -> Eff es () -> Eff es ()
- xdescribe :: forall (es :: [Effect]) a. (HasCallStack, Hspec :> es) => String -> Eff es a -> Eff es a
- xcontext :: forall (es :: [Effect]) a. (HasCallStack, Hspec :> es) => String -> Eff es a -> Eff es a
- focus :: forall (es :: [Effect]) a. (HasCallStack, Hspec :> es) => Eff es a -> Eff es a
- fit :: forall (es :: [Effect]). (HasCallStack, Hspec :> es) => String -> Eff es () -> Eff es ()
- fspecify :: forall (es :: [Effect]). (HasCallStack, Hspec :> es) => String -> Eff es () -> Eff es ()
- fdescribe :: forall (es :: [Effect]) a. (HasCallStack, Hspec :> es) => String -> Eff es a -> Eff es a
- fcontext :: forall (es :: [Effect]) a. (HasCallStack, Hspec :> es) => String -> Eff es a -> Eff es a
- parallel :: forall (es :: [Effect]) a. (HasCallStack, Hspec :> es) => Eff es a -> Eff es a
- sequential :: forall (es :: [Effect]) a. (HasCallStack, Hspec :> es) => Eff es a -> Eff es a
- before_ :: forall (es :: [Effect]) a. (HasCallStack, Hspec :> es) => Eff es () -> Eff es a -> Eff es a
- beforeAll_ :: forall (es :: [Effect]) a. (HasCallStack, Hspec :> es) => Eff es () -> Eff es a -> Eff es a
- after_ :: forall (es :: [Effect]) a. (HasCallStack, Hspec :> es) => Eff es () -> Eff es a -> Eff es a
- afterAll_ :: forall (es :: [Effect]) a. (HasCallStack, Hspec :> es) => Eff es () -> Eff es a -> Eff es a
- around_ :: forall (es :: [Effect]) a. (HasCallStack, Hspec :> es) => (Eff es () -> Eff es ()) -> Eff es a -> Eff es a
- aroundAll_ :: forall (es :: [Effect]) a. (HasCallStack, Hspec :> es) => (Eff es () -> Eff es ()) -> Eff es a -> Eff es a
- expectationFailure :: forall (es :: [Effect]). (HasCallStack, Hspec :> es) => String -> Expectation es
- shouldBe :: forall a (es :: [Effect]). (HasCallStack, Show a, Eq a, Hspec :> es) => a -> a -> Expectation es
- shouldSatisfy :: forall a (es :: [Effect]). (HasCallStack, Show a, Hspec :> es) => a -> (a -> Bool) -> Expectation es
- shouldStartWith :: forall a (es :: [Effect]). (HasCallStack, Show a, Eq a, Hspec :> es) => [a] -> [a] -> Expectation es
- shouldEndWith :: forall a (es :: [Effect]). (HasCallStack, Show a, Eq a, Hspec :> es) => [a] -> [a] -> Expectation es
- shouldContain :: forall a (es :: [Effect]). (HasCallStack, Show a, Eq a, Hspec :> es) => [a] -> [a] -> Expectation es
- shouldMatchList :: forall a (es :: [Effect]). (HasCallStack, Show a, Eq a, Hspec :> es) => [a] -> [a] -> Expectation es
- shouldReturn :: forall a (es :: [Effect]). (HasCallStack, Show a, Eq a, Hspec :> es) => Eff es a -> a -> Expectation es
- shouldNotBe :: forall a (es :: [Effect]). (HasCallStack, Show a, Eq a, Hspec :> es) => a -> a -> Expectation es
- shouldNotSatisfy :: forall a (es :: [Effect]). (HasCallStack, Show a, Hspec :> es) => a -> (a -> Bool) -> Expectation es
- shouldNotContain :: forall a (es :: [Effect]). (HasCallStack, Show a, Eq a, Hspec :> es) => [a] -> [a] -> Expectation es
- shouldNotReturn :: forall a (es :: [Effect]). (HasCallStack, Show a, Eq a, Hspec :> es) => Eff es a -> a -> Expectation es
- shouldThrow :: forall e (es :: [Effect]) a. (HasCallStack, Exception e, Hspec :> es) => Eff es a -> Selector e -> Expectation es
- anyException :: Selector SomeException
- data Config = Config {
- configIgnoreConfigFile :: Bool
- configDryRun :: Bool
- configFocusedOnly :: Bool
- configFailOnEmpty :: Bool
- configFailOnFocused :: Bool
- configFailOnPending :: Bool
- configFailOnEmptyDescription :: Bool
- configPrintSlowItems :: Maybe Int
- configPrintCpuTime :: Bool
- configFailFast :: Bool
- configRandomize :: Bool
- configSeed :: Maybe Integer
- configQuickCheckSeed :: Maybe Integer
- configFailureReport :: Maybe FilePath
- configRerun :: Bool
- configRerunAllOnSuccess :: Bool
- configFilterPredicate :: Maybe (Path -> Bool)
- configSkipPredicate :: Maybe (Path -> Bool)
- configQuickCheckMaxSuccess :: Maybe Int
- configQuickCheckMaxDiscardRatio :: Maybe Int
- configQuickCheckMaxSize :: Maybe Int
- configQuickCheckMaxShrinks :: Maybe Int
- configSmallCheckDepth :: Maybe Int
- configColorMode :: ColorMode
- configUnicodeMode :: UnicodeMode
- configDiff :: Bool
- configDiffContext :: Maybe Int
- configExternalDiff :: Maybe (Maybe Int -> String -> String -> IO ())
- configPrettyPrint :: Bool
- configPrettyPrintFunction :: Bool -> String -> String -> (String, String)
- configFormatException :: SomeException -> String
- configTimes :: Bool
- configExpertMode :: Bool
- configAvailableFormatters :: [(String, FormatConfig -> IO Format)]
- configFormat :: Maybe (FormatConfig -> IO Format)
- configFormatter :: Maybe Formatter
- configHtmlOutput :: Bool
- configConcurrentJobs :: Maybe Int
- configAnnotations :: Annotations
- defaultConfig :: Config
- type Spec = SpecWith ()
- type HasCallStack = ?callStack :: CallStack
- prop :: forall prop (es :: [Effect]). (HasCallStack, Testable prop, Hspec :> es) => String -> prop -> Eff es ()
- xprop :: forall prop (es :: [Effect]). (HasCallStack, Testable prop, Hspec :> es) => String -> prop -> Eff es ()
- fprop :: forall prop (es :: [Effect]). (HasCallStack, Testable prop, Hspec :> es) => String -> prop -> Eff es ()
Effect
data Hspec (a :: Type -> Type) b Source #
Instances
| type DispatchOf Hspec Source # | |
Defined in Effectful.Hspec | |
| data StaticRep Hspec Source # | |
type Expectation (es :: [Effect]) = Assertion es Source #
runHspecWith' :: forall (es :: [Effect]) a. (IOE :> es, HUnit :> es) => Config -> Eff (Hspec ': es) a -> Eff es a Source #
runHspecWith :: forall (es :: [Effect]) a. IOE :> es => Config -> Eff (Hspec ': es) a -> Eff es a Source #
runHspec' :: forall (es :: [Effect]) a. (IOE :> es, HUnit :> es) => Eff (Hspec ': es) a -> Eff es a Source #
Spec construction
describe :: forall (es :: [Effect]) a. (HasCallStack, Hspec :> es) => String -> Eff es a -> Eff es a Source #
Lifted describe.
context :: forall (es :: [Effect]) a. (HasCallStack, Hspec :> es) => String -> Eff es a -> Eff es a Source #
Lifted context.
it :: forall (es :: [Effect]). (HasCallStack, Hspec :> es) => String -> Eff es () -> Eff es () Source #
Lifted it.
specify :: forall (es :: [Effect]). (HasCallStack, Hspec :> es) => String -> Eff es () -> Eff es () Source #
Lifted specify.
pending :: forall (es :: [Effect]). (HasCallStack, Hspec :> es) => Eff es () Source #
Lifted pending.
pendingWith :: forall (es :: [Effect]). (HasCallStack, Hspec :> es) => String -> Eff es () Source #
Lifted pendingWith.
Skipping
xit :: forall (es :: [Effect]). (HasCallStack, Hspec :> es) => String -> Eff es () -> Eff es () Source #
Lifted xit.
xspecify :: forall (es :: [Effect]). (HasCallStack, Hspec :> es) => String -> Eff es () -> Eff es () Source #
Lifted xspecify.
xdescribe :: forall (es :: [Effect]) a. (HasCallStack, Hspec :> es) => String -> Eff es a -> Eff es a Source #
Lifted xdescribe.
xcontext :: forall (es :: [Effect]) a. (HasCallStack, Hspec :> es) => String -> Eff es a -> Eff es a Source #
Lifted xcontext.
Focusing
focus :: forall (es :: [Effect]) a. (HasCallStack, Hspec :> es) => Eff es a -> Eff es a Source #
Lifted focus.
fit :: forall (es :: [Effect]). (HasCallStack, Hspec :> es) => String -> Eff es () -> Eff es () Source #
Lifted fit.
fspecify :: forall (es :: [Effect]). (HasCallStack, Hspec :> es) => String -> Eff es () -> Eff es () Source #
Lifted fspecify.
fdescribe :: forall (es :: [Effect]) a. (HasCallStack, Hspec :> es) => String -> Eff es a -> Eff es a Source #
Lifted fdescribe.
fcontext :: forall (es :: [Effect]) a. (HasCallStack, Hspec :> es) => String -> Eff es a -> Eff es a Source #
Lifted fcontext.
parallel :: forall (es :: [Effect]) a. (HasCallStack, Hspec :> es) => Eff es a -> Eff es a Source #
Lifted parallel.
sequential :: forall (es :: [Effect]) a. (HasCallStack, Hspec :> es) => Eff es a -> Eff es a Source #
Lifted sequential.
Setup / Teardown
before_ :: forall (es :: [Effect]) a. (HasCallStack, Hspec :> es) => Eff es () -> Eff es a -> Eff es a Source #
Lifted before_.
beforeAll_ :: forall (es :: [Effect]) a. (HasCallStack, Hspec :> es) => Eff es () -> Eff es a -> Eff es a Source #
Lifted beforeAll_.
after_ :: forall (es :: [Effect]) a. (HasCallStack, Hspec :> es) => Eff es () -> Eff es a -> Eff es a Source #
Lifted after_.
afterAll_ :: forall (es :: [Effect]) a. (HasCallStack, Hspec :> es) => Eff es () -> Eff es a -> Eff es a Source #
Lifted afterAll_.
around_ :: forall (es :: [Effect]) a. (HasCallStack, Hspec :> es) => (Eff es () -> Eff es ()) -> Eff es a -> Eff es a Source #
Lifted around_.
aroundAll_ :: forall (es :: [Effect]) a. (HasCallStack, Hspec :> es) => (Eff es () -> Eff es ()) -> Eff es a -> Eff es a Source #
Lifted aroundAll_.
Expectations
expectationFailure :: forall (es :: [Effect]). (HasCallStack, Hspec :> es) => String -> Expectation es Source #
shouldBe :: forall a (es :: [Effect]). (HasCallStack, Show a, Eq a, Hspec :> es) => a -> a -> Expectation es infix 1 Source #
actual `shouldBe` expected sets the expectation that actual is equal
to expected.
shouldSatisfy :: forall a (es :: [Effect]). (HasCallStack, Show a, Hspec :> es) => a -> (a -> Bool) -> Expectation es infix 1 Source #
v `shouldSatisfy` p sets the expectation that p v is True.
shouldStartWith :: forall a (es :: [Effect]). (HasCallStack, Show a, Eq a, Hspec :> es) => [a] -> [a] -> Expectation es infix 1 Source #
list `shouldStartWith` prefix sets the expectation that list starts with prefix.
shouldEndWith :: forall a (es :: [Effect]). (HasCallStack, Show a, Eq a, Hspec :> es) => [a] -> [a] -> Expectation es infix 1 Source #
list `shouldEndWith` suffix sets the expectation that list ends with suffix.
shouldContain :: forall a (es :: [Effect]). (HasCallStack, Show a, Eq a, Hspec :> es) => [a] -> [a] -> Expectation es infix 1 Source #
list `shouldContain` sublist sets the expectation that sublist is contained,
wholly and intact, anywhere in list.
shouldMatchList :: forall a (es :: [Effect]). (HasCallStack, Show a, Eq a, Hspec :> es) => [a] -> [a] -> Expectation es infix 1 Source #
xs `shouldMatchList` ys sets the expectation that xs has the same
elements that ys has, possibly in another order.
shouldReturn :: forall a (es :: [Effect]). (HasCallStack, Show a, Eq a, Hspec :> es) => Eff es a -> a -> Expectation es infix 1 Source #
action `shouldReturn` expected sets the expectation that action
returns expected.
shouldNotBe :: forall a (es :: [Effect]). (HasCallStack, Show a, Eq a, Hspec :> es) => a -> a -> Expectation es infix 1 Source #
actual `shouldNotBe` notExpected sets the expectation that actual is not
equal to notExpected.
shouldNotSatisfy :: forall a (es :: [Effect]). (HasCallStack, Show a, Hspec :> es) => a -> (a -> Bool) -> Expectation es infix 1 Source #
v `shouldNotSatisfy` p sets the expectation that p v is False.
shouldNotContain :: forall a (es :: [Effect]). (HasCallStack, Show a, Eq a, Hspec :> es) => [a] -> [a] -> Expectation es infix 1 Source #
list `shouldNotContain` sublist sets the expectation that sublist is not
contained anywhere in list.
shouldNotReturn :: forall a (es :: [Effect]). (HasCallStack, Show a, Eq a, Hspec :> es) => Eff es a -> a -> Expectation es infix 1 Source #
action `shouldNotReturn` notExpected sets the expectation that action
does not return notExpected.
shouldThrow :: forall e (es :: [Effect]) a. (HasCallStack, Exception e, Hspec :> es) => Eff es a -> Selector e -> Expectation es infix 1 Source #
action `shouldThrow` selector sets the expectation that action throws
an exception. The precise nature of the expected exception is described
with a Selector.
Constructors
defaultConfig :: Config #
type HasCallStack = ?callStack :: CallStack #
Request a CallStack.
NOTE: The implicit parameter ?callStack :: CallStack is an
implementation detail and should not be considered part of the
CallStack API, we may decide to change the implementation in the
future.
Since: base-4.9.0.0
Properties
prop :: forall prop (es :: [Effect]). (HasCallStack, Testable prop, Hspec :> es) => String -> prop -> Eff es () Source #
Lifted prop.