Merge pull request #509 from ShaneKilkelly/test-additions

Test additions
This commit is contained in:
Michael Snoyman 2013-03-03 22:38:41 -08:00
commit 98fb0370bc

View File

@ -52,7 +52,7 @@ module Yesod.Test (
-- * Assertions
assertEqual, assertHeader, assertNoHeader, statusIs, bodyEquals, bodyContains,
htmlAllContain, htmlCount,
htmlAllContain, htmlAnyContain, htmlCount,
-- * Utils for debugging tests
printBody, printMatches,
@ -253,6 +253,16 @@ htmlAllContain query search = do
_ -> liftIO $ HUnit.assertBool ("Not all "++T.unpack query++" contain "++search) $
DL.all (DL.isInfixOf search) (map (TL.unpack . decodeUtf8) matches)
-- | Queries the html using a css selector, and passes if any matched
-- element contains the given string.
htmlAnyContain :: HoldsResponse a => Query -> String -> ST.StateT a IO ()
htmlAnyContain query search = do
matches <- htmlQuery query
case matches of
[] -> failure $ "Nothing matched css query: " <> query
_ -> liftIO $ HUnit.assertBool ("None of "++T.unpack query++" contain "++search) $
DL.any (DL.isInfixOf search) (map (TL.unpack . decodeUtf8) matches)
-- | Performs a css query on the last response and asserts the matched elements
-- are as many as expected.
htmlCount :: HoldsResponse a => Query -> Int -> ST.StateT a IO ()