/
PMockSpecs.purs
37 lines (30 loc) · 1.01 KB
/
PMockSpecs.purs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
module Test.PMockSpecs
( it
, mockIt
, runRuntimeThrowableFunction
) where
import Prelude
import Control.Monad.Error.Class (class MonadError, class MonadThrow)
import Effect.Exception (Error)
import Test.Spec (SpecT)
import Test.Spec as Spec
import Test.Spec.Assertions (fail)
foreign import _runRuntimeThrowableFunction :: forall r. (Unit -> r) -> TryCatchResult r
type TryCatchResult r = {
hasError :: Boolean,
error :: String,
result :: r
}
it :: forall m g. Monad m => MonadError Error g => String -> (Unit -> g Unit) -> SpecT g Unit m Unit
it name fun =
Spec.it name do
let
r = _runRuntimeThrowableFunction fun
if r.hasError then fail r.error else r.result
mockIt :: forall m g. Monad m => MonadError Error g => String -> (Unit -> g Unit) -> SpecT g Unit m Unit
mockIt = it
runRuntimeThrowableFunction :: forall r m. MonadThrow Error m => (Unit -> r) -> m Unit
runRuntimeThrowableFunction f =
let
r = _runRuntimeThrowableFunction f
in if r.hasError then fail r.error else pure unit