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
r <- safeEvaluateExample example a b c
case r of
Right result -> case result of
Success{} -> return result
Pending{} -> return result
Failure{} -> retry
Left _ -> retry
| otherwise = evaluateExample example a b c
where
retry = evaluateExample (Retry (pred n) example) a b c
retryWith :: Int
-> a
-> Retry a
retryWith = Retry