Copyright | (c) 2022 Tim Emiola |
---|---|
License | BSD3 |
Maintainer | Tim Emiola <adetokunbo@emio.la> |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
Provides convenient functions for writing hspec tests where test values are returned from a monad.
Synopsis
- endsThen :: Show a => IO a -> (a -> Bool) -> IO ()
- endsJust :: (HasCallStack, Show a, Eq a) => IO (Maybe a) -> a -> Expectation
- endsJust_ :: Show a => IO (Maybe a) -> IO ()
- endsNothing :: (Show a, Eq a) => IO (Maybe a) -> IO ()
- endsLeft :: (HasCallStack, Show a, Eq a, Show b, Eq b) => IO (Either a b) -> a -> Expectation
- endsLeft_ :: (Show a, Show b) => IO (Either a b) -> IO ()
- endsRight :: (HasCallStack, Show a, Eq a, Show b, Eq b) => IO (Either a b) -> b -> Expectation
- endsRight_ :: (Show a, Show b) => IO (Either a b) -> IO ()
match a predicate
endsThen :: Show a => IO a -> (a -> Bool) -> IO () infix 1 Source #
action `endsThen` expected
sets the expectation that the result of
action
satisfies the predicate p
.
Example
>>>
pure (readMaybe "1" :: Maybe Int) `endsThen` isJust
>>>
pure (readMaybe "not a number" :: Maybe Int) `endsThen` isNothing
Maybe
values
endsJust :: (HasCallStack, Show a, Eq a) => IO (Maybe a) -> a -> Expectation infix 1 Source #
action `endsJust` expected
sets the expectation that action
returns
Just expected
.
Example
>>>
pure (readMaybe "1" :: Maybe Int) `endsJust` 1
endsJust_ :: Show a => IO (Maybe a) -> IO () Source #
endsJust_ action
sets the expectation that action
returns Just a
.
Example
>>>
endsJust_ $ pure (readMaybe "1" :: Maybe Int)
endsNothing :: (Show a, Eq a) => IO (Maybe a) -> IO () Source #
endsNothing action
sets the expectation that action
returns
Nothing
.
Example
>>>
endsNothing $ pure (readMaybe "not an int" :: Maybe Int)
Either
values
endsLeft :: (HasCallStack, Show a, Eq a, Show b, Eq b) => IO (Either a b) -> a -> Expectation infix 1 Source #
action `endsLeft` expected
sets the expectation that action
returns
Left expected
.
Example
>>>
pure (readEither "not an int" :: Either String Int) `endsLeft` "Prelude.read: no parse"
endsLeft_ :: (Show a, Show b) => IO (Either a b) -> IO () Source #
endsLeft_ action
sets the expectation that action
returns Left a
.
Example
>>>
endsLeft_ $ pure (readEither "not an int" :: Either String Int)