packages feed

hspec-yesod 0.2.0.1 → 0.2.1.0

raw patch · 3 files changed

+73/−13 lines, 3 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

+ Test.Hspec.Yesod: testModifyFoundation :: (site -> IO site) -> YesodExample site ()
+ Test.Hspec.Yesod: testModifyFoundationAndMiddleware :: (site -> Middleware -> IO (site, Middleware)) -> YesodExample site ()
+ Test.Hspec.Yesod: testModifyMiddleware :: (Middleware -> IO Middleware) -> YesodExample site ()

Files

ChangeLog.md view
@@ -1,5 +1,10 @@ # ChangeLog for hspec-yesod +## 0.2.1.0++- [#6](https://github.com/parsonsmatt/hspec-yesod/pull/6)+  - The function `testModifySite` is deprecated and replaced with `testModifyMiddleware`, `testModifyFoundation`, and `testModifyFoundationAndMiddleware`.+ ## 0.2.0.1  - Fixes unused import warnings in `Test.Hspec.Yesod.Internal`
hspec-yesod.cabal view
@@ -1,5 +1,5 @@ name:               hspec-yesod-version:            0.2.0.1+version:            0.2.1.0 license:            MIT license-file:       LICENSE author:             Nubis <nubis@woobiz.com.ar>, Matt Parsons <parsonsmatt@gmail.com>
src/Test/Hspec/Yesod.hs view
@@ -137,6 +137,9 @@      -- * Modify test site     , testModifySite+    , testModifyFoundation+    , testModifyMiddleware+    , testModifyFoundationAndMiddleware      -- * Modify test state     , testSetCookie@@ -471,14 +474,66 @@ testModifySite     :: (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-  (newSite, middleware) <- liftIO $ newSiteFn currentSite-  modify $ \yed -> yed-    { yedSite = newSite-    , yedMiddleware = middleware-    }+testModifySite newSiteFn =+    testModifyFoundationAndMiddleware $ \site _ -> do+        newSiteFn site +{-# DEPRECATED testModifySite+   [ "This function throws away the prior Middleware, which can break assumptions in tests."+   , "If you want this behavior, see 'testModifyMiddleware' which will allow you to modify the middleware directly."+   , "If you do not, see 'testModifyFoundation' which does not impact Middleware."+   ]+  #-}++-- | Modify the site's 'Middleware' for the remainder of the tests.+--+-- @since 0.2.1.0+testModifyMiddleware+    :: (Middleware -> IO Middleware)+    -> YesodExample site ()+testModifyMiddleware mkNewMiddleware =+    testModifyFoundationAndMiddleware $ \site middleware -> do+        newMiddleware <- mkNewMiddleware middleware+        pure (site, newMiddleware)++-- | Modify the @site@ without altering the 'Middleware'.+--+-- @since 0.2.1.0+testModifyFoundation+    :: (site -> IO site)+    -> YesodExample site ()+testModifyFoundation mkNewSite =+    testModifyFoundationAndMiddleware $ \site middleware -> do+        newSite <- mkNewSite site+        pure (newSite, middleware)++-- | Modify the @site@ and the 'Middleware' under test for the remainder of+-- the test.+--+-- 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.+--+-- ==== __Examples__+--+-- > post SendEmailR+-- > -- Assert email not created in database+-- > post SendEmailR+-- > -- Assert email created in database+--+-- > testModifyFoundationAndMiddleware (\site middleware -> do+-- >   pure (site { appRedisConnection = Nothing }, middleware)+-- > )+-- @since 0.2.1.0+testModifyFoundationAndMiddleware+    :: (site -> Middleware -> IO (site, Middleware))+    -> YesodExample site ()+testModifyFoundationAndMiddleware mkNewSiteAndMiddleware = do+    currentSite <- gets yedSite+    currentMiddleware <- gets yedMiddleware+    (newSite, newMiddleware) <- liftIO $ mkNewSiteAndMiddleware currentSite currentMiddleware+    modify $ \yed -> yed { yedSite = newSite, yedMiddleware = newMiddleware }+ -- | Sets a cookie -- -- ==== __Examples__@@ -605,7 +660,7 @@         isResponseUTF8ContentType = maybe False YT.Internal.contentTypeHeaderIsUtf8 mResponseContentType          responsePreview = T.unpack $ YT.Internal.getBodyTextPreview body-        previewFinal = if responsePreview == "" then "<empty response>" else +        previewFinal = if responsePreview == "" then "<empty response>" else                 if isResponseUTF8ContentType then T.unpack $ YT.Internal.getBodyTextPreview body                     else "<content-type not suitable for printing>" @@ -619,14 +674,14 @@    where     getRequestBodyPreview :: RequestBuilderData site -> T.Text-    getRequestBodyPreview RequestBuilderData{..} = +    getRequestBodyPreview RequestBuilderData{..} =         let mRequestContentType = lookup hContentType rbdHeaders             isRequestUTF8ContentType = maybe False YT.Internal.contentTypeHeaderIsUtf8 mRequestContentType         in case rbdPostData of                     MultipleItemsPostData xs -> case xs of                         [] -> "<empty body>"                         _ -> "<POST param preview not supported>"-                    BinaryPostData lbs -> if isRequestUTF8ContentType then +                    BinaryPostData lbs -> if isRequestUTF8ContentType then                         getRequestTextPreview lbs                         else "<empty body>" @@ -1406,8 +1461,8 @@     (TE.decodeUtf8 rbdMethod) <> " " <> getEncodedPath rbdPath <> (TE.decodeUtf8 $ H.renderQuery True rbdGets)  getEncodedPath :: [T.Text] -> T.Text-getEncodedPath pathSegments = -    if null pathSegments +getEncodedPath pathSegments =+    if null pathSegments         then "/"         else TE.decodeUtf8 $ Builder.toByteString $ H.encodePathSegments pathSegments