diff --git a/yesod-test/Yesod/Test.hs b/yesod-test/Yesod/Test.hs index 5b1bc3ee..4d922d6f 100644 --- a/yesod-test/Yesod/Test.hs +++ b/yesod-test/Yesod/Test.hs @@ -28,6 +28,7 @@ module Yesod.Test yesodSpec , YesodSpec , yesodSpecWithSiteGenerator + , yesodSpecApp , YesodExample , YesodExampleData(..) , YesodSpecTree (..) @@ -235,6 +236,27 @@ yesodSpecWithSiteGenerator getSiteAction yspecs = , 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 +yesodSpecApp :: YesodDispatch site + => site + -> IO Application + -> YesodSpec site + -> Hspec.Spec +yesodSpecApp site getApp yspecs = + Core.fromSpecList $ map unYesod $ execWriter yspecs + where + unYesod (YesodSpecGroup x y) = Core.SpecGroup x $ map unYesod y + unYesod (YesodSpecItem x y) = Core.it x $ do + app <- getApp + ST.evalStateT y YesodExampleData + { yedApp = app + , yedSite = site + , yedCookies = M.empty + , yedResponse = Nothing + } + -- | Describe a single test that keeps cookies, and a reference to the last response. yit :: String -> YesodExample site () -> YesodSpec site yit label example = tell [YesodSpecItem label example] diff --git a/yesod-test/yesod-test.cabal b/yesod-test/yesod-test.cabal index 8a322391..02400a24 100644 --- a/yesod-test/yesod-test.cabal +++ b/yesod-test/yesod-test.cabal @@ -1,5 +1,5 @@ name: yesod-test -version: 1.2.4 +version: 1.2.5 license: MIT license-file: LICENSE author: Nubis