From 0aa1765b6c35b21800fd2bab93ceba162f6567d5 Mon Sep 17 00:00:00 2001 From: Tom Sydney Kerckhove Date: Thu, 26 Apr 2018 11:00:48 +0200 Subject: [PATCH] Updated according to review --- yesod-test/ChangeLog.md | 4 ++++ yesod-test/Yesod/Test.hs | 27 ++++++++++----------------- yesod-test/yesod-test.cabal | 2 +- 3 files changed, 15 insertions(+), 18 deletions(-) diff --git a/yesod-test/ChangeLog.md b/yesod-test/ChangeLog.md index 3941b750..3cf743fd 100644 --- a/yesod-test/ChangeLog.md +++ b/yesod-test/ChangeLog.md @@ -1,3 +1,7 @@ +## 1.6.4 +Add yesodSpecWithSiteGeneratorAndArgument +[#1485](https://github.com/yesodweb/yesod/pull/1485) + ## 1.6.3 Add performMethod [#1502](https://github.com/yesodweb/yesod/pull/1502) diff --git a/yesod-test/Yesod/Test.hs b/yesod-test/Yesod/Test.hs index f3a80280..e5efbf28 100644 --- a/yesod-test/Yesod/Test.hs +++ b/yesod-test/Yesod/Test.hs @@ -34,7 +34,7 @@ module Yesod.Test yesodSpec , YesodSpec , yesodSpecWithSiteGenerator - , yesodSpecWithSiteGenerator' + , yesodSpecWithSiteGeneratorAndArgument , yesodSpecApp , YesodExample , YesodExampleData(..) @@ -275,32 +275,25 @@ yesodSpecWithSiteGenerator :: YesodDispatch site => IO site -> YesodSpec site -> Hspec.Spec -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 $ do - site <- getSiteAction' - app <- toWaiAppPlain site - evalSIO y YesodExampleData - { yedApp = app - , yedSite = site - , yedCookies = M.empty - , yedResponse = Nothing - } +yesodSpecWithSiteGenerator getSiteAction = + yesodSpecWithSiteGeneratorAndArgument (const getSiteAction) -yesodSpecWithSiteGenerator' :: YesodDispatch site +-- | Same as yesodSpecWithSiteGenerator, but also takes an argument to build the site +-- and makes that argument available to the tests. +-- +-- @since 1.6.4 +yesodSpecWithSiteGeneratorAndArgument :: YesodDispatch site => (a -> IO site) -> YesodSpec site -> Hspec.SpecWith a -yesodSpecWithSiteGenerator' getSiteAction yspecs = +yesodSpecWithSiteGeneratorAndArgument 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 + evalSIO y YesodExampleData { yedApp = app , yedSite = site , yedCookies = M.empty diff --git a/yesod-test/yesod-test.cabal b/yesod-test/yesod-test.cabal index ddc5519c..0255cde5 100644 --- a/yesod-test/yesod-test.cabal +++ b/yesod-test/yesod-test.cabal @@ -1,5 +1,5 @@ name: yesod-test -version: 1.6.3 +version: 1.6.4 license: MIT license-file: LICENSE author: Nubis