diff options
author | adamw <adam@warski.org> | 2017-10-09 17:03:44 +0200 |
---|---|---|
committer | adamw <adam@warski.org> | 2017-10-09 17:03:44 +0200 |
commit | 5620043c1fc9fc846fa4a5fe91b2af7fb1ff6008 (patch) | |
tree | 6cc71430df59ad68815352be26696b835e3354ac /core/src/test/scala | |
parent | e093ee494d45350818933049c498ec5eb4fb98be (diff) | |
download | sttp-5620043c1fc9fc846fa4a5fe91b2af7fb1ff6008.tar.gz sttp-5620043c1fc9fc846fa4a5fe91b2af7fb1ff6008.tar.bz2 sttp-5620043c1fc9fc846fa4a5fe91b2af7fb1ff6008.zip |
Backend stubs with fallback (thx to @gabro)
Diffstat (limited to 'core/src/test/scala')
-rw-r--r-- | core/src/test/scala/com/softwaremill/sttp/testing/SttpBackendStubTests.scala | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/core/src/test/scala/com/softwaremill/sttp/testing/SttpBackendStubTests.scala b/core/src/test/scala/com/softwaremill/sttp/testing/SttpBackendStubTests.scala index 538dd35..b80ae76 100644 --- a/core/src/test/scala/com/softwaremill/sttp/testing/SttpBackendStubTests.scala +++ b/core/src/test/scala/com/softwaremill/sttp/testing/SttpBackendStubTests.scala @@ -13,7 +13,7 @@ class SttpBackendStubTests extends FlatSpec with Matchers with ScalaFutures { .whenRequestMatches(_.method == Method.GET) .thenRespondServerError() - it should "use the first rule if it matches" in { + "backend stub" should "use the first rule if it matches" in { implicit val b = testingStub val r = sttp.get(uri"http://example.org/a/b/c").send() r.is200 should be(true) @@ -48,4 +48,23 @@ class SttpBackendStubTests extends FlatSpec with Matchers with ScalaFutures { val r = sttp.post(uri"http://example.org").send() r.futureValue.code should be(404) } + + val testingStubWithFallback = SttpBackendStub + .withFallback(testingStub) + .whenRequestMatches(_.uri.path.startsWith(List("c"))) + .thenRespond("ok") + + "backend stub with fallback" should "use the stub when response for a request is defined" in { + implicit val b = testingStubWithFallback + + val r = sttp.post(uri"http://example.org/c").send() + r.body should be(Right("ok")) + } + + it should "delegate to the fallback for unhandled requests" in { + implicit val b = testingStubWithFallback + + val r = sttp.post(uri"http://example.org/a/b").send() + r.is200 should be(true) + } } |