diff --git a/yesod-test/Yesod/Test.hs b/yesod-test/Yesod/Test.hs index 3548ddf8..42a020c3 100644 --- a/yesod-test/Yesod/Test.hs +++ b/yesod-test/Yesod/Test.hs @@ -50,7 +50,7 @@ module Yesod.Test ( runDB, -- * Assertions - assertEqual, statusIs, bodyContains, htmlAllContain, htmlCount, + assertEqual, statusIs, bodyEquals, bodyContains, htmlAllContain, htmlCount, -- * Utils for debugging tests printBody, printMatches, @@ -179,6 +179,13 @@ statusIs number = withResponse $ \ SResponse { simpleStatus = s } -> , " but received status was ", show $ H.statusCode s ] +-- | Assert the last response is exactly equal to the given text. This is +-- useful for testing API responses. +bodyEquals :: HoldsResponse a => String -> ST.StateT a IO () +bodyEquals text = withResponse $ \ res -> + liftIO $ HUnit.assertBool ("Expected body to equal " ++ text) $ + (simpleBody res) == BSL8.pack text + -- | Assert the last response has the given text. The check is performed using the response -- body in full text form. bodyContains :: HoldsResponse a => String -> ST.StateT a IO ()