hspec-wai 0.10.1 → 0.12.1
raw patch · 6 files changed
Files
- hspec-wai.cabal +13/−11
- src/Test/Hspec/Wai.hs +47/−3
- src/Test/Hspec/Wai/Internal.hs +1/−4
- src/Test/Hspec/Wai/Matcher.hs +2/−1
- src/Test/Hspec/Wai/Util.hs +2/−2
- test/Test/Hspec/WaiSpec.hs +1/−1
hspec-wai.cabal view
@@ -1,13 +1,11 @@ cabal-version: 1.12 --- This file has been generated from package.yaml by hpack version 0.31.2.+-- This file has been generated from package.yaml by hpack version 0.39.1. -- -- see: https://github.com/sol/hpack------ hash: cdec1913966ee86da27fb743e19bf06bc5822fe4611e017391f8d476ef5a6cc5 name: hspec-wai-version: 0.10.1+version: 0.12.1 homepage: https://github.com/hspec/hspec-wai#readme bug-reports: https://github.com/hspec/hspec-wai/issues license: MIT@@ -34,8 +32,9 @@ src ghc-options: -Wall build-depends:- QuickCheck- , base ==4.*+ HUnit+ , QuickCheck+ , base >=4.9.1.0 && <5 , base-compat , bytestring >=0.10 , case-insensitive@@ -45,7 +44,7 @@ , text , transformers , wai >=3- , wai-extra >=3+ , wai-extra >=3.1.14 exposed-modules: Test.Hspec.Wai Test.Hspec.Wai.QuickCheck@@ -63,9 +62,12 @@ src test ghc-options: -Wall+ build-tool-depends:+ hspec-discover:hspec-discover build-depends:- QuickCheck- , base ==4.*+ HUnit+ , QuickCheck+ , base >=4.9.1.0 && <5 , base-compat , bytestring >=0.10 , case-insensitive@@ -75,8 +77,8 @@ , http-types , text , transformers- , wai >=3- , wai-extra >=3+ , wai >=3.2.2+ , wai-extra >=3.1.14 other-modules: Test.Hspec.Wai Test.Hspec.Wai.Internal
src/Test/Hspec/Wai.hs view
@@ -1,3 +1,5 @@+{-# LANGUAGE TupleSections #-}+{-# LANGUAGE PackageImports #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE ConstraintKinds #-}@@ -36,22 +38,30 @@ , getState , pending , pendingWith+, annotate+, SResponse(..) ) where import Prelude ()-import Prelude.Compat+import "base-compat" Prelude.Compat import Data.Foldable import Data.ByteString (ByteString) import qualified Data.ByteString.Lazy as LB+import Control.Exception (Exception, handle, throwIO) import Control.Monad.IO.Class+import Control.Monad.Trans.Class (lift)+import Control.Monad.Trans.Reader+import Control.Monad.Trans.State (StateT(..))+ import Network.Wai (Request(..)) import Network.HTTP.Types import Network.Wai.Test hiding (request) import qualified Network.Wai.Test as Wai+import Test.HUnit.Lang (HUnitFailure(..), FailureReason(..)) import Test.Hspec.Expectations -import Test.Hspec.Core.Spec hiding (pending, pendingWith)+import Test.Hspec.Core.Spec hiding (pending, pendingWith, FailureReason(..)) import qualified Test.Hspec.Core.Spec as Core import Test.Hspec.Core.Hooks @@ -71,6 +81,40 @@ pending :: WaiSession st () pending = liftIO Core.pending +-- | -- If you have a test case that has multiple assertions, you can use the+-- 'annotate' function to provide a string message that will be attached to the+-- 'Expectation'.+--+-- @+-- describe "annotate" $ do+-- it "adds the message" $ do+-- annotate "obvious falsehood" $ do+-- True `shouldBe` False+--+-- ========>+--+-- 1) annotate, adds the message+-- obvious falsehood+-- expected: False+-- but got: True+-- @+annotate :: String -> WaiSession st a -> WaiSession st a+annotate message = handleWai $ \ (HUnitFailure loc reason) -> throwIO . HUnitFailure loc $ case reason of+ Reason err -> Reason $ addMessage err+ ExpectedButGot err expected got -> ExpectedButGot (Just $ maybe message addMessage err) expected got+ where+ addMessage :: String -> String+ addMessage err+ | null err = message+ | otherwise = message ++ "\n" ++ err++ handleWai :: Exception e => (e -> IO a) -> WaiSession st a -> WaiSession st a+ handleWai k (WaiSession (ReaderT f)) = WaiSession $ ReaderT $ \st ->+ ReaderT $ \app -> do+ case flip runReaderT app $ f st of+ StateT runSt -> StateT $ \s ->+ handle (fmap (, s) . k) $ runSt s+ -- | A lifted version of `Core.pendingWith`. pendingWith :: String -> WaiSession st () pendingWith = liftIO . Core.pendingWith@@ -141,7 +185,7 @@ -- | Perform a request to the application under test, with specified HTTP -- method, request path, headers and body. request :: Method -> ByteString -> [Header] -> LB.ByteString -> WaiSession st SResponse-request method path headers body = getApp >>= liftIO . runSession (Wai.srequest $ SRequest req body)+request method path headers = WaiSession . lift . Wai.srequest . SRequest req where req = setPath defaultRequest {requestMethod = method, requestHeaders = headers} path
src/Test/Hspec/Wai/Internal.hs view
@@ -14,9 +14,6 @@ , formatHeader ) where -import Prelude ()-import Prelude.Compat- import Control.Monad.IO.Class import Control.Monad.Trans.Class import Control.Monad.Trans.Reader@@ -25,7 +22,7 @@ import Test.Hspec.Core.Spec import Test.Hspec.Wai.Util (formatHeader) -#if MIN_VERSION_base(4,9,0)+#if MIN_VERSION_base(4,9,0) && !MIN_VERSION_base(4,13,0) import Control.Monad.Fail #endif
src/Test/Hspec/Wai/Matcher.hs view
@@ -1,3 +1,4 @@+{-# LANGUAGE PackageImports #-} {-# LANGUAGE ViewPatterns #-} module Test.Hspec.Wai.Matcher ( ResponseMatcher(..)@@ -11,7 +12,7 @@ ) where import Prelude ()-import Prelude.Compat+import "base-compat" Prelude.Compat import Control.Monad import Data.Maybe
src/Test/Hspec/Wai/Util.hs view
@@ -12,8 +12,8 @@ import qualified Data.ByteString as B import qualified Data.ByteString.Char8 as B8 import qualified Data.ByteString.Lazy as LB-import Data.ByteString.Lazy.Builder (Builder)-import qualified Data.ByteString.Lazy.Builder as Builder+import Data.ByteString.Builder (Builder)+import qualified Data.ByteString.Builder as Builder import qualified Data.Text as T import qualified Data.Text.Encoding as T import qualified Data.CaseInsensitive as CI
test/Test/Hspec/WaiSpec.hs view
@@ -23,7 +23,7 @@ requestMethod req `shouldBe` method rawPathInfo req `shouldBe` path requestHeaders req `shouldBe` headers- rawBody <- requestBody req+ rawBody <- getRequestBodyChunk req rawBody `shouldBe` body respond $ responseLBS status200 [] ""