benri-hspec-0.1.0.1: Simplify tests where Either or Maybe types are returned from monadic code
Copyright(c) 2022 Tim Emiola
LicenseBSD3
MaintainerTim Emiola <adetokunbo@emio.la>
Safe HaskellSafe-Inferred
LanguageHaskell2010

Test.Hspec.Benri

Description

Provides convenient functions for writing hspec tests where test values are returned from a monad.

Synopsis

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

Expand
>>> 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

Expand
>>> 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

Expand
>>> 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

Expand
>>> 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

Expand
>>> 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

Expand
>>> endsLeft_ $ pure (readEither "not an int" :: Either String Int)

endsRight :: (HasCallStack, Show a, Eq a, Show b, Eq b) => IO (Either a b) -> b -> Expectation infix 1 Source #

action `endsRight` expected sets the expectation that action returns Right expected.

Example

Expand
>>> pure (readEither "1" :: Either String Int) `endsRight` 1

endsRight_ :: (Show a, Show b) => IO (Either a b) -> IO () Source #

endsRight_ action sets the expectation that action returns Right b.

Example

Expand
>>> endsRight_ $ pure (readEither "1" :: Either String Int)