@@ -13,6 +13,7 @@ module Network.Wai.Test
1313 , assertStatus
1414 , assertContentType
1515 , assertBody
16+ , assertBodyContains
1617 , assertHeader
1718 , assertNoHeader
1819 ) where
@@ -32,6 +33,7 @@ import qualified Data.ByteString.Lazy as L
3233import qualified Data.ByteString.Lazy.Char8 as L8
3334import qualified Network.HTTP.Types as H
3435import Data.CaseInsensitive (CI)
36+import qualified Data.ByteString as S
3537
3638type Session = ReaderT Application (StateT ClientState IO)
3739
@@ -130,6 +132,16 @@ assertBody lbs SResponse{simpleBody = lbs'} = assertBool (concat
130132 , show $ L8.unpack lbs'
131133 ]) $ lbs == lbs'
132134
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
139+ , ", but received "
140+ , show $ L8.unpack lbs'
141+ ]) $ strict lbs `S.isInfixOf` strict lbs'
142+ where
143+ strict = S.concat . L.toChunks
144+
133145assertHeader :: CI ByteString -> ByteString -> SResponse -> Session ()
134146assertHeader header value SResponse{simpleHeaders = h} =
135147 case lookup header h of