diff options
Diffstat (limited to 'tests/src/test/scala')
-rw-r--r-- | tests/src/test/scala/com/softwaremill/sttp/IllTypedTests.scala | 39 | ||||
-rw-r--r-- | tests/src/test/scala/com/softwaremill/sttp/testHelpers.scala | 10 |
2 files changed, 37 insertions, 12 deletions
diff --git a/tests/src/test/scala/com/softwaremill/sttp/IllTypedTests.scala b/tests/src/test/scala/com/softwaremill/sttp/IllTypedTests.scala index 0d0c012..057ba9e 100644 --- a/tests/src/test/scala/com/softwaremill/sttp/IllTypedTests.scala +++ b/tests/src/test/scala/com/softwaremill/sttp/IllTypedTests.scala @@ -2,22 +2,37 @@ package com.softwaremill.sttp import org.scalatest.{FlatSpec, Matchers} +import scala.tools.reflect.ToolBoxError + class IllTypedTests extends FlatSpec with Matchers { "compilation" should "fail when trying to stream using the default handler" in { - """ - import akka.stream.scaladsl.Source - import akka.util.ByteString - import java.net.URI - implicit val sttpHandler = HttpURLConnectionSttpHandler - sttp.get(new URI("http://example.com")).response(asStream[Source[ByteString, Any]]).send() - """ shouldNot typeCheck + val thrown = intercept[ToolBoxError] { + EvalScala( + """ + import com.softwaremill.sttp._ + import akka.stream.scaladsl.Source + import akka.util.ByteString + import java.net.URI + implicit val sttpHandler = HttpURLConnectionSttpHandler + sttp.get(new URI("http://example.com")).response(asStream[Source[ByteString, Any]]).send() + """) + } + + thrown.getMessage should include( + "could not find implicit value for parameter handler: com.softwaremill.sttp.SttpHandler[R,akka.stream.scaladsl.Source[akka.util.ByteString,Any]]") } "compilation" should "fail when trying to send a request without giving an URL" in { - """ - import java.net.URI - implicit val sttpHandler = HttpURLConnectionSttpHandler - sttp.send() - """ shouldNot typeCheck + val thrown = intercept[ToolBoxError] { + EvalScala(""" + import com.softwaremill.sttp._ + import java.net.URI + implicit val sttpHandler = HttpURLConnectionSttpHandler + sttp.send() + """) + } + + thrown.getMessage should include( + "This is a partial request, the method & url are not specified") } } diff --git a/tests/src/test/scala/com/softwaremill/sttp/testHelpers.scala b/tests/src/test/scala/com/softwaremill/sttp/testHelpers.scala index bc7eccd..6d83848 100644 --- a/tests/src/test/scala/com/softwaremill/sttp/testHelpers.scala +++ b/tests/src/test/scala/com/softwaremill/sttp/testHelpers.scala @@ -48,3 +48,13 @@ trait ForceWrapped extends ScalaFutures { this: Suite => def force()(implicit fwv: ForceWrappedValue[R]): T = fwv.force(wrapped) } } + +object EvalScala { + import scala.tools.reflect.ToolBox + + def apply(code: String): Any = { + val m = scala.reflect.runtime.currentMirror + val tb = m.mkToolBox() + tb.eval(tb.parse(code)) + } +} |