git.iko.soy/typeable/servant
on master help sign in
servant-mock: add simple test case
commit3fdaffa08dea2e2806c044b7b21d86823fe2a73b authorSönke Hahn <soenkehahn@gmail.com> dateMon 18 Jan 2016, 12:29 (11 years ago) parent39b0507
2 files changed+37−3
servant-mock/servant-mock.cabal+5−1 servant-mock/test/Servant/MockSpec.hs+32−2
servant-mock/servant-mock.cabal+5−1
@@ -58,5 +58,9 @@ test-suite spec
5858 build-depends:
5959 base,
6060 hspec,
61+ hspec-wai,
62+ QuickCheck,
6163 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 #-}
16
27module Servant.MockSpec where
38
4−import Test.Hspec
9+import Data.Aeson as Aeson
10+import Data.Proxy
11+import GHC.Generics
12+import Servant.API
13+import Test.Hspec hiding (pending)
14+import Test.Hspec.Wai
15+import Test.QuickCheck
516
17+import Servant
618import Servant.API.Internal.Test.ComprehensiveAPI
719import Servant.Mock
820
921_ = mock comprehensiveAPI
1022
23+data Body
24+ = Body
25+ | ArbitraryBody
26+ deriving (Generic, ToJSON)
27+
28+instance Arbitrary Body where
29+ arbitrary = return ArbitraryBody
30+
1131spec :: 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+ }