From f035b1fc22c31fa1b081ef650b0c44363126a380 Mon Sep 17 00:00:00 2001 From: Michael Xavier Date: Thu, 22 Mar 2012 19:20:15 -0700 Subject: [PATCH] Add bodyEquals assertion --- yesod-test/Yesod/Test.hs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) 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 ()