git.iko.soy/typeable/servant
on master help sign in
servant-mock: add simple test case
3fdaffaSönke Hahn
servant-mock/servant-mock.cabal+5−1
@@ -58,5 +58,9 @@ test-suite spec
58 build-depends:
58 build-depends:
59 base,
59 base,
60 hspec,
60 hspec,
61+ hspec-wai,
62+ QuickCheck,
61 servant,
63 servant,
62− servant-mock
64+ servant-server,
65+ servant-mock,
66+ aeson
servant-mock/test/Servant/MockSpec.hs+32−2
@@ -1,12 +1,42 @@
1+{-# LANGUAGE DataKinds #-}
2+{-# LANGUAGE DeriveAnyClass #-}
3+{-# LANGUAGE DeriveGeneric #-}
4+{-# LANGUAGE OverloadedStrings #-}
5+{-# LANGUAGE TypeOperators #-}
1
6
2module Servant.MockSpec where
7module Servant.MockSpec where
3
8
9+import Data.Aeson as Aeson
10+import Data.Proxy
11+import GHC.Generics
12+import Servant.API
13+import Test.Hspec hiding (pending)
4−import Test.Hspec
14+import Test.Hspec.Wai
15+import Test.QuickCheck
5
16
17+import Servant
6import Servant.API.Internal.Test.ComprehensiveAPI
18import Servant.API.Internal.Test.ComprehensiveAPI
7import Servant.Mock
19import Servant.Mock
8
20
9_ = mock comprehensiveAPI
21_ = mock comprehensiveAPI
10
22
23+data Body
24+ = Body
25+ | ArbitraryBody
26+ deriving (Generic, ToJSON)
27+
28+instance Arbitrary Body where
29+ arbitrary = return ArbitraryBody
30+
11spec :: Spec
31spec :: Spec
12−spec = return ()
32+spec = do
33+ describe "mock" $ do
34+ context "Get" $ do
35+ let api :: Proxy (Get '[JSON] Body)
36+ api = Proxy
37+ app = serve api (mock api)
38+ with (return app) $ do
39+ it "serves arbitrary response bodies" $ do
40+ get "/" `shouldRespondWith` 200{
41+ matchBody = Just $ Aeson.encode ArbitraryBody
42+ }