@@ -14,29 +14,37 @@ import Network.Wai.Handler.Warp
1414import Test.Hspec
1515
1616import Servant.Client
17−import Servant.API.Sub
18−import Servant.API.Get
17+import Servant.API
1918import Servant.Server
2019
2120import Servant.ServerSpec
2221
2322type Api =
24− "a" :> Get Person
23+ ("a" :> Get Person)
24+ :<|> ("b" :> Capture "name" String :> Get Person)
2525api :: Proxy Api
2626api = Proxy
2727
2828server :: Application
2929server = serve api (
30− return alice
30+ return alice
31+ :<|> (\ name -> return $ Person name 0)
3132 )
3233
34+withServer :: (URIAuth -> IO a) -> IO a
35+withServer action = withWaiDaemon (return server) (action . mkHost "localhost")
36+
3337getA :: URIAuth -> EitherT String IO Person
34−getA = client api
38+getB :: String -> URIAuth -> EitherT String IO Person
39+(getA :<|> getB) = client api
3540
3641spec :: Spec
3742spec = do
38− it "Servant.API.Get" $ withWaiDaemon (return server) $ \ port -> do
39− runEitherT (getA (mkHost "localhost" port)) `shouldReturn` Right alice
43+ it "Servant.API.Get" $ withServer $ \ host -> do
44+ runEitherT (getA host) `shouldReturn` Right alice
45+
46+ it "Servant.API.Capture" $ withServer $ \ host -> do
47+ runEitherT (getB "Paula" host) `shouldReturn` Right (Person "Paula" 0)
4048
4149
4250-- * utils