| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Test.MockCat.WithMock
Description
This module provides a declarative way to define mock functions with expectations
that are automatically verified when the withMock block completes.
Example:
withMock $ do mockFn mock (any ~ True)expectsdo called oncewith"a" evaluate $ mockFn "a"
Synopsis
- withMock :: ReaderT WithMockContext IO a -> IO a
- expects :: forall m fn exp params. (MonadIO m, MonadWithMockContext m, ResolvableMock fn, ResolvableParamsOf fn ~ params, ExtractParams exp, ExpParams exp ~ params, BuildExpectations fn exp, Show params, Eq params) => m fn -> exp -> m fn
- called :: Called params => TimesSpec -> Expectations params ()
- with :: WithArgs exp args params => exp -> args -> Expectations params ()
- calledInOrder :: CalledInOrder args params => args -> Expectations params ()
- calledInSequence :: CalledInSequence args params => args -> Expectations params ()
- times :: Int -> TimesSpec
- once :: TimesSpec
- never :: TimesSpec
- atLeast :: Int -> TimesSpec
- anything :: VerificationSpec params
- newtype WithMockContext = WithMockContext (TVar [IO ()])
- class MonadWithMockContext (m :: Type -> Type) where
- data Expectation params where
- CountExpectation :: forall params. CountVerifyMethod -> params -> Expectation params
- CountAnyExpectation :: forall params. CountVerifyMethod -> Expectation params
- OrderExpectation :: forall params. VerifyOrderMethod -> [params] -> Expectation params
- SimpleExpectation :: forall params. params -> Expectation params
- AnyExpectation :: forall params. Expectation params
- newtype Expectations params a = Expectations (State [Expectation params] a)
Documentation
withMock :: ReaderT WithMockContext IO a -> IO a Source #
Run a block with mock expectations that are automatically verified
expects :: forall m fn exp params. (MonadIO m, MonadWithMockContext m, ResolvableMock fn, ResolvableParamsOf fn ~ params, ExtractParams exp, ExpParams exp ~ params, BuildExpectations fn exp, Show params, Eq params) => m fn -> exp -> m fn infixl 0 Source #
called :: Called params => TimesSpec -> Expectations params () Source #
with :: WithArgs exp args params => exp -> args -> Expectations params () Source #
calledInOrder :: CalledInOrder args params => args -> Expectations params () Source #
calledInSequence :: CalledInSequence args params => args -> Expectations params () Source #
times :: Int -> TimesSpec Source #
Create a times condition for exact count.
f `shouldBeCalled` times 3 f `shouldBeCalled` (times 3 `with` "arg")
Create a times condition for never (zero times). Equivalent to 'times 0'.
atLeast :: Int -> TimesSpec Source #
Create a times condition for at least count (>=).
f `shouldBeCalled` atLeast 1
anything :: VerificationSpec params Source #
Create a simple verification without arguments. It verifies that the function was called at least once, with ANY arguments.
f `shouldBeCalled` anything
newtype WithMockContext Source #
Mock expectation context holds verification actions to run at the end
of the withMock block. Storing `IO ()` avoids forcing concrete param
types at registration time.
Constructors
| WithMockContext (TVar [IO ()]) |
class MonadWithMockContext (m :: Type -> Type) where Source #
Methods
Instances
| MonadReader WithMockContext m => MonadWithMockContext m Source # | |
Defined in Test.MockCat.WithMock Methods | |
| Monad m => MonadWithMockContext (MockT m) Source # | |
Defined in Test.MockCat.MockT Methods | |
data Expectation params where Source #
Expectation specification
Constructors
| CountExpectation :: forall params. CountVerifyMethod -> params -> Expectation params | Count expectation with specific arguments |
| CountAnyExpectation :: forall params. CountVerifyMethod -> Expectation params | Count expectation without arguments (any arguments) |
| OrderExpectation :: forall params. VerifyOrderMethod -> [params] -> Expectation params | Order expectation |
| SimpleExpectation :: forall params. params -> Expectation params | Simple expectation (at least once) with arguments |
| AnyExpectation :: forall params. Expectation params | Simple expectation (at least once) without arguments |
newtype Expectations params a Source #
Expectations builder (Monad instance for do syntax)
Constructors
| Expectations (State [Expectation params] a) |
Instances
| Applicative (Expectations params) Source # | |
Defined in Test.MockCat.WithMock Methods pure :: a -> Expectations params a # (<*>) :: Expectations params (a -> b) -> Expectations params a -> Expectations params b # liftA2 :: (a -> b -> c) -> Expectations params a -> Expectations params b -> Expectations params c # (*>) :: Expectations params a -> Expectations params b -> Expectations params b # (<*) :: Expectations params a -> Expectations params b -> Expectations params a # | |
| Functor (Expectations params) Source # | |
Defined in Test.MockCat.WithMock Methods fmap :: (a -> b) -> Expectations params a -> Expectations params b # (<$) :: a -> Expectations params b -> Expectations params a # | |
| Monad (Expectations params) Source # | |
Defined in Test.MockCat.WithMock Methods (>>=) :: Expectations params a -> (a -> Expectations params b) -> Expectations params b # (>>) :: Expectations params a -> Expectations params b -> Expectations params b # return :: a -> Expectations params a # | |