[yesod-test] Add testModifySite
This commit is contained in:
parent
a2d200c182
commit
cbef19fae9
@ -1,5 +1,9 @@
|
||||
# ChangeLog for yesod-test
|
||||
|
||||
## 1.6.8
|
||||
|
||||
Add `testModifySite` function [#](https://github.com/yesodweb/yesod/pull/)
|
||||
|
||||
## 1.6.7
|
||||
|
||||
Add `addBasicAuthHeader` function [#1632](https://github.com/yesodweb/yesod/pull/1632)
|
||||
|
||||
@ -344,15 +344,33 @@ yesodSpecApp site getApp yspecs =
|
||||
yit :: String -> YesodExample site () -> YesodSpec site
|
||||
yit label example = tell [YesodSpecItem label example]
|
||||
|
||||
-- | Modifies the site ('yedSite') of the test
|
||||
-- | Modifies the site ('yedSite') of the test, and creates a new WAI app ('yedApp') for it.
|
||||
--
|
||||
-- TODO documentation here
|
||||
-- yesod-test allows sending requests to your application to test that it handles them correctly.
|
||||
-- In rare cases, you may wish to modify that application in the middle of a test.
|
||||
-- This may be useful if you wish to, for example, test your application under a certain configuration,
|
||||
-- then change that configuration to see if your app responds differently.
|
||||
--
|
||||
-- TODO @since
|
||||
testModifySite :: YesodDispatch site => (site -> site) -> Middleware -> YesodExample site ()
|
||||
testModifySite newSiteFn middleware = do
|
||||
-- ==== __Examples__
|
||||
--
|
||||
-- > post SendEmailR
|
||||
-- > -- Assert email not created in database
|
||||
-- > testModifySite (\site -> pure (site { siteSettingsStoreEmail = True }, id))
|
||||
-- > post SendEmailR
|
||||
-- > -- Assert email created in database
|
||||
--
|
||||
-- > testModifySite (\site -> do
|
||||
-- > middleware <- makeLogware site
|
||||
-- > pure (site { appRedisConnection = Nothing }, middleware)
|
||||
-- > )
|
||||
--
|
||||
-- @since 1.6.8
|
||||
testModifySite :: YesodDispatch site
|
||||
=> (site -> IO (site, Middleware)) -- ^ A function from the existing site, to a new site and middleware for a WAI app.
|
||||
-> YesodExample site ()
|
||||
testModifySite newSiteFn = do
|
||||
currentSite <- getTestYesod
|
||||
let newSite = newSiteFn currentSite
|
||||
(newSite, middleware) <- liftIO $ newSiteFn currentSite
|
||||
app <- liftIO $ toWaiAppPlain newSite
|
||||
modifySIO $ \yed -> yed { yedSite = newSite, yedApp = middleware app }
|
||||
|
||||
|
||||
@ -453,7 +453,7 @@ main = hspec $ do
|
||||
yit "can change site value" $ do
|
||||
get ("/get-integer" :: Text)
|
||||
bodyContains "0"
|
||||
testModifySite (\site -> site { routedAppInteger = 1 }) id
|
||||
testModifySite (\site -> pure (site { routedAppInteger = 1 }, id))
|
||||
get ("/get-integer" :: Text)
|
||||
bodyContains "1"
|
||||
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
name: yesod-test
|
||||
version: 1.6.7
|
||||
version: 1.6.8
|
||||
license: MIT
|
||||
license-file: LICENSE
|
||||
author: Nubis <nubis@woobiz.com.ar>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user