@@ -14,29 +14,37 @@ import Network.Wai.Handler.Warp
14import Test.Hspec
14import Test.Hspec
16import Servant.Client
16import Servant.Client
17−import Servant.API.Sub
17+import Servant.API
18−import Servant.API.Get
19import Servant.Server
18import Servant.Server
21import Servant.ServerSpec
20import Servant.ServerSpec
24− "a" :> Get Person
23+ ("a" :> Get Person)
24+ :<|> ("b" :> Capture "name" String :> Get Person)
25api :: Proxy Api
25api :: Proxy Api
26api = Proxy
26api = Proxy
28server :: Application
28server :: Application
29server = serve api (
29server = serve api (
30− return alice
30+ return alice
31+ :<|> (\ name -> return $ Person name 0)
34+withServer :: (URIAuth -> IO a) -> IO a
35+withServer action = withWaiDaemon (return server) (action . mkHost "localhost")
33getA :: URIAuth -> EitherT String IO Person
37getA :: URIAuth -> EitherT String IO Person
38+getB :: String -> URIAuth -> EitherT String IO Person
34−getA = client api
39+(getA :<|> getB) = client api
36spec :: Spec
41spec :: Spec
38− it "Servant.API.Get" $ withWaiDaemon (return server) $ \ port -> do
43+ it "Servant.API.Get" $ withServer $ \ host -> do
39− runEitherT (getA (mkHost "localhost" port)) `shouldReturn` Right alice
44+ runEitherT (getA host) `shouldReturn` Right alice
46+ it "Servant.API.Capture" $ withServer $ \ host -> do
47+ runEitherT (getB "Paula" host) `shouldReturn` Right (Person "Paula" 0)