Ensure db fixtures loaded in feature specs
This commit is contained in:
+1
-1
@@ -52,7 +52,7 @@ Test-Suite spec
|
||||
Hs-Source-Dirs: src , test
|
||||
Ghc-Options: -Wall
|
||||
Main-Is: Spec.hs
|
||||
Other-Modules: Dbapi
|
||||
Other-Modules: Dbapi, SpecHelper
|
||||
Build-Depends: base, hspec2
|
||||
, hspec-wai
|
||||
, HDBC, HDBC-postgresql
|
||||
|
||||
@@ -5,16 +5,15 @@ import Test.Hspec
|
||||
import Test.Hspec.Wai
|
||||
import Test.Hspec.Wai.JSON
|
||||
|
||||
import Dbapi (AppConfig(..), app)
|
||||
import SpecHelper
|
||||
|
||||
import Dbapi (app)
|
||||
|
||||
main :: IO ()
|
||||
main = hspec spec
|
||||
|
||||
cfg :: AppConfig
|
||||
cfg = AppConfig "postgres://postgres:@localhost:5432/dbapi_test" 9000
|
||||
|
||||
spec :: Spec
|
||||
spec = with (return $ app cfg) $ do
|
||||
spec = with (prepareAppDb "schema" $ app cfg) $ do
|
||||
describe "GET /" $ do
|
||||
it "responds with 200" $ do
|
||||
get "/" `shouldRespondWith` 200
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
module SpecHelper where
|
||||
|
||||
import Network.Wai
|
||||
|
||||
import Database.HDBC
|
||||
import Database.HDBC.PostgreSQL
|
||||
|
||||
import Dbapi (AppConfig(..))
|
||||
|
||||
cfg :: AppConfig
|
||||
cfg = AppConfig "postgres://postgres:@localhost:5432/dbapi_test" 9000
|
||||
|
||||
loadFixture :: String -> IO Connection
|
||||
loadFixture name = do
|
||||
conn <- connectPostgreSQL $ configDbUri cfg
|
||||
sql <- readFile $ "test/fixtures/" ++ name ++ ".sql"
|
||||
runRaw conn "drop schema if exists \"1\" cascade"
|
||||
runRaw conn sql
|
||||
commit conn
|
||||
return conn
|
||||
|
||||
prepareAppDb :: String -> Application -> IO Application
|
||||
prepareAppDb = (. return) . (>>) . loadFixture
|
||||
@@ -5,18 +5,11 @@ module Unit.PgQuerySpec where
|
||||
import Test.Hspec
|
||||
|
||||
import Database.HDBC
|
||||
import Database.HDBC.PostgreSQL
|
||||
|
||||
import PgQuery (insert)
|
||||
import Types (SqlRow(..))
|
||||
|
||||
loadFixture :: String -> IO Connection
|
||||
loadFixture name = do
|
||||
conn <- connectPostgreSQL "postgres://postgres:@localhost:5432/dbapi_test"
|
||||
sql <- readFile $ "test/fixtures/" ++ name ++ ".sql"
|
||||
runRaw conn "drop schema if exists \"1\" cascade"
|
||||
runRaw conn sql
|
||||
return conn
|
||||
import SpecHelper
|
||||
|
||||
main :: IO ()
|
||||
main = hspec spec
|
||||
|
||||
Reference in New Issue
Block a user