Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- data MockState m = MockState {
- mockExpectSet :: ExpectSet (Step m)
- mockDefaults :: [Step m]
- mockClasses :: Set TypeRep
- initMockState :: MockState m
- newtype MockT m a where
- mapMockT :: (m a -> m b) -> MockT m a -> MockT m b
- initClassIfNeeded :: forall cls m proxy. (Mockable cls, Typeable m, MonadIO m) => proxy cls -> MockT m ()
- initClassesAsNeeded :: MonadIO m => ExpectSet (Step m) -> MockT m ()
- runMockT :: forall m a. MonadIO m => MockT m a -> m a
- withMockT :: forall m b. MonadIO m => ((forall a. MockT m a -> m a) -> MockT m b) -> m b
- describeExpectations :: MonadIO m => MockT m String
- verifyExpectations :: MonadIO m => MockT m ()
- byDefault :: forall cls name m r. (MonadIO m, MockableMethod cls name m r) => Rule cls name m r -> MockT m ()
- mockMethodImpl :: forall cls name m r. (HasCallStack, MonadIO m, MockableMethod cls name m r) => r -> Action cls name m r -> MockT m r
- mockMethod :: forall cls name m r. (HasCallStack, MonadIO m, MockableMethod cls name m r, Default r) => Action cls name m r -> MockT m r
- mockDefaultlessMethod :: forall cls name m r. (HasCallStack, MonadIO m, MockableMethod cls name m r) => Action cls name m r -> MockT m r
- noMatchError :: (HasCallStack, Mockable cls) => Action cls name m a -> String
- partialMatchError :: (HasCallStack, Mockable cls) => Action cls name m a -> [String] -> String
Documentation
MockState | |
|
initMockState :: MockState m Source #
newtype MockT m a where Source #
Monad transformer for running mocks.
Instances
initClassIfNeeded :: forall cls m proxy. (Mockable cls, Typeable m, MonadIO m) => proxy cls -> MockT m () Source #
runMockT :: forall m a. MonadIO m => MockT m a -> m a Source #
Runs a test in the MockT
monad, handling all of the mocks.
withMockT :: forall m b. MonadIO m => ((forall a. MockT m a -> m a) -> MockT m b) -> m b Source #
Runs a test in the MockT
monad. The test can unlift other MockT pieces
to the base monad while still acting on the same set of expectations. This
can be useful for testing concurrency or similar mechanisms.
test =withMockT
$
inMockT -> doexpect
$
...liftIO
$
forkIO
$
inMockT firstThreadliftIO
$
forkIO
$
inMockT secondThread
This is a low-level primitive. Consider using the unliftio
package for
higher level implementations of multithreading and other primitives.
describeExpectations :: MonadIO m => MockT m String Source #
Fetches a String
that describes the current set of outstanding
expectations. This is sometimes useful for debugging test code. The exact
format is not specified.
verifyExpectations :: MonadIO m => MockT m () Source #
Verifies that all mock expectations are satisfied. You normally don't need
to do this, because it happens automatically at the end of your test in
runMockT
. However, it's occasionally useful to check expectations in the
middle of a test, such as before going on to the next stage.
Use of verifyExpectations
might signify that you are doing too much in a
single test. Consider splitting large tests into a separate test for each
case.
byDefault :: forall cls name m r. (MonadIO m, MockableMethod cls name m r) => Rule cls name m r -> MockT m () Source #
Changes the default response for matching actions.
Without byDefault
, actions with no explicit response will return the
Default
value for the type, or undefined
if the return type isn't an
instance of Default
. byDefault
replaces that with a new default
response, also overriding any previous defaults. The rule passed in must have
exactly one response.
mockMethodImpl :: forall cls name m r. (HasCallStack, MonadIO m, MockableMethod cls name m r) => r -> Action cls name m r -> MockT m r Source #
mockMethod :: forall cls name m r. (HasCallStack, MonadIO m, MockableMethod cls name m r, Default r) => Action cls name m r -> MockT m r Source #
Implements a method in a Mockable
monad by delegating to the mock
framework. If the method is called unexpectedly, an exception will be
thrown. However, an expected invocation without a specified response will
return the default value.
mockDefaultlessMethod :: forall cls name m r. (HasCallStack, MonadIO m, MockableMethod cls name m r) => Action cls name m r -> MockT m r Source #
Implements a method in a Mockable
monad by delegating to the mock
framework. If the method is called unexpectedly, an exception will be
thrown. However, an expected invocation without a specified response will
return undefined. This can be used in place of mockMethod
when the return
type has no default.
:: (HasCallStack, Mockable cls) | |
=> Action cls name m a | The action that was received. |
-> String |
:: (HasCallStack, Mockable cls) | |
=> Action cls name m a | The action that was received. |
-> [String] | Descriptions of the matchers that most closely matched, closest first. |
-> String |