0
這裏有三條路線,我嘗試匹配阿卡路由DSL不符合預期的路線
/games/2016/1
/games/2016
/games
,我想這個路由結構可以這樣做:
pathPrefix("games") {
logger.info("INSIDE GAMES PATH KEY ")
path(PathEnd) {
complete("no numbers")
} ~ path(IntNumber/IntNumber) { case (year: Int, week: Int) =>
logger.info("Matched week/year")
//gets games for this year and week
complete("two numbers")
} ~ path(IntNumber) { year: Int =>
logger.info("Matched year")
complete("one number")
}
}
該方法適用於前兩個例子我有,但不是最後的工作。我在做什麼錯了,我怎麼能解決這個問題,所以我的路由匹配/games
我試圖切換到PathEnd
PathNetural
,RemainingPath
等無濟於事。
編輯:我使用的測試案例:
it must "return all games for this week" in {
Get("/games") ~>
NflRoutes.gamesRoutes ~> check {
val games: Seq[NflGame] = responseAs[Seq[NflGame]]
games.size must be (14)
}
}
與日誌錯誤:
> test-only *NflRoutesTest*
[info] Compiling 1 Scala source to /home/chris/dev/suredbits-api/target/scala-2.11/classes...
[info] Compiling 1 Scala source to /home/chris/dev/suredbits-api/target/scala-2.11/test-classes...
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/home/chris/dev/suredbits-api/lib/nfldb-api-assembly-0.0.1.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/home/chris/.ivy2/cache/ch.qos.logback/logback-classic/jars/logback-classic-1.0.13.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [ch.qos.logback.classic.util.ContextSelectorStaticBinder]
13:09:39.721 TKD [com-suredbits-api-routes-NflRoutesTest-akka.actor.default-dispatcher-3] INFO akka.event.slf4j.Slf4jLogger - Slf4jLogger started
13:09:39.907 TKD [suredbits-api-akka.actor.default-dispatcher-4] INFO akka.event.slf4j.Slf4jLogger - Slf4jLogger started
13:09:40.012 TKD [pool-9-thread-6-ScalaTest-running-NflRoutesTest] INFO c.suredbits.api.routes.NflRoutes$ - INSIDE GAMES PATH KEY
[info] NflRoutesTest:
[info] - must return all games for this week *** FAILED ***
[info] Request was rejected (DynamicVariable.scala:58)
[info] ScalaTest
[info] Run completed in 934 milliseconds.
[info] Total number of tests run: 1
[info] Suites: completed 1, aborted 0
[info] Tests: succeeded 0, failed 1, canceled 0, ignored 0, pending 0
[info] *** 1 TEST FAILED ***
[error] Failed: Total 1, Failed 1, Errors 0, Passed 0
[error] Failed tests:
[error] com.suredbits.api.routes.NflRoutesTest
[error] (test:testOnly) sbt.TestsFailedException: Tests unsuccessful
[error] Total time: 4 s, completed Oct 10, 2016 1:09:40 PM
>
這並沒有:-( –
@ChrisStewart工作我已經添加了一些功能和單元測試,你可以詳細說明「沒有工作」嗎? –
我已經編輯了OP更加真實,注意日誌消息「INSIDE GAMES PATH KEY」我測試我的路徑 –