2015-04-27 49 views
1

我又一次在使用噴霧方式掙扎,無法正確設置測試。我查看了類似的問題spray-testkit: could not find implicit value for parameter ta:official spray template,無法弄清楚我錯過了什麼和/或做錯了什麼。Spray,ScalaTest和HTTP服務:找不到參數ta的隱含值:

我有一個非常簡單的服務:

trait SimpleService extends HttpService{ 

    val fooRoute = path("foo") { 
    get { 
     complete("bar") 
    } 
    } 
} 

而且我有一個非常簡單的測試:

class SimpleServiceTest extends FlatSpec with Matchers with SimpleService with ScalatestRouteTest { 

    override implicit def actorRefFactory: ActorRefFactory = system 

    "The service" should "return OK status when getting /foo" in { 
    Get("/foo") ~> fooRoute ~> check { 
     status should be(OK) 
    } 
    } 
} 

,當我嘗試編譯,我得到以下錯誤:

Error:(17, 17) could not find implicit value for parameter ta: SimpleServiceTest.this.TildeArrow[spray.routing.RequestContext,Unit] 
Get("/foo") ~> fooRoute ~> check { 
      ^

任何人都可以幫助我,並告訴我我失蹤了什麼?我沒有發現任何不尋常的東西,我正在評估Play而不是噴霧。

回答

0

你應該SimpleService前混入ScalatestRouteTest,就像這樣:

class SimpleServiceTest extends ScalatestRouteTest with FlatSpec with Matchers with SimpleService 

另一種可能的解決方案是增加以下行到你的測試拋出隱未發現:

implicitly[spray.testkit.RouteTestTimeout] 
implicitly[spray.routing.RoutingSettings] 
implicitly[spray.util.LoggingContext] 

看看哪些訂單拋出併爲該類型提供隱式。

+0

'FlatSpec'需要是第一,因爲它不是一個特點,但我只是做正是這一點和我得到同樣的錯誤。 – rabejens

+0

我終於放棄了這一點,並轉向播放。 – rabejens

-1

ScalatestRouteTest已經提供了一個隱式的ActorySystem。從您的actorRefFactory方法中刪除「隱式」修飾符,並且應該執行測試。

這解決了這個問題對我的代碼

Spray.io: Can't compile test spec

相關問題