일부 JSON 구문 분석의 유효성을 검사하기 위해 specs 테스트를 만들었습니다. 이 테스트는 완벽하게 잘 작동하지만 다소 시끄 럽습니다.unbox 옵션과 어느 쪽이든 specs matcher가 있습니까
기존 코드가 unbox 옵션에 있습니까?
"twitter json to Scala class mapper" should {
"parsing a tweet" in {
TwitterJsonMapper.tweetP(tweetS) match {
case Right(t: Tweet) => {
implicit def unOption[T](t: Option[T]): T = t.get
implicit def unEither[T](t: Either[T,Throwable]): T = t match {case Left(left) => left ;case Right(t) => throw t}
"test id" in {
true must_== (t.id.get == 228106060337135617l)
}
"test id_str" in {
true must_== (t.id_str.get == "228106060337135617")
}
"test time" in {
true must_== (t.created_at.getHours == 13)
}
}
case Left((pe: JsonParseException, reason: String)) => fail(reason + "\n" + pe)
}
}
}
//The Tweet is produced from JSON using Fasterxml's Jackson-Scala library.
//I want to use Option or Either monads over all child attributes - for the usual reasons.
case class Tweet(
@BeanProperty contributors: Option[String],
@BeanProperty coordinates: Option[String],
@BeanProperty @JsonDeserialize (
using = classOf[TwitterDateDeserializer]
) created_at: Either[Date,Throwable],
@BeanProperty favorited: Boolean = false,
//elided etc etc
@BeanProperty id_str: Option[String]
}
예, 정합 기의 설명서를 참조하십시오 : http://etorreborre.github.com/specs2/guide/org.specs2.guide.Matchers.html#Matchers –
아, 알았습니다. 나는 아직 사양 1에 있습니다. 내 라이브러리를 업그레이드하는 데 많은 시간을 할애해야합니다. 스펙 1에없는 기능입니까? –
신뢰할 수있는 scala/maven/eclipse/specs - toolchain - up 및 running을 얻는 것은 매우 어렵습니다. 나는 이클립스로 작업 할 스펙을 얻었고 내 의존성의 해당 섹션을 동결시켰다. –