Safe Haskell | None |
---|---|
Language | Haskell2010 |
Helpers for creating database tests with hspec and pg-transact
hspec-pg-transact
utilizes tmp-postgres
to automatically and connect to a temporary instance of postgres
on a random port.
describeDB
migrate "Query” $ itDB "work" $ doexecute_
[sql| INSERT INTO things VALUES (‘me’) |]query_
[sql| SELECT name FROM things |]shouldReturn
[Only "me"]
In the example above describeDB
wraps describe
with a beforeAll
hook for creating a db and a afterAll
hook for stopping a db.
.
Tests can be written with itDB
which is wrapper around it
that uses the passed in TestDB
to run a db transaction automatically for the test.
The libary also provides a few other functions for more fine grained control over running transactions in tests.
- data TestDB = TestDB {
- tempDB :: DB
- pool :: Pool Connection
- setupDB :: (Connection -> IO ()) -> IO TestDB
- teardownDB :: TestDB -> IO ()
- withPool :: TestDB -> (Connection -> IO a) -> IO a
- withDB :: DB a -> TestDB -> IO a
- runDB :: TestDB -> DB a -> IO a
- itDB :: String -> DB a -> SpecWith TestDB
- describeDB :: (Connection -> IO ()) -> String -> SpecWith TestDB -> Spec
Documentation
setupDB :: (Connection -> IO ()) -> IO TestDB Source #
Start a temporary postgres
process and create a pool of connections to it
teardownDB :: TestDB -> IO () Source #
Drop all the connections and shutdown the postgres
process
withPool :: TestDB -> (Connection -> IO a) -> IO a Source #
Run an IO
action with a connection from the pool
describeDB :: (Connection -> IO ()) -> String -> SpecWith TestDB -> Spec Source #
Wraps describe
with a
beforeAll
(setupDB
migrate)
hook for creating a db and a
afterAll
teardownDB
hook for stopping a db.