@@ -13,6 +13,7 @@ module Network.Wai.Test
13 , assertStatus
13 , assertStatus
14 , assertContentType
14 , assertContentType
15 , assertBody
15 , assertBody
16 , assertHeader
17 , assertHeader
17 , assertNoHeader
18 , assertNoHeader
@@ -32,6 +33,7 @@ import qualified Data.ByteString.Lazy as L
32import qualified Data.ByteString.Lazy.Char8 as L8
33import qualified Data.ByteString.Lazy.Char8 as L8
33import qualified Network.HTTP.Types as H
34import qualified Network.HTTP.Types as H
34import Data.CaseInsensitive (CI)
35import Data.CaseInsensitive (CI)
36+import qualified Data.ByteString as S
36type Session = ReaderT Application (StateT ClientState IO)
38type Session = ReaderT Application (StateT ClientState IO)
@@ -130,6 +132,16 @@ assertBody lbs SResponse{simpleBody = lbs'} = assertBool (concat
130 , show $ L8.unpack lbs'
132 , show $ L8.unpack lbs'
131 ]) $ lbs == lbs'
133 ]) $ lbs == lbs'
135+assertBodyContains :: L.ByteString -> SResponse -> Session ()
136+assertBodyContains lbs SResponse{simpleBody = lbs'} = assertBool (concat
137+ [ "Expected response body to contain "
138+ , show $ L8.unpack lbs
140+ , show $ L8.unpack lbs'
141+ ]) $ strict lbs `S.isInfixOf` strict lbs'
143+ strict = S.concat . L.toChunks
133assertHeader :: CI ByteString -> ByteString -> SResponse -> Session ()
145assertHeader :: CI ByteString -> ByteString -> SResponse -> Session ()
134assertHeader header value SResponse{simpleHeaders = h} =
146assertHeader header value SResponse{simpleHeaders = h} =
135 case lookup header h of
147 case lookup header h of