{-# LANGUAGE TypeFamilies #-}
module Test.Hspec.Contrib.Retry (retryWith) where
import Test.Hspec.Core.Spec
data Retry a = Retry Int a
instance Example a => Example (Retry a) where
type Arg (Retry a) = Arg a
evaluateExample (Retry n example) a b c
| n > 1 = do
result <- safeEvaluateExample example a b c
case result of
Result _ Success{} -> return result
Result _ Pending{} -> return result
Result _ Failure{} -> retry
| otherwise = evaluateExample example a b c
where
retry = evaluateExample (Retry (pred n) example) a b c
retryWith :: Int
-> a
-> Retry a
retryWith = Retry