test suite: added initial test suite

This commit is contained in:
Sönke Hahn 2014-10-27 07:24:23 +01:00
parent d838191ec8
commit 13664a218c
3 changed files with 74 additions and 0 deletions

View File

@ -60,3 +60,27 @@ executable greet
, either
, text
, network-uri
test-suite spec
type: exitcode-stdio-1.0
ghc-options:
-Wall -Werror -fno-warn-name-shadowing -fno-warn-missing-signatures
default-language: Haskell2010
hs-source-dirs: src, test
main-is: Spec.hs
build-depends:
base == 4.*
, aeson
, bytestring
, either
, exceptions
, hspec2
, hspec-wai
, http-client
, http-types
, network-uri >= 2.6
, string-conversions
, text
, transformers
, wai
, wai-extra

View File

@ -0,0 +1,49 @@
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE ScopedTypeVariables #-}
module Servant.ServerSpec where
import Data.Aeson
import Data.Proxy
import GHC.Generics
import Network.Wai.Test
import Test.Hspec
import Test.Hspec.Wai
import Servant.API.Get
import Servant.Server
data Person = Person {
name :: String,
age :: Integer
}
deriving (Eq, Show, Generic)
instance ToJSON Person
instance FromJSON Person
alice :: Person
alice = Person "Alice" 103
spec :: Spec
spec = do
getSpec
type GetApi = Get Person
getApi :: Proxy GetApi
getApi = Proxy
getSpec = do
describe "Servant.API.Get" $ do
with (return (serve getApi (return alice))) $ do
it "serves a Person" $ do
response <- get "/"
return response `shouldRespondWith` 200
liftIO $ do
decode' (simpleBody response) `shouldBe` Just alice

1
test/Spec.hs Normal file
View File

@ -0,0 +1 @@
{-# OPTIONS_GHC -F -pgmF hspec-discover #-}