on master help sign in
Pull out instance for hopefully more clarity
bb36515Erik Aker
doc/cookbook/testing/Testing.lhs+4−1
@@ -253,6 +253,9 @@ Imagine, then, that this is our real server implementation:
253type DocApi =
253type DocApi =
254 "docs" :> Capture "docId" Integer :> Get '[JSON] Value
254 "docs" :> Capture "docId" Integer :> Get '[JSON] Value
255
255
256+docsApp :: Text -> Text -> Application
257+docsApp esHost esPort = serve (Proxy :: Proxy DocApi) $ docServer esHost esPort
258+
256docServer :: Text -> Text -> Server DocApi
259docServer :: Text -> Text -> Server DocApi
257docServer esHost esPort = getDocById esHost esPort
260docServer esHost esPort = getDocById esHost esPort
258
261
@@ -330,7 +333,7 @@ Hopefully, this will simplify our testing code:
330thirdPartyResourcesSpec :: Spec
333thirdPartyResourcesSpec :: Spec
331thirdPartyResourcesSpec = around_ withElasticsearch $ do
334thirdPartyResourcesSpec = around_ withElasticsearch $ do
332 -- we call `with` from `hspec-wai` and pass *real* `Application`
335 -- we call `with` from `hspec-wai` and pass *real* `Application`
333− with (pure $ serve (Proxy :: Proxy DocApi) $ docServer "localhost" "9999") $ do
336+ with (pure $ docsApp "localhost" "9999") $ do
334 describe "GET /docs" $ do
337 describe "GET /docs" $ do
335 it "should be able to get a document" $
338 it "should be able to get a document" $
336 -- `get` is a function from hspec-wai`.
339 -- `get` is a function from hspec-wai`.