| Safe Haskell | None |
|---|
Test.Hspec.Expectations.Lifted
Contents
Description
Introductory documentation: https://github.com/sol/hspec-expectations#readme
- type Expectation = Assertion
- expectationFailure :: MonadIO m => String -> m ()
- shouldBe :: (Show a, Eq a, MonadIO m) => a -> a -> m ()
- shouldSatisfy :: (Show a, MonadIO m) => a -> (a -> Bool) -> m ()
- shouldContain :: (Show a, Eq a, MonadIO m) => [a] -> [a] -> m ()
- shouldReturn :: (Show a, Eq a, MonadIO m) => IO a -> a -> m ()
- shouldThrow :: (Exception e, MonadIO m) => IO a -> Selector e -> m ()
- type Selector a = a -> Bool
- anyException :: Selector SomeException
- anyErrorCall :: Selector ErrorCall
- anyIOException :: Selector IOException
- anyArithException :: Selector ArithException
- errorCall :: String -> Selector ErrorCall
Setting expectations
type Expectation = AssertionSource
expectationFailure :: MonadIO m => String -> m ()Source
This is just an alias for HUnit's assertFailure.
shouldBe :: (Show a, Eq a, MonadIO m) => a -> a -> m ()Source
actual `shouldBe` expected sets the expectation that actual is equal
to expected (this is just an alias for @?=).
shouldSatisfy :: (Show a, MonadIO m) => a -> (a -> Bool) -> m ()Source
v `shouldSatisfy` p sets the expectation that p v is True.
shouldContain :: (Show a, Eq a, MonadIO m) => [a] -> [a] -> m ()Source
list `shouldContain` sublist sets the expectation that sublist is contained,
wholly and intact, anywhere in the second.
shouldReturn :: (Show a, Eq a, MonadIO m) => IO a -> a -> m ()Source
action `shouldReturn` expected sets the expectation that action
returns expected.
Expecting exceptions
shouldThrow :: (Exception e, MonadIO m) => IO a -> Selector e -> m ()Source
action `shouldThrow` selector sets the expectation that action throws
an exception. The precise nature of the expected exception is described
with a Selector.
Selecting exceptions
type Selector a = a -> BoolSource
A Selector is a predicate; it can simultaneously constrain the type and
value of an exception.
Predefined type-based selectors
There are predefined selectors for some standard exceptions. Each selector
is just const True with an appropriate type.
Combinators for defining value-based selectors
Some exceptions (most prominently ErrorCall) have no Eq instance.
Selecting a specific value would require pattern matching.
For such exceptions, combinators that construct selectors are provided. Each combinator corresponds to a constructor; it takes the same arguments, and has the same name (but starting with a lower-case letter).