2015-08-26 40 views
0

我有以下SPEC2测试Specs2斯卡拉错误不计算字符串是相同

import akka.testkit._ 
import akka.actor.ActorSystem 
import com.github.nfldb.config.{NflDbApiActorSystemConfig, NflDbApiDbConfigTest} 
import org.scalatest.MustMatchers 
import org.specs2.mutable.Specification 
import spray.testkit.Specs2RouteTest 
import spray.routing.HttpService 
import spray.http.StatusCodes._ 
import spray.json.DefaultJsonProtocol._ 
import spray.httpx.SprayJsonSupport._ 
import concurrent.duration._ 

/** 
* Created by chris on 8/25/15. 
*/ 
class NflPlayerScoringSvcTest extends Specification with Specs2RouteTest with NflPlayerScoringService 
    with NflDbApiDbConfigTest with NflDbApiActorSystemConfig { 
    import PlayerScoreProtocol.playerScoreProtocol 
    implicit def actorRefFactory = actorSystem 
    implicit def default(implicit system: ActorSystem) = RouteTestTimeout(new DurationInt(5).second.dilated(system)) 

    "NflPlayerScoringSvc" should { 

    "return hello" in { 
     Get("/hello") ~> nflPlayerScoringServiceRoutes ~> check { 
     responseAs[String] must contain("Say hello") 
     } 
    } 

    "calculate a player's score for a given week" in { 
     import PlayerScoreProtocol.playerScoreProtocol 
     Get("/playerScore?playerId=00-0031237&gsisId=2015081551") ~> nflPlayerScoringServiceRoutes ~> check { 
     val playerScore : DfsNflScoringEngineComponent.PlayerScore = responseAs[DfsNflScoringEngineComponent.PlayerScore] 
     println(playerScore.playerId == "00-0031237") //evaluates to true 
     playerScore.playerId must be ("00-0031237") 
     } 
    } 

    } 
} 

正如你可以在我的评论看,我println声明要求的playerScore.playerId == "00-0031237演算值为等价为true。然而,在下一行中,我的测试失败说,

[error] '00-0031237' is not the same as '00-0031237' (NflPlayerScoringSvcTest.scala:37) 

这是怎么发生的?

回答

1

你有没有试过这样:

playerScore.playerId must beEqualTo("00-0031237")