on master help sign in
assertBodyContains
commit42aae8cdef4ae4df90c93a826f7bc59f18c7a9e7 authorMichael Snoyman <michael@snoyman.com> dateThu 6 Oct 2011, 16:13 (15 years ago) parent4ed7c5e
2 files changed+13−1
wai-test/Network/Wai/Test.hs+12 wai-test/wai-test.cabal+1−1
wai-test/Network/Wai/Test.hs+12
@@ -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
wai-test/wai-test.cabal+1−1
@@ -1,5 +1,5 @@
11name: wai-test
2−version: 0.1.1
2+version: 0.1.2
33license: BSD3
44license-file: LICENSE
55author: Michael Snoyman <michael@snoyman.com>