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