From a8f5418b22d86aec39438fe194e29a2761101983 Mon Sep 17 00:00:00 2001 From: Tom Sydney Kerckhove Date: Thu, 1 Feb 2018 18:48:54 +0100 Subject: [PATCH] yesodSpecWithSiteGenerator with an argument --- yesod-test/Yesod/Test.hs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/yesod-test/Yesod/Test.hs b/yesod-test/Yesod/Test.hs index 10f15f0a..f3a80280 100644 --- a/yesod-test/Yesod/Test.hs +++ b/yesod-test/Yesod/Test.hs @@ -34,6 +34,7 @@ module Yesod.Test yesodSpec , YesodSpec , yesodSpecWithSiteGenerator + , yesodSpecWithSiteGenerator' , yesodSpecApp , YesodExample , YesodExampleData(..) @@ -288,6 +289,24 @@ yesodSpecWithSiteGenerator getSiteAction yspecs = , yedResponse = Nothing } +yesodSpecWithSiteGenerator' :: YesodDispatch site + => (a -> IO site) + -> YesodSpec site + -> Hspec.SpecWith a +yesodSpecWithSiteGenerator' getSiteAction yspecs = + Hspec.fromSpecList $ map (unYesod getSiteAction) $ execWriter yspecs + where + unYesod getSiteAction' (YesodSpecGroup x y) = Hspec.specGroup x $ map (unYesod getSiteAction') y + unYesod getSiteAction' (YesodSpecItem x y) = Hspec.specItem x $ \a -> do + site <- getSiteAction' a + app <- toWaiAppPlain site + ST.evalStateT y YesodExampleData + { yedApp = app + , yedSite = site + , yedCookies = M.empty + , yedResponse = Nothing + } + -- | Same as yesodSpec, but instead of taking a site it -- takes an action which produces the 'Application' for each test. -- This lets you use your middleware from makeApplication