我正在使用一个简单的测试规范使用喷雾,我无法正确编译,不知道我做错了什么.我的scala版本是2.9.3并且喷涂1.0.1(更新其中任何一个都不是合适的选项).这是我的测试规范代码:
import org.specs2.mutable.Specification
import spray.testkit.Specs2RouteTest
import spray.http._
import akka.util.Duration
import java.util.concurrent.TimeUnit
import service.MyProxy
abstract class MyTestSpec extends Specification with Specs2RouteTest with MyProxy{
val duration = Duration(30, TimeUnit.SECONDS)
implicit val routeTestTimeout = RouteTestTimeout(duration)
"MyProxy" should {
"return a json for GET requests to the /api/getclass/classCode path for a regular request" in {
Get("/api/getclass/123/") ~> myRoutes~> check {
responseAs[String] must contain("classCode")
contentType === ContentTypes.`application/json`
}
}
} // end should...
} //end class
Run Code Online (Sandbox Code Playgroud)
我在运行测试时遇到此错误.
[error] C:\Users\Desktop\Project\MyTestSpec.scala:23: could not find implicit value for …Run Code Online (Sandbox Code Playgroud) 如果我有一个端点解组json像这样:
(path("signup")& post) {
entity(as[Credentials]) { credentials =>
…
Run Code Online (Sandbox Code Playgroud)
如何使用Spray测试规范测试:
"The Authentication service" should {
"create a new account if none exists" in {
Post("/api/authentication/signup", """{"email":"foo", "password":"foo:" }""") ~> authenticationRoute ~> check {
handled === true
}
}
}
Run Code Online (Sandbox Code Playgroud)
由于几个原因,这显然不起作用.什么是正确的方法?
我尝试喷涂测试
class FullTestKitExampleSpec extends Specification with Specs2RouteTest with UserController with HttpService {
def actorRefFactory = system
"The service" should {
"return a greeting for GET requests to the root path" in {
Get("/user") ~> `Accept-Encoding`(gzip) ~> userRoute ~> check {
val responsex = response
responseAs[String] must contain("Test1")
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
我跟着路由器
trait UserController extends HttpService with Json4sSupport with CORSSupport{
override implicit def json4sFormats: Formats = DefaultFormats
val userRoute = {
cors {
compressResponse(Gzip) {
path("user") {
get {
complete …Run Code Online (Sandbox Code Playgroud) 我是Scala和Spray的新手.我根据本博文中给出的说明编写了一个简单的REST API. http://www.smartjava.org/content/first-steps-rest-spray-and-scala
所有人都按预期工作.
现在我想修改程序来打印HTTP头文件,如编码,语言,远程地址等.我想打印所有的头信息(目的是记录这些信息)
但我找不到合适的文档或示例.谁能帮助我完成这件事.