summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorClint Adams <clint@softwarefreedom.org>2013-10-24 15:34:15 -0400
committerClint Adams <clint@softwarefreedom.org>2013-10-24 17:39:13 -0400
commit515338784b8fc2fb5435ee4e061c092ff754d6cf (patch)
treeceb2c2660cacaa3b90a80836a9f1e0dd8941ffa2 /tests
parent1725e252b7bd6bec9faecb0249961343bb27afb0 (diff)
Use newer persistent and newer Yesod
Diffstat (limited to 'tests')
-rw-r--r--tests/HomeTest.hs46
-rw-r--r--tests/main.hs16
2 files changed, 38 insertions, 24 deletions
diff --git a/tests/HomeTest.hs b/tests/HomeTest.hs
index 17c9e6d..fbe52ac 100644
--- a/tests/HomeTest.hs
+++ b/tests/HomeTest.hs
@@ -1,24 +1,38 @@
+{-# LANGUAGE OverloadedStrings #-}
module HomeTest
( homeSpecs
) where
-import Import
-import Yesod.Test
+import TestImport
+import qualified Data.List as L
-homeSpecs :: Specs
+homeSpecs :: Spec
homeSpecs =
- describe "These are some example tests" $
- it "loads the index and checks it looks right" $ do
- get_ "/"
- statusIs 200
- htmlAllContain "h1" "Hello"
+ ydescribe "These are some example tests" $ do
- post "/" $ do
- addNonce
- fileByLabel "Choose a file" "tests/main.hs" "text/plain" -- talk about self-reference
- byLabel "What's on the file?" "Some Content"
+ yit "loads the index and checks it looks right" $ do
+ get HomeR
+ statusIs 200
+ htmlAllContain "h1" "Hello"
- statusIs 200
- htmlCount ".message" 1
- htmlAllContain ".message" "Some Content"
- htmlAllContain ".message" "text/plain"
+ request $ do
+ setMethod "POST"
+ setUrl HomeR
+ addNonce
+ fileByLabel "Choose a file" "tests/main.hs" "text/plain" -- talk about self-reference
+ byLabel "What's on the file?" "Some Content"
+
+ statusIs 200
+ printBody
+ htmlCount ".message" 1
+ htmlAllContain ".message" "Some Content"
+ htmlAllContain ".message" "text/plain"
+
+ -- This is a simple example of using a database access in a test. The
+ -- test will succeed for a fresh scaffolded site with an empty database,
+ -- but will fail on an existing database with a non-empty user table.
+ yit "leaves the user table empty" $ do
+ get HomeR
+ statusIs 200
+ users <- runDB $ selectList ([] :: [Filter User]) []
+ assertEqual "user table empty" 0 $ L.length users
diff --git a/tests/main.hs b/tests/main.hs
index d475fe8..672220d 100644
--- a/tests/main.hs
+++ b/tests/main.hs
@@ -5,18 +5,18 @@
module Main where
import Import
-import Settings
-import Yesod.Logger (defaultDevelopmentLogger)
import Yesod.Default.Config
import Yesod.Test
import Application (makeFoundation)
import HomeTest
-main :: IO a
+main :: IO ()
main = do
- conf <- loadConfig $ (configSettings Testing) { csParseExtra = parseExtra }
- logger <- defaultDevelopmentLogger
- foundation <- makeFoundation conf logger
- app <- toWaiAppPlain foundation
- runTests app (connPool foundation) homeSpecs
+ conf <- Yesod.Default.Config.loadConfig $ (configSettings Testing)
+ { csParseExtra = parseExtra
+ }
+ foundation <- makeFoundation conf
+ hspec $ do
+ yesodSpec foundation $ do
+ homeSpecs