@@ -8,6 +8,7 @@
8module Servant.ServerSpec where
8module Servant.ServerSpec where
11+import Control.Monad.Trans.Either
11import Data.Aeson
12import Data.Aeson
12import Data.Proxy
13import Data.Proxy
13import Data.String.Conversions
14import Data.String.Conversions
@@ -18,6 +19,7 @@ import Network.Wai.Test
18import Test.Hspec
19import Test.Hspec
19import Test.Hspec.Wai
20import Test.Hspec.Wai
22+import Servant.API.Capture
21import Servant.API.Get
23import Servant.API.Get
22import Servant.API.GetParam
24import Servant.API.GetParam
23import Servant.API.Post
25import Servant.API.Post
@@ -54,11 +56,15 @@ instance FromJSON Animal
54jerry :: Animal
56jerry :: Animal
55jerry = Animal "Mouse" 4
57jerry = Animal "Mouse" 4
60+tweety = Animal "Bird" 2
60spec :: Spec
65spec :: Spec
63 getParamSpec
69 getParamSpec
@@ -66,6 +72,25 @@ spec = do
75+type CaptureApi = Capture "legs" Integer :> Get Animal
76+captureApi :: Proxy CaptureApi
78+captureServer :: Integer -> EitherT (Int, String) IO Animal
79+captureServer legs = case legs of
82+ _ -> left (404, "not found")
86+ describe "Servant.API.Capture" $ do
87+ with (return (serve captureApi captureServer)) $ do
88+ it "can capture parts of the 'pathInfo'" $ do
91+ decode' (simpleBody response) `shouldBe` Just tweety
69type GetApi = Get Person
94type GetApi = Get Person
70getApi :: Proxy GetApi
95getApi :: Proxy GetApi
71getApi = Proxy
96getApi = Proxy