servant-mock: add simple test case

This commit is contained in:
Sönke Hahn 2016-01-18 12:29:33 +01:00
parent 39b0507098
commit 3fdaffa08d
2 changed files with 37 additions and 3 deletions

View File

@ -58,5 +58,9 @@ test-suite spec
build-depends: build-depends:
base, base,
hspec, hspec,
hspec-wai,
QuickCheck,
servant, servant,
servant-mock servant-server,
servant-mock,
aeson

View File

@ -1,12 +1,42 @@
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TypeOperators #-}
module Servant.MockSpec where module Servant.MockSpec where
import Test.Hspec import Data.Aeson as Aeson
import Data.Proxy
import GHC.Generics
import Servant.API
import Test.Hspec hiding (pending)
import Test.Hspec.Wai
import Test.QuickCheck
import Servant
import Servant.API.Internal.Test.ComprehensiveAPI import Servant.API.Internal.Test.ComprehensiveAPI
import Servant.Mock import Servant.Mock
_ = mock comprehensiveAPI _ = mock comprehensiveAPI
data Body
= Body
| ArbitraryBody
deriving (Generic, ToJSON)
instance Arbitrary Body where
arbitrary = return ArbitraryBody
spec :: Spec spec :: Spec
spec = return () spec = do
describe "mock" $ do
context "Get" $ do
let api :: Proxy (Get '[JSON] Body)
api = Proxy
app = serve api (mock api)
with (return app) $ do
it "serves arbitrary response bodies" $ do
get "/" `shouldRespondWith` 200{
matchBody = Just $ Aeson.encode ArbitraryBody
}