Feature tests pass, unit test does not
This commit is contained in:
@@ -8,7 +8,6 @@ import Test.Hspec.Wai.JSON
|
||||
import SpecHelper
|
||||
|
||||
import Network.HTTP.Types
|
||||
import Dbapi (app)
|
||||
|
||||
spec :: Spec
|
||||
spec = around appWithFixture $ do
|
||||
@@ -74,7 +73,9 @@ spec = around appWithFixture $ do
|
||||
it "returns whole range with status 200" $ do
|
||||
get "/auto_incrementing_pk" `shouldRespondWith` 206
|
||||
|
||||
-- describe "Posting new record" $ do
|
||||
-- context "into a table with auto-incrementing pk" $ do
|
||||
-- it "does not require pk in the payload" $ do
|
||||
-- undefined
|
||||
describe "Posting new record" $ do
|
||||
context "into a table with auto-incrementing pk" $ do
|
||||
it "does not require pk in the payload" $ do
|
||||
post "/auto_incrementing_pk" [json|
|
||||
{ "non_nullable_string":"not null"} |]
|
||||
`shouldRespondWith` 200
|
||||
|
||||
+6
-2
@@ -1,10 +1,14 @@
|
||||
module Main where
|
||||
|
||||
import Database.HDBC (runRaw, disconnect)
|
||||
import Test.Hspec
|
||||
import Spec
|
||||
import SpecHelper (openConnection, loadFixture)
|
||||
|
||||
main :: IO ()
|
||||
main = do
|
||||
putStrLn "before spec"
|
||||
c <-openConnection
|
||||
runRaw c "drop schema if exists \"1\" cascade"
|
||||
loadFixture "schema" c
|
||||
disconnect c
|
||||
hspec spec
|
||||
putStrLn "after spec"
|
||||
|
||||
+6
-12
@@ -10,8 +10,6 @@ import Control.Exception.Base (bracket)
|
||||
|
||||
import Dbapi (app, AppConfig(..))
|
||||
|
||||
import Debug.Trace
|
||||
|
||||
cfg :: AppConfig
|
||||
cfg = AppConfig "postgres://postgres:@localhost:5432/dbapi_test" 9000
|
||||
|
||||
@@ -23,21 +21,17 @@ withDatabaseConnection = bracket openConnection disconnect
|
||||
|
||||
loadFixture :: String -> Connection -> IO ()
|
||||
loadFixture name conn = do
|
||||
runRaw conn "begin;"
|
||||
sql <- readFile $ "test/fixtures/" ++ name ++ ".sql"
|
||||
runRaw conn sql
|
||||
|
||||
rollbackFixture :: Connection -> IO ()
|
||||
rollbackFixture = flip runRaw "rollback;"
|
||||
|
||||
dbWithSchema :: ActionWith Connection -> IO ()
|
||||
dbWithSchema action = withDatabaseConnection $ \c -> do
|
||||
trace "Load fixture" loadFixture "schema" c
|
||||
trace "act" action (c)
|
||||
trace "rollback" rollbackFixture c
|
||||
runRaw c "begin;"
|
||||
action c
|
||||
rollback c
|
||||
|
||||
appWithFixture :: ActionWith Application -> IO ()
|
||||
appWithFixture action = withDatabaseConnection $ \c -> do
|
||||
loadFixture "schema" c
|
||||
action (app cfg)
|
||||
rollbackFixture c
|
||||
runRaw c "begin;"
|
||||
action $ app c
|
||||
rollback c
|
||||
|
||||
@@ -6,7 +6,7 @@ import Test.Hspec
|
||||
|
||||
import Database.HDBC
|
||||
|
||||
import PgQuery (insert)
|
||||
import PgQuery (insert, getRows, RangedResult(..))
|
||||
import Types (SqlRow(..))
|
||||
|
||||
import SpecHelper
|
||||
@@ -20,7 +20,3 @@ spec = around dbWithSchema $ do
|
||||
]) conn
|
||||
r <- quickQuery conn "select count(1) from auto_incrementing_pk" []
|
||||
[[toSql (1 :: Int)]] `shouldBe` r
|
||||
|
||||
describe "insert again" $
|
||||
it "is true" $ \_ ->
|
||||
True `shouldBe` True
|
||||
|
||||
Reference in New Issue
Block a user