| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Test.Hspec.DB
Description
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.
describeDBmigrate "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.
Synopsis
- data TestDB = TestDB {
- tempDB :: DB
- pool :: Pool Connection
- setupDB :: (Connection -> IO ()) -> IO (Either StartError TestDB)
- setupDBWithConfig :: Config -> (Connection -> IO ()) -> IO (Either StartError TestDB)
- wrapCallback :: (Connection -> IO ()) -> DB -> 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
- describeDBWithConfig :: Config -> (Connection -> IO ()) -> String -> SpecWith TestDB -> Spec
Documentation
setupDB :: (Connection -> IO ()) -> IO (Either StartError TestDB) Source #
Start a temporary postgres process and create a pool of connections to it
setupDBWithConfig :: Config -> (Connection -> IO ()) -> IO (Either StartError TestDB) Source #
Start a temporary postgres process using the provided configuration
wrapCallback :: (Connection -> IO ()) -> DB -> IO TestDB Source #
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 describeDBWithConfig using the default configuration
describeDBWithConfig :: Config -> (Connection -> IO ()) -> String -> SpecWith TestDB -> Spec Source #
Wraps describe with a
beforeAll(setupDBmigrate)
hook for creating a db and a
afterAllteardownDB
hook for stopping a db.