【问题标题】:How does the "specs" BDD framework for Scala work?Scala 的“规范”BDD 框架如何工作?
【发布时间】:2010-10-10 01:16:58
【问题描述】:

我刚刚开始使用 Scala,我想知道哪种语言功能允许您这样做:

"PersistentQueue" should {
  "add and remove one item" in {
    withTempFolder {
      val q = new PersistentQueue(folderName, "work", Config.fromMap(Map.empty))
      q.setup

      q.length mustEqual 0
      q.totalItems mustEqual 0
      q.bytes mustEqual 0
      q.journalSize mustEqual 0

      q.add("hello kitty".getBytes)

      q.length mustEqual 1
      q.totalItems mustEqual 1
      q.bytes mustEqual 11
      q.journalSize mustEqual 32

      new String(q.remove.get.data) mustEqual "hello kitty"

      q.length mustEqual 0
      q.totalItems mustEqual 1
      q.bytes mustEqual 0
      q.journalSize mustEqual 33

      q.close
      dumpJournal("work") mustEqual "add(11:0:hello kitty), remove"
    }
  }
}

来自unit tests for Kestrel

这里发生了什么? "PersistentQueue" should 是否意味着 Scala 字符串类已使用“应该”方法进行扩展,还是这里发生了其他事情?我快速浏览了 Scala 文档,但看不到此代码示例使用了哪些语言功能。

【问题讨论】:

    标签: scala bdd specs


    【解决方案1】:

    在我看来,隐式方法被添加到 String 类中。 This post有演示。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多