@@ -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