运行 sbt 控制台中的 specs2

Run specs2 in sbt console

是否可以 运行 并在 sbt 控制台中试用 specs2?我试过 === 但这没有用,因为我认为它是规范 class 中的一种方法。我也试过:

class A extends Specification{ "b" should{ "do" in{ 3 === 4 } } }; (new A).toResult(true) 

如果我知道正确的调用方法,我怀疑上面的方法应该有效,values

理想情况下,如果我可以执行单个语句,我会喜欢它,但如果那不可能,有没有办法 运行 这种块?

PS:specs2 是否有非 Fluent 接口?

您可以在控制台中对 运行 期望执行以下操作:

import org.specs2._, matcher.MustMatchers._, execute._

def t[R:AsResult](r: =>R) = specs2.run(new Specification { def is = p^s2"test $r" })

// then
t(1 === 2)

[info] Specification
[info]
[error] x test
[error]  '1' is not equal to '2' (file:1)
[info]
[info] Total for specification Specification
[info] Finished in 5 ms
       1 example, 1 failure, 0 error
[info]