Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
This module defines the Rule
type, which describes a matcher for methods
and a (possibly empty) list of responses to use for successive calls to
matching methods. The Expectable
type class generalizes Rule
, so that
you can specify a bare Matcher
or Action
in most situations where a
Rule
is needed but you don't want to provide a response.
Synopsis
- data Rule (cls :: (Type -> Type) -> Constraint) (name :: Symbol) (m :: Type -> Type) (r :: Type)
- class Expectable cls name m r ex | ex -> cls name m r where
- (|->) :: (Monad m, Expectable cls name m r ex) => ex -> r -> Rule cls name m r
- (|=>) :: Expectable cls name m r ex => ex -> (Action cls name m r -> MockT m r) -> Rule cls name m r
- data WholeMethodMatcher cls name m r where
- SuchThat :: Matcher cls name m r -> (Action cls name m r -> Bool) -> WholeMethodMatcher cls name m r
Documentation
data Rule (cls :: (Type -> Type) -> Constraint) (name :: Symbol) (m :: Type -> Type) (r :: Type) Source #
A rule for matching a method and responding to it when it matches.
The method may be matched by providing either an Action
to match exactly,
or a Matcher
. Exact matching is only available when all method arguments
A Rule
may have zero or more responses, which are attached using
|->
and |=>
. If there are no responses
for a Rule
, then there must be a default response for that action, and it
is used. If more than one response is added, the rule will perform the
responses in order, repeating the last response if there are additional
matches.
Example:
expect
$ GetLine_anything
|->
"hello"|=>
(GetLine prompt) -> "The prompt was " ++ prompt|->
"quit"
Instances
Expectable cls name m r (Rule cls name m r) Source # | |
class Expectable cls name m r ex | ex -> cls name m r where Source #
Class for things that can be expected. This is includes Rule
s, but also
bare Matcher
s and Action
s with no explicit response.
toRule :: ex -> Rule cls name m r Source #
Converts an expectable to a Rule that means the same thing.
Instances
Expectable cls name m r (WholeMethodMatcher cls name m r) Source # | |
Defined in Test.HMock.Rule toRule :: WholeMethodMatcher cls name m r -> Rule cls name m r Source # | |
Expectable cls name m r (Matcher cls name m r) Source # | |
Expectable cls name m r (Rule cls name m r) Source # | |
(|=>) :: Expectable cls name m r ex => ex -> (Action cls name m r -> MockT m r) -> Rule cls name m r infixl 1 Source #
Attaches a response to an expectation. This is a flexible response,
which can look at arguments, do things in the base monad, set up more
expectations, etc. A matching Action
is passed to the response.
data WholeMethodMatcher cls name m r where Source #
A way to match an entire action, using conditions that might depend on the relationship between arguments.
SuchThat :: Matcher cls name m r -> (Action cls name m r -> Bool) -> WholeMethodMatcher cls name m r |
Instances
Expectable cls name m r (WholeMethodMatcher cls name m r) Source # | |
Defined in Test.HMock.Rule toRule :: WholeMethodMatcher cls name m r -> Rule cls name m r Source # |