Specs2中mustEqual中的奇怪错误

时间:2012-03-26 17:57:46

标签: scala specs2

我正在尝试编写一个解决方案来练习Scala for the impatient的8.4,但在我的specs2测试中遇到了一个奇怪的错误。

代码如下:

abstract class Item {
  def price: Double
  def description: String
}

class SimpleItem(val price: Double,  val description: String) extends Item

class Bundle(items: List[Item], val description: String) extends Item {
  def price  = (items map (_.price)).sum
}

测试是:

"SimpleItem" should {
    "allow usage of Item methods" in {
      val si = new SimpleItem(13, "Nail")
      si.price mustEqual 13
      si.description mustEqual "Nail"
    }
}

"Bundle" should {
    "summarize item prices" {
      val l = List(new SimpleItem(2, "Fork"), new SimpleItem(3, "Knife"))
      val b = new Bundle(l, "Cutlery")
      b.price mustEqual 5
      b.description mustEqual "Cutlery" 
    }
}

第一次测试顺利通过,但在第二次测试中我得到了:

[error]  found   : org.specs2.matcher.MatchResult[Any]
[error]  required: Int
[error]       b.description mustEqual "Cutlery"

我不明白。为什么会期待Int?为什么它在第一次测试中有效?

0 个答案:

没有答案