diff options
author | adamw <adam@warski.org> | 2017-10-18 14:20:26 +0200 |
---|---|---|
committer | adamw <adam@warski.org> | 2017-10-18 14:20:26 +0200 |
commit | 21c4700bbe8cf37d7b9feacc5afdf64357604d8f (patch) | |
tree | 50cd74646955bae495296b1d9a212ac412a75b7c /docs/backends/testing.rst | |
parent | 6e109a964383bfe5e2be04f65fa7cc1356a97cbe (diff) | |
download | sttp-21c4700bbe8cf37d7b9feacc5afdf64357604d8f.tar.gz sttp-21c4700bbe8cf37d7b9feacc5afdf64357604d8f.tar.bz2 sttp-21c4700bbe8cf37d7b9feacc5afdf64357604d8f.zip |
More docs
Diffstat (limited to 'docs/backends/testing.rst')
-rw-r--r-- | docs/backends/testing.rst | 24 |
1 files changed, 8 insertions, 16 deletions
diff --git a/docs/backends/testing.rst b/docs/backends/testing.rst index 0ac21c2..c0cfc6f 100644 --- a/docs/backends/testing.rst +++ b/docs/backends/testing.rst @@ -1,13 +1,9 @@ Testing ======= -If you need a stub backend for use in tests instead of a "real" backend (you -probably don't want to make HTTP calls during unit tests), you can use the -``SttpBackendStub`` class. It allows specifying how the backend should respond -to requests matching given predicates. +If you need a stub backend for use in tests instead of a "real" backend (you probably don't want to make HTTP calls during unit tests), you can use the ``SttpBackendStub`` class. It allows specifying how the backend should respond to requests matching given predicates. -A backend stub can be created using an instance of a "real" backend, or by -explicitly giving the response wrapper monad and supported streams type. +A backend stub can be created using an instance of a "real" backend, or by explicitly giving the response wrapper monad and supported streams type. For example:: @@ -23,18 +19,14 @@ For example:: val response2 = sttp.post(uri"http://example.org/d/e").send() // response2.code will be 500 -However, this approach has one caveat: the responses are not type-safe. That -is, the backend cannot match on or verify that the type included in the -response matches the response type requested. +However, this approach has one caveat: the responses are not type-safe. That is, the backend cannot match on or verify that the type included in the response matches the response type requested. -It is also possible to create a stub backend which delegates calls to another -(possibly "real") backend if none of the specified predicates match a request. -This can be useful during development, to partially stub a yet incomplete -API with which we integrate:: +It is also possible to create a stub backend which delegates calls to another (possibly "real") backend if none of the specified predicates match a request. This can be useful during development, to partially stub a yet incomplete API with which we integrate:: - implicit val testingBackend = SttpBackendStub.withFallback(HttpURLConnectionBackend()) - .whenRequestMatches(_.uri.path.startsWith(List("a"))) - .thenRespond("I'm a STUB!") + implicit val testingBackend = + SttpBackendStub.withFallback(HttpURLConnectionBackend()) + .whenRequestMatches(_.uri.path.startsWith(List("a"))) + .thenRespond("I'm a STUB!") val response1 = sttp.get(uri"http://api.internal/a").send() // response1.body will be Right("I'm a STUB") |