【问题标题】:Specs2's acceptance specification can't work with 'Scope'Specs2 的验收规范不能与“范围”一起使用
【发布时间】:2014-10-18 13:09:18
【问题描述】:

我用 Scope 进行了一些 specs2 测试:

"hello" should {
   "return world" in new Subject {
       hello.get === "world"
   }
}
trait Subject extends org.specs2.specification.Scope {
   val hello = new Hello
}

现在我想把它转换成接受风格:

def is = s2"""
   hello.get should return 'world' $e1
"""
def e1 = new Subject {
    hello.get === "world"
}
trait Subject extends org.specs2.specification.Scope {
   val hello = new Hello
}

好像可以了,测试通过了,但是很快我发现不管怎么修改都没有失败:

hello.get === "invalid-world" // still passing

如何在接受风格中正确使用Scope

【问题讨论】:

    标签: scala specs2


    【解决方案1】:

    刚刚发现这个问题的一个问题:https://github.com/etorreborre/specs2/issues/180

    从那里引用的答案:

    这是意料之中的。范围是仅用于可变的特征 规格。您有两种解决方法:

    使用案例类或案例对象

    s2"""
     will fail      ${t.fail}
    """
    case object t {
      val foo = false
      def fail = foo must beTrue
    }
    

    ThrownExpectations 特征混入Specification,这样失败的期望就会“冒泡” 在 Scope 特征之外

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-12-18
      • 1970-01-01
      • 2019-05-26
      • 2012-04-08
      相关资源
      最近更新 更多