diff options
author | Dean Povey <dpovey@skedulo.com> | 2017-11-29 16:57:51 +1000 |
---|---|---|
committer | Dean Povey <dpovey@skedulo.com> | 2017-11-29 16:57:51 +1000 |
commit | 3b1b7d8389a503bd28a99d84fdbfd1fc9857a2e9 (patch) | |
tree | 141f4b680df7156747876911e74d82e16c625b9b /core/src/test/scala | |
parent | 6b7edb9bec49b4070acda2b75a3d91ef68074547 (diff) | |
download | sttp-3b1b7d8389a503bd28a99d84fdbfd1fc9857a2e9.tar.gz sttp-3b1b7d8389a503bd28a99d84fdbfd1fc9857a2e9.tar.bz2 sttp-3b1b7d8389a503bd28a99d84fdbfd1fc9857a2e9.zip |
When stubbing using with thenRespondWithCode, treat 2xx as a success and return Right(body)
Diffstat (limited to 'core/src/test/scala')
-rw-r--r-- | core/src/test/scala/com/softwaremill/sttp/testing/SttpBackendStubTests.scala | 56 |
1 files changed, 54 insertions, 2 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 7e6f15f..1cab218 100644 --- a/core/src/test/scala/com/softwaremill/sttp/testing/SttpBackendStubTests.scala +++ b/core/src/test/scala/com/softwaremill/sttp/testing/SttpBackendStubTests.scala @@ -31,7 +31,7 @@ class SttpBackendStubTests extends FlatSpec with Matchers with ScalaFutures { implicit val b = testingStub val r = sttp.get(uri"http://example.org/a/b/c").send() r.is200 should be(true) - r.body should be('left) + r.body should be('right) } it should "use subsequent rules if the first doesn't match" in { @@ -47,7 +47,7 @@ class SttpBackendStubTests extends FlatSpec with Matchers with ScalaFutures { implicit val b = testingStub val r = sttp.get(uri"http://example.org/a/b/c?p=v").send() r.is200 should be(true) - r.body should be('left) + r.body should be('right) } it should "use the default response if no rule matches" in { @@ -107,6 +107,58 @@ class SttpBackendStubTests extends FlatSpec with Matchers with ScalaFutures { result.body should be(Right(20)) } + it should "handle a 201 as a success" in { + implicit val s = SttpBackendStub(HttpURLConnectionBackend()) + .whenAnyRequest + .thenRespondWithCode(201) + + val result = sttp + .get(uri"http://example.org") + .send() + + result.body should be(Right("")) + + } + + it should "handle a 300 as a failure" in { + implicit val s = SttpBackendStub(HttpURLConnectionBackend()) + .whenAnyRequest + .thenRespondWithCode(300) + + val result = sttp + .get(uri"http://example.org") + .send() + + result.body should be(Left("")) + + } + + it should "handle a 400 as a failure" in { + implicit val s = SttpBackendStub(HttpURLConnectionBackend()) + .whenAnyRequest + .thenRespondWithCode(400) + + val result = sttp + .get(uri"http://example.org") + .send() + + result.body should be(Left("")) + + } + + it should "handle a 500 as a failure" in { + implicit val s = SttpBackendStub(HttpURLConnectionBackend()) + .whenAnyRequest + .thenRespondWithCode(500) + + val result = sttp + .get(uri"http://example.org") + .send() + + result.body should be(Left("")) + + } + private val testingStubWithFallback = SttpBackendStub .withFallback(testingStub) .whenRequestMatches(_.uri.path.startsWith(List("c"))) |