Basic hspec + postgres fixtures setup

This commit is contained in:
Joe Nelson
2014-08-10 17:18:52 -07:00
parent 6391c73184
commit 82d7953554
4 changed files with 153 additions and 10 deletions
+20 -10
View File
@@ -1,13 +1,13 @@
name: dbapi
version: 0.1.0.0
synopsis: The database is your api
license: MIT
license-file: LICENSE
author: Joe Nelson
maintainer: cred+github@begriffs.com
category: Web
build-type: Simple
cabal-version: >=1.10
name: dbapi
version: 0.1.0.0
synopsis: The database is your api
license: MIT
license-file: LICENSE
author: Joe Nelson, Adam Baker
maintainer: cred+github@begriffs.com
category: Web
build-type: Simple
cabal-version: >=1.10
executable dbapi
main-is: Main.hs
@@ -26,5 +26,15 @@ executable dbapi
, regex-base
, http-media, regex-tdfa
, Ranged-sets
, transformers
hs-source-dirs: src
default-language: Haskell2010
Test-Suite spec
Type: exitcode-stdio-1.0
Default-Language: Haskell2010
Hs-Source-Dirs: src , test
Ghc-Options: -Wall
Main-Is: Spec.hs
Build-Depends: base, hspec2, HDBC,
HDBC-postgresql
+27
View File
@@ -0,0 +1,27 @@
module PgQuerySpec where
import Test.Hspec
import Database.HDBC
import Database.HDBC.PostgreSQL
loadFixture :: String -> IO ()
loadFixture name = do
sql <- readFile $ "test/fixtures/" ++ name ++ ".sql"
conn <- connectPostgreSQL "postgres://postgres:@localhost:5432/dbapi_test"
runRaw conn sql
commit conn
main :: IO ()
main = do
hspec spec
spec :: Spec
spec = beforeAll (loadFixture "schema") $ do
describe "insert" $
it "can insert into an empty table" $
head [23 ..] `shouldBe` (23 :: Int)
describe "insert again" $
it "is true" $
True `shouldBe` True
+1
View File
@@ -0,0 +1 @@
{-# OPTIONS_GHC -F -pgmF hspec-discover #-}
+105
View File
@@ -0,0 +1,105 @@
--
-- PostgreSQL database dump
--
-- Dumped from database version 9.3.4
-- Dumped by pg_dump version 9.3.1
-- Started on 2014-08-10 15:29:43 PDT
SET statement_timeout = 0;
SET lock_timeout = 0;
SET client_encoding = 'UTF8';
SET standard_conforming_strings = on;
SET check_function_bodies = false;
SET client_min_messages = warning;
--
-- TOC entry 172 (class 3079 OID 12018)
-- Name: plpgsql; Type: EXTENSION; Schema: -; Owner: -
--
CREATE EXTENSION IF NOT EXISTS plpgsql WITH SCHEMA pg_catalog;
--
-- TOC entry 2209 (class 0 OID 0)
-- Dependencies: 172
-- Name: EXTENSION plpgsql; Type: COMMENT; Schema: -; Owner: -
--
COMMENT ON EXTENSION plpgsql IS 'PL/pgSQL procedural language';
SET search_path = public, pg_catalog;
SET default_tablespace = '';
SET default_with_oids = false;
--
-- TOC entry 171 (class 1259 OID 226379)
-- Name: auto_incrementing_pk; Type: TABLE; Schema: public; Owner: -; Tablespace:
--
CREATE TABLE auto_incrementing_pk (
id integer NOT NULL,
nullable_string character varying,
non_nullable_string character varying NOT NULL,
inserted_at timestamp with time zone DEFAULT now()
);
--
-- TOC entry 170 (class 1259 OID 226377)
-- Name: auto_incrementing_pk_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE auto_incrementing_pk_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--
-- TOC entry 2210 (class 0 OID 0)
-- Dependencies: 170
-- Name: auto_incrementing_pk_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--
ALTER SEQUENCE auto_incrementing_pk_id_seq OWNED BY auto_incrementing_pk.id;
--
-- TOC entry 2090 (class 2604 OID 226382)
-- Name: id; Type: DEFAULT; Schema: public; Owner: -
--
ALTER TABLE ONLY auto_incrementing_pk ALTER COLUMN id SET DEFAULT nextval('auto_incrementing_pk_id_seq'::regclass);
--
-- TOC entry 2211 (class 0 OID 0)
-- Dependencies: 170
-- Name: auto_incrementing_pk_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
--
SELECT pg_catalog.setval('auto_incrementing_pk_id_seq', 1, true);
--
-- TOC entry 2093 (class 2606 OID 226388)
-- Name: auto_incrementing_pk_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace:
--
ALTER TABLE ONLY auto_incrementing_pk
ADD CONSTRAINT auto_incrementing_pk_pkey PRIMARY KEY (id);
-- Completed on 2014-08-10 15:29:43 PDT
--
-- PostgreSQL database dump complete
--