git.iko.soy/typeable/servant
on master help sign in
test suite: added initial test suite
13664a2Sönke Hahn
servant.cabal+24
@@ -60,3 +60,27 @@ executable greet
60 , either
60 , either
61 , text
61 , text
62 , network-uri
62 , network-uri
63+
64+test-suite spec
65+ type: exitcode-stdio-1.0
66+ ghc-options:
67+ -Wall -Werror -fno-warn-name-shadowing -fno-warn-missing-signatures
68+ default-language: Haskell2010
69+ hs-source-dirs: src, test
70+ main-is: Spec.hs
71+ build-depends:
72+ base == 4.*
73+ , aeson
74+ , bytestring
75+ , either
76+ , exceptions
77+ , hspec2
78+ , hspec-wai
79+ , http-client
80+ , http-types
81+ , network-uri >= 2.6
82+ , string-conversions
83+ , text
84+ , transformers
85+ , wai
86+ , wai-extra
test/Servant/ServerSpec.hsnew file+49
@@ -0,0 +1,49 @@
1+{-# LANGUAGE DeriveGeneric #-}
2+{-# LANGUAGE OverloadedStrings #-}
3+{-# LANGUAGE QuasiQuotes #-}
4+{-# LANGUAGE ScopedTypeVariables #-}
5+
6+module Servant.ServerSpec where
7+
8+
9+import Data.Aeson
10+import Data.Proxy
11+import GHC.Generics
12+import Network.Wai.Test
13+import Test.Hspec
14+import Test.Hspec.Wai
15+
16+import Servant.API.Get
17+import Servant.Server
18+
19+
20+data Person = Person {
21+ name :: String,
22+ age :: Integer
23+ }
24+ deriving (Eq, Show, Generic)
25+
26+instance ToJSON Person
27+instance FromJSON Person
28+
29+alice :: Person
30+alice = Person "Alice" 103
31+
32+
33+spec :: Spec
34+spec = do
35+ getSpec
36+
37+
38+type GetApi = Get Person
39+getApi :: Proxy GetApi
40+getApi = Proxy
41+
42+getSpec = do
43+ describe "Servant.API.Get" $ do
44+ with (return (serve getApi (return alice))) $ do
45+ it "serves a Person" $ do
46+ response <- get "/"
47+ return response `shouldRespondWith` 200
48+ liftIO $ do
49+ decode' (simpleBody response) `shouldBe` Just alice
test/Spec.hsnew file+1
@@ -0,0 +1 @@
1+{-# OPTIONS_GHC -F -pgmF hspec-discover #-}