From df5018a94ca9f637d8b0c66aa71903e6ed84cd4a Mon Sep 17 00:00:00 2001 From: Michael Snoyman Date: Fri, 3 Aug 2012 15:40:36 +0300 Subject: [PATCH] hspec 1.3 --- scripts | 2 +- yesod-core/test.hs | 2 +- yesod-core/test/YesodCoreTest.hs | 29 +++++++------- yesod-core/test/YesodCoreTest/Cache.hs | 5 +-- yesod-core/test/YesodCoreTest/CleanPath.hs | 17 ++++---- .../test/YesodCoreTest/ErrorHandling.hs | 13 +++--- yesod-core/test/YesodCoreTest/Exceptions.hs | 7 ++-- .../test/YesodCoreTest/InternalRequest.hs | 40 +++++++++---------- yesod-core/test/YesodCoreTest/JsLoader.hs | 7 ++-- yesod-core/test/YesodCoreTest/Links.hs | 5 +-- yesod-core/test/YesodCoreTest/Media.hs | 7 ++-- .../test/YesodCoreTest/NoOverloadedStrings.hs | 5 +-- yesod-core/test/YesodCoreTest/Redirect.hs | 11 +++-- yesod-core/test/YesodCoreTest/WaiSubsite.hs | 5 +-- yesod-core/test/YesodCoreTest/Widget.hs | 13 +++--- yesod-core/yesod-core.cabal | 2 +- yesod-routes/yesod-routes.cabal | 2 +- yesod-static/test/YesodStaticTest.hs | 8 ++-- yesod-static/test/tests.hs | 2 +- yesod-static/yesod-static.cabal | 2 +- yesod-test/Yesod/Test.hs | 13 ------ 21 files changed, 83 insertions(+), 114 deletions(-) diff --git a/scripts b/scripts index eba05a0b..bf06d8e7 160000 --- a/scripts +++ b/scripts @@ -1 +1 @@ -Subproject commit eba05a0b5fe121883969f8fa9b7f7669592430a4 +Subproject commit bf06d8e764f3d2931c0a676dc5c6fc14491b012a diff --git a/yesod-core/test.hs b/yesod-core/test.hs index 49141594..c85d1890 100644 --- a/yesod-core/test.hs +++ b/yesod-core/test.hs @@ -2,4 +2,4 @@ import Test.Hspec import qualified YesodCoreTest main :: IO () -main = hspecX $ YesodCoreTest.specs +main = hspec YesodCoreTest.specs diff --git a/yesod-core/test/YesodCoreTest.hs b/yesod-core/test/YesodCoreTest.hs index b89d5ed2..b6384331 100644 --- a/yesod-core/test/YesodCoreTest.hs +++ b/yesod-core/test/YesodCoreTest.hs @@ -15,18 +15,17 @@ import qualified YesodCoreTest.JsLoader as JsLoader import Test.Hspec -specs :: [Spec] -specs = - [ cleanPathTest - , exceptionsTest - , widgetTest - , mediaTest - , linksTest - , noOverloadedTest - , internalRequestTest - , errorHandlingTest - , cacheTest - , WaiSubsite.specs - , Redirect.specs - , JsLoader.specs - ] +specs :: Spec +specs = do + cleanPathTest + exceptionsTest + widgetTest + mediaTest + linksTest + noOverloadedTest + internalRequestTest + errorHandlingTest + cacheTest + WaiSubsite.specs + Redirect.specs + JsLoader.specs diff --git a/yesod-core/test/YesodCoreTest/Cache.hs b/yesod-core/test/YesodCoreTest/Cache.hs index 9e96947b..3514f8f3 100644 --- a/yesod-core/test/YesodCoreTest/Cache.hs +++ b/yesod-core/test/YesodCoreTest/Cache.hs @@ -37,9 +37,8 @@ getRootR = do cacheTest :: Spec cacheTest = - describe "Test.Cache" - [ it "works" works - ] + describe "Test.Cache" $ do + it "works" works runner :: Session () -> IO () runner f = toWaiApp C >>= runSession f diff --git a/yesod-core/test/YesodCoreTest/CleanPath.hs b/yesod-core/test/YesodCoreTest/CleanPath.hs index 10d95497..99637af4 100644 --- a/yesod-core/test/YesodCoreTest/CleanPath.hs +++ b/yesod-core/test/YesodCoreTest/CleanPath.hs @@ -64,15 +64,14 @@ getPlainR = return $ RepPlain "plain" cleanPathTest :: Spec cleanPathTest = - describe "Test.CleanPath" - [ it "remove trailing slash" removeTrailingSlash - , it "noTrailingSlash" noTrailingSlash - , it "add trailing slash" addTrailingSlash - , it "has trailing slash" hasTrailingSlash - , it "/foo/something" fooSomething - , it "subsite dispatch" subsiteDispatch - , it "redirect with query string" redQueryString - ] + describe "Test.CleanPath" $ do + it "remove trailing slash" removeTrailingSlash + it "noTrailingSlash" noTrailingSlash + it "add trailing slash" addTrailingSlash + it "has trailing slash" hasTrailingSlash + it "/foo/something" fooSomething + it "subsite dispatch" subsiteDispatch + it "redirect with query string" redQueryString runner :: Session () -> IO () runner f = toWaiApp Y >>= runSession f diff --git a/yesod-core/test/YesodCoreTest/ErrorHandling.hs b/yesod-core/test/YesodCoreTest/ErrorHandling.hs index 92171c41..fdd1021f 100644 --- a/yesod-core/test/YesodCoreTest/ErrorHandling.hs +++ b/yesod-core/test/YesodCoreTest/ErrorHandling.hs @@ -67,13 +67,12 @@ getErrorInBodyNoEvalR :: Handler (DontFullyEvaluate RepHtml) getErrorInBodyNoEvalR = fmap DontFullyEvaluate getErrorInBodyR errorHandlingTest :: Spec -errorHandlingTest = describe "Test.ErrorHandling" - [ it "says not found" caseNotFound - , it "says 'There was an error' before runRequestBody" caseBefore - , it "says 'There was an error' after runRequestBody" caseAfter - , it "error in body == 500" caseErrorInBody - , it "error in body, no eval == 200" caseErrorInBodyNoEval - ] +errorHandlingTest = describe "Test.ErrorHandling" $ do + it "says not found" caseNotFound + it "says 'There was an error' before runRequestBody" caseBefore + it "says 'There was an error' after runRequestBody" caseAfter + it "error in body == 500" caseErrorInBody + it "error in body, no eval == 200" caseErrorInBodyNoEval runner :: Session () -> IO () runner f = toWaiApp App >>= runSession f diff --git a/yesod-core/test/YesodCoreTest/Exceptions.hs b/yesod-core/test/YesodCoreTest/Exceptions.hs index 81c10d07..3ea0d720 100644 --- a/yesod-core/test/YesodCoreTest/Exceptions.hs +++ b/yesod-core/test/YesodCoreTest/Exceptions.hs @@ -31,10 +31,9 @@ getRedirR = do redirectWith status301 RootR exceptionsTest :: Spec -exceptionsTest = describe "Test.Exceptions" - [ it "500" case500 - , it "redirect keeps headers" caseRedirect - ] +exceptionsTest = describe "Test.Exceptions" $ do + it "500" case500 + it "redirect keeps headers" caseRedirect runner :: Session () -> IO () runner f = toWaiApp Y >>= runSession f diff --git a/yesod-core/test/YesodCoreTest/InternalRequest.hs b/yesod-core/test/YesodCoreTest/InternalRequest.hs index b2a1e179..6fcd924d 100644 --- a/yesod-core/test/YesodCoreTest/InternalRequest.hs +++ b/yesod-core/test/YesodCoreTest/InternalRequest.hs @@ -11,10 +11,9 @@ import Yesod.Request (Request (..)) import Test.Hspec randomStringSpecs :: Spec -randomStringSpecs = describe "Yesod.Internal.Request.randomString" - [ it "looks reasonably random" looksRandom - , it "does not repeat itself" $ noRepeat 10 100 - ] +randomStringSpecs = describe "Yesod.Internal.Request.randomString" $ do + it "looks reasonably random" looksRandom + it "does not repeat itself" $ noRepeat 10 100 -- NOTE: this testcase may break on other systems/architectures if -- mkStdGen is not identical everywhere (is it?). @@ -31,12 +30,11 @@ g = error "test/YesodCoreTest/InternalRequest.g" tokenSpecs :: Spec -tokenSpecs = describe "Yesod.Internal.Request.parseWaiRequest (reqToken)" - [ it "is Nothing if sessions are disabled" noDisabledToken - , it "ignores pre-existing token if sessions are disabled" ignoreDisabledToken - , it "uses preexisting token in session" useOldToken - , it "generates a new token for sessions without token" generateToken - ] +tokenSpecs = describe "Yesod.Internal.Request.parseWaiRequest (reqToken)" $ do + it "is Nothing if sessions are disabled" noDisabledToken + it "ignores pre-existing token if sessions are disabled" ignoreDisabledToken + it "uses preexisting token in session" useOldToken + it "generates a new token for sessions without token" generateToken noDisabledToken :: Bool noDisabledToken = reqToken r == Nothing where @@ -56,13 +54,12 @@ generateToken = reqToken r /= Nothing where langSpecs :: Spec -langSpecs = describe "Yesod.Internal.Request.parseWaiRequest (reqLangs)" - [ it "respects Accept-Language" respectAcceptLangs - , it "respects sessions" respectSessionLang - , it "respects cookies" respectCookieLang - , it "respects queries" respectQueryLang - , it "prioritizes correctly" prioritizeLangs - ] +langSpecs = describe "Yesod.Internal.Request.parseWaiRequest (reqLangs)" $ do + it "respects Accept-Language" respectAcceptLangs + it "respects sessions" respectSessionLang + it "respects cookies" respectCookieLang + it "respects queries" respectQueryLang + it "prioritizes correctly" prioritizeLangs respectAcceptLangs :: Bool respectAcceptLangs = reqLangs r == ["en-US", "es", "en"] where @@ -94,8 +91,7 @@ prioritizeLangs = reqLangs r == ["en-QUERY", "en-COOKIE", "en-SESSION", "en", "e internalRequestTest :: Spec -internalRequestTest = describe "Test.InternalRequestTest" - [ randomStringSpecs - , tokenSpecs - , langSpecs - ] +internalRequestTest = describe "Test.InternalRequestTest" $ do + randomStringSpecs + tokenSpecs + langSpecs diff --git a/yesod-core/test/YesodCoreTest/JsLoader.hs b/yesod-core/test/YesodCoreTest/JsLoader.hs index c23b2229..11b1a38d 100644 --- a/yesod-core/test/YesodCoreTest/JsLoader.hs +++ b/yesod-core/test/YesodCoreTest/JsLoader.hs @@ -23,19 +23,18 @@ getHeadR :: Handler RepHtml getHeadR = defaultLayout $ addScriptRemote "load.js" specs :: Spec -specs = describe "Test.JsLoader" [ +specs = describe "Test.JsLoader" $ do it "link from head" $ runner H $ do res <- request defaultRequest assertBody "\n" res - , it "link from head async" $ runner HA $ do + it "link from head async" $ runner HA $ do res <- request defaultRequest assertBody "\n" res - , it "link from bottom" $ runner B $ do + it "link from bottom" $ runner B $ do res <- request defaultRequest assertBody "\n" res - ] runner :: (YesodDispatch master master, Yesod master) => master -> Session () -> IO () runner app f = toWaiApp app >>= runSession f diff --git a/yesod-core/test/YesodCoreTest/Links.hs b/yesod-core/test/YesodCoreTest/Links.hs index d8c6090b..611e17d5 100644 --- a/yesod-core/test/YesodCoreTest/Links.hs +++ b/yesod-core/test/YesodCoreTest/Links.hs @@ -21,9 +21,8 @@ getRootR :: Handler RepHtml getRootR = defaultLayout $ toWidget [hamlet||] linksTest :: Spec -linksTest = describe "Test.Links" - [ it "linkToHome" case_linkToHome - ] +linksTest = describe "Test.Links" $ do + it "linkToHome" case_linkToHome runner :: Session () -> IO () runner f = toWaiApp Y >>= runSession f diff --git a/yesod-core/test/YesodCoreTest/Media.hs b/yesod-core/test/YesodCoreTest/Media.hs index 812b39de..cfd6aff8 100644 --- a/yesod-core/test/YesodCoreTest/Media.hs +++ b/yesod-core/test/YesodCoreTest/Media.hs @@ -50,7 +50,6 @@ caseMediaLink = runner $ do flip assertBody res "\n" mediaTest :: Spec -mediaTest = describe "Test.Media" - [ it "media" caseMedia - , it "media link" caseMediaLink - ] +mediaTest = describe "Test.Media" $ do + it "media" caseMedia + it "media link" caseMediaLink diff --git a/yesod-core/test/YesodCoreTest/NoOverloadedStrings.hs b/yesod-core/test/YesodCoreTest/NoOverloadedStrings.hs index 63e20c80..a3d8cd20 100644 --- a/yesod-core/test/YesodCoreTest/NoOverloadedStrings.hs +++ b/yesod-core/test/YesodCoreTest/NoOverloadedStrings.hs @@ -45,6 +45,5 @@ case_sanity = runner $ do assertBody mempty res noOverloadedTest :: Spec -noOverloadedTest = describe "Test.NoOverloadedStrings" - [ it "sanity" case_sanity - ] +noOverloadedTest = describe "Test.NoOverloadedStrings" $ do + it "sanity" case_sanity diff --git a/yesod-core/test/YesodCoreTest/Redirect.hs b/yesod-core/test/YesodCoreTest/Redirect.hs index 178dbe2f..63d28759 100644 --- a/yesod-core/test/YesodCoreTest/Redirect.hs +++ b/yesod-core/test/YesodCoreTest/Redirect.hs @@ -27,33 +27,32 @@ getR307 = redirectWith H.status307 RootR getRRegular = redirect RootR specs :: Spec -specs = describe "Redirect" [ +specs = describe "Redirect" $ do it "301 redirect" $ app $ do res <- request defaultRequest { pathInfo = ["r301"] } assertStatus 301 res assertBodyContains "" res - , it "303 redirect" $ app $ do + it "303 redirect" $ app $ do res <- request defaultRequest { pathInfo = ["r303"] } assertStatus 303 res assertBodyContains "" res - , it "307 redirect" $ app $ do + it "307 redirect" $ app $ do res <- request defaultRequest { pathInfo = ["r307"] } assertStatus 307 res assertBodyContains "" res - , it "303 redirect for regular, HTTP 1.1" $ app $ do + it "303 redirect for regular, HTTP 1.1" $ app $ do res <- request defaultRequest { pathInfo = ["rregular"] } assertStatus 303 res assertBodyContains "" res - , it "302 redirect for regular, HTTP 1.0" $ app $ do + it "302 redirect for regular, HTTP 1.0" $ app $ do res <- request defaultRequest { pathInfo = ["rregular"] , httpVersion = H.http10 } assertStatus 302 res assertBodyContains "" res - ] diff --git a/yesod-core/test/YesodCoreTest/WaiSubsite.hs b/yesod-core/test/YesodCoreTest/WaiSubsite.hs index 929f2d2b..a30469e5 100644 --- a/yesod-core/test/YesodCoreTest/WaiSubsite.hs +++ b/yesod-core/test/YesodCoreTest/WaiSubsite.hs @@ -26,14 +26,13 @@ getRootR :: Handler () getRootR = return () specs :: Spec -specs = describe "WaiSubsite" [ +specs = describe "WaiSubsite" $ do it "root" $ app $ do res <- request defaultRequest { pathInfo = [] } assertStatus 200 res assertBodyContains "" res - , it "subsite" $ app $ do + it "subsite" $ app $ do res <- request defaultRequest { pathInfo = ["sub", "foo"] } assertStatus 200 res assertBodyContains "WAI" res - ] diff --git a/yesod-core/test/YesodCoreTest/Widget.hs b/yesod-core/test/YesodCoreTest/Widget.hs index 7d079596..842a43f0 100644 --- a/yesod-core/test/YesodCoreTest/Widget.hs +++ b/yesod-core/test/YesodCoreTest/Widget.hs @@ -87,13 +87,12 @@ getJSHeadR :: Handler RepHtml getJSHeadR = defaultLayout $ toWidgetHead [julius|alert("hello");|] widgetTest :: Spec -widgetTest = describe "Test.Widget" - [ it "addJuliusBody" case_addJuliusBody - , it "whamlet" case_whamlet - , it "two letter lang codes" case_two_letter_lang - , it "automatically applies toWidget" case_auto - , it "toWidgetHead puts JS in head" case_jshead - ] +widgetTest = describe "Test.Widget" $ do + it "addJuliusBody" case_addJuliusBody + it "whamlet" case_whamlet + it "two letter lang codes" case_two_letter_lang + it "automatically applies toWidget" case_auto + it "toWidgetHead puts JS in head" case_jshead runner :: Session () -> IO () runner f = toWaiApp Y >>= runSession f diff --git a/yesod-core/yesod-core.cabal b/yesod-core/yesod-core.cabal index ffd641a0..bd02ce69 100644 --- a/yesod-core/yesod-core.cabal +++ b/yesod-core/yesod-core.cabal @@ -108,7 +108,7 @@ test-suite tests cpp-options: -DTEST build-depends: base - ,hspec >= 1.2 && < 1.3 + ,hspec >= 1.3 && < 1.4 ,wai-test ,wai ,yesod-core diff --git a/yesod-routes/yesod-routes.cabal b/yesod-routes/yesod-routes.cabal index 3fe03050..6fcf092a 100644 --- a/yesod-routes/yesod-routes.cabal +++ b/yesod-routes/yesod-routes.cabal @@ -42,7 +42,7 @@ test-suite runtests , yesod-routes , text >= 0.5 && < 0.12 , HUnit >= 1.2 && < 1.3 - , hspec >= 1.2 && < 1.3 + , hspec >= 1.3 && < 1.4 , containers , template-haskell , path-pieces diff --git a/yesod-static/test/YesodStaticTest.hs b/yesod-static/test/YesodStaticTest.hs index 30147081..53e33bf6 100644 --- a/yesod-static/test/YesodStaticTest.hs +++ b/yesod-static/test/YesodStaticTest.hs @@ -6,11 +6,9 @@ import Test.Hspec.HUnit ( ) import Yesod.Static (getFileListPieces) -specs :: Specs -specs = [ - describe "get file list" [ +specs :: Spec +specs = do + describe "get file list" $ do it "pieces" $ do x <- getFileListPieces "test/fs" x @?= [["foo"], ["bar", "baz"]] - ] - ] diff --git a/yesod-static/test/tests.hs b/yesod-static/test/tests.hs index 672c61e0..00553511 100644 --- a/yesod-static/test/tests.hs +++ b/yesod-static/test/tests.hs @@ -4,4 +4,4 @@ import Test.Hspec import YesodStaticTest (specs) main :: IO () -main = hspecX specs +main = hspec specs diff --git a/yesod-static/yesod-static.cabal b/yesod-static/yesod-static.cabal index 84a9fe38..a248e32d 100644 --- a/yesod-static/yesod-static.cabal +++ b/yesod-static/yesod-static.cabal @@ -45,7 +45,7 @@ test-suite tests type: exitcode-stdio-1.0 cpp-options: -DTEST_EXPORT build-depends: base - , hspec >= 1.2 && < 1.3 + , hspec >= 1.3 && < 1.4 , HUnit -- copy from above , containers >= 0.2 diff --git a/yesod-test/Yesod/Test.hs b/yesod-test/Yesod/Test.hs index 97e4cc3d..8a8f7f39 100644 --- a/yesod-test/Yesod/Test.hs +++ b/yesod-test/Yesod/Test.hs @@ -316,19 +316,6 @@ nameFromLabel label = withResponse $ \ res -> do (<>) :: T.Text -> T.Text -> T.Text (<>) = T.append --- | Escape HTML entities in a string, so you can write the text you want in --- label lookups without worrying about the fact that yesod escapes some characters. -escapeHtmlEntities :: T.Text -> T.Text -escapeHtmlEntities = - T.concatMap go - where - go '<' = "<" - go '>' = ">" - go '&' = "&" - go '"' = """ - go '\'' = "'" - go x = T.singleton x - byLabel :: T.Text -> T.Text -> RequestBuilder () byLabel label value = do name <- nameFromLabel label