From 21e0ef11bac768fd491822316921e5e731049665 Mon Sep 17 00:00:00 2001 From: Amitaibu Date: Thu, 1 Sep 2016 14:09:10 +0300 Subject: [PATCH 1/4] Add bodyNotContains function --- yesod-test/Yesod/Test.hs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/yesod-test/Yesod/Test.hs b/yesod-test/Yesod/Test.hs index 984d8eb0..fc1c3770 100644 --- a/yesod-test/Yesod/Test.hs +++ b/yesod-test/Yesod/Test.hs @@ -395,6 +395,13 @@ bodyContains text = withResponse $ \ res -> liftIO $ HUnit.assertBool ("Expected body to contain " ++ text) $ (simpleBody res) `contains` text +-- | Assert the last response doesn't have the given text. The check is performed using the response +-- body in full text form. +bodyNotContains :: String -> YesodExample site () +bodyNotContains text = withResponse $ \ res -> + liftIO $ HUnit.assertBool ("Expected body not to contain " ++ text) $ + not . contains (simpleBody res) text + contains :: BSL8.ByteString -> String -> Bool contains a b = DL.isInfixOf b (TL.unpack $ decodeUtf8 a) From ac0229dff04cea1bbd7b69319ad0a05e933a67c8 Mon Sep 17 00:00:00 2001 From: Amitaibu Date: Thu, 1 Sep 2016 14:19:38 +0300 Subject: [PATCH 2/4] Bump cabal version and export function --- yesod-test/ChangeLog.md | 6 +++++- yesod-test/Yesod/Test.hs | 1 + yesod-test/yesod-test.cabal | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/yesod-test/ChangeLog.md b/yesod-test/ChangeLog.md index c80d2f6e..34ba62d5 100644 --- a/yesod-test/ChangeLog.md +++ b/yesod-test/ChangeLog.md @@ -1,3 +1,7 @@ +## 1.5.3 + +* Added bodyNotContains [#1271](https://github.com/yesodweb/yesod/pull/1271) + ## 1.5.2 * Added assertEq, deprecated assertEqual [#1259](https://github.com/yesodweb/yesod/pull/1259) @@ -5,7 +9,7 @@ ## 1.5.1.1 * Fix `addToken_` needing a trailing space and allows multiples spaces in css selector. - + ## 1.5.1.0 * Better error provenance for stuff invoking withResponse' [#1191](https://github.com/yesodweb/yesod/pull/1191) diff --git a/yesod-test/Yesod/Test.hs b/yesod-test/Yesod/Test.hs index fc1c3770..664359bf 100644 --- a/yesod-test/Yesod/Test.hs +++ b/yesod-test/Yesod/Test.hs @@ -93,6 +93,7 @@ module Yesod.Test , statusIs , bodyEquals , bodyContains + , bodyNotContains , htmlAllContain , htmlAnyContain , htmlNoneContain diff --git a/yesod-test/yesod-test.cabal b/yesod-test/yesod-test.cabal index 3365dfa3..09b684c8 100644 --- a/yesod-test/yesod-test.cabal +++ b/yesod-test/yesod-test.cabal @@ -1,5 +1,5 @@ name: yesod-test -version: 1.5.2 +version: 1.5.3 license: MIT license-file: LICENSE author: Nubis From 6ddfd07032e4504adba20f6be6b8cd79336ca1a3 Mon Sep 17 00:00:00 2001 From: Amitaibu Date: Thu, 1 Sep 2016 14:20:29 +0300 Subject: [PATCH 3/4] Add since tag --- yesod-test/Yesod/Test.hs | 1 + 1 file changed, 1 insertion(+) diff --git a/yesod-test/Yesod/Test.hs b/yesod-test/Yesod/Test.hs index 664359bf..6ef46285 100644 --- a/yesod-test/Yesod/Test.hs +++ b/yesod-test/Yesod/Test.hs @@ -398,6 +398,7 @@ bodyContains text = withResponse $ \ res -> -- | Assert the last response doesn't have the given text. The check is performed using the response -- body in full text form. +-- @since 1.5.3 bodyNotContains :: String -> YesodExample site () bodyNotContains text = withResponse $ \ res -> liftIO $ HUnit.assertBool ("Expected body not to contain " ++ text) $ From 827040f279562a6b93d69bb0d864af844b7f81b3 Mon Sep 17 00:00:00 2001 From: Amitaibu Date: Thu, 1 Sep 2016 15:22:25 +0300 Subject: [PATCH 4/4] Fix error --- yesod-test/Yesod/Test.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yesod-test/Yesod/Test.hs b/yesod-test/Yesod/Test.hs index 6ef46285..b3cf4a29 100644 --- a/yesod-test/Yesod/Test.hs +++ b/yesod-test/Yesod/Test.hs @@ -402,7 +402,7 @@ bodyContains text = withResponse $ \ res -> bodyNotContains :: String -> YesodExample site () bodyNotContains text = withResponse $ \ res -> liftIO $ HUnit.assertBool ("Expected body not to contain " ++ text) $ - not . contains (simpleBody res) text + not $ contains (simpleBody res) text contains :: BSL8.ByteString -> String -> Bool contains a b = DL.isInfixOf b (TL.unpack $ decodeUtf8 a)