aboutsummaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorPaweł Stawicki <pawelstawicki@gmail.com>2018-01-24 18:38:40 +0100
committerPaweł Stawicki <pawelstawicki@gmail.com>2018-01-24 18:38:40 +0100
commit9da3ff4fd8fc76772b365b1368d335d1722f007b (patch)
tree324cfea63e485080066c1d1f431ace2d1e68cd96 /docs
parente60dab5c77bca2c3b7a76732e98b406a9d7a095e (diff)
downloadsttp-9da3ff4fd8fc76772b365b1368d335d1722f007b.tar.gz
sttp-9da3ff4fd8fc76772b365b1368d335d1722f007b.tar.bz2
sttp-9da3ff4fd8fc76772b365b1368d335d1722f007b.zip
Docs for thenResponseWithMonad, and a little code cleanup in test
Diffstat (limited to 'docs')
-rw-r--r--docs/testing.rst12
1 files changed, 12 insertions, 0 deletions
diff --git a/docs/testing.rst b/docs/testing.rst
index bb2e3d5..ead722b 100644
--- a/docs/testing.rst
+++ b/docs/testing.rst
@@ -49,6 +49,18 @@ It is also possible to match requests by partial function, returning a response.
This approach to testing has one caveat: the responses are not type-safe. That is, the stub backend cannot match on or verify that the type of the response body matches the response body type requested.
+Another way to specify the behaviour is passing a response monad to Stub. It is useful if you need to test scenario with slow server, when response should be not returned immediately but after some time.
+Example with Futures: ::
+
+ implicit val testingBackend = SttpBackendStub(new FutureMonad()).whenAnyRequest
+ .thenRespondWithMonad(Future {
+ Thread.sleep(5000)
+ Response(Right("OK"), 200, "", Nil, Nil)
+ })
+
+ val respFuture = sttp.get(uri"http://example.org").send()
+ // responseFuture will complete after 10 seconds with "OK" response
+
Simulating exceptions
---------------------