From 29c335af563799f4ae3df66ee9b131463452700a Mon Sep 17 00:00:00 2001 From: Mark Wotton Date: Mon, 21 Mar 2016 13:39:49 -0400 Subject: [PATCH] use Either rather than throwing an exception --- yesod-test/Yesod/Test.hs | 10 +++++----- yesod-test/test/main.hs | 7 ++----- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/yesod-test/Yesod/Test.hs b/yesod-test/Yesod/Test.hs index 32b6b0b1..4e7afe0e 100644 --- a/yesod-test/Yesod/Test.hs +++ b/yesod-test/Yesod/Test.hs @@ -700,18 +700,18 @@ get url = request $ do -- -- > followRedirect followRedirect :: Yesod site - => YesodExample site () + => YesodExample site (Either T.Text ()) followRedirect = do mr <- getResponse case mr of - Nothing -> failure "no response, so no redirect to follow" + Nothing -> return $ Left "no response, so no redirect to follow" Just r -> do if not ((H.statusCode $ simpleStatus r) `elem` [301,303]) - then failure "followRedirect called, but previous request was not a redirect" + then return $ Left "followRedirect called, but previous request was not a redirect" else do case lookup "Location" (simpleHeaders r) of - Nothing -> failure "No location header set" - Just h -> get (TE.decodeUtf8 h) + Nothing -> return $ Left "No location header set" + Just h -> get (TE.decodeUtf8 h) >> return (Right ()) -- | Sets the HTTP method used by the request. -- diff --git a/yesod-test/test/main.hs b/yesod-test/test/main.hs index c9271df7..3cee06be 100644 --- a/yesod-test/test/main.hs +++ b/yesod-test/test/main.hs @@ -231,13 +231,10 @@ main = hspec $ do bodyContains "we have been successfully redirected" - yit "throws an exception when no redirect was returned" $ do + yit "returns a Left when no redirect was returned" $ do get ("/" :: Text) statusIs 200 - -- This appears to be an HUnitFailure, which is not - -- exported, so I'm catching SomeException instead. - (r :: Either SomeException ()) <- try followRedirect - statusIs 200 + r <- followRedirect liftIO $ assertBool "expected exception" $ isLeft r instance RenderMessage LiteApp FormMessage where