前面的例子
import org.specs2._ class HelloWorldAcceptanceSpec extends Specification { def is = s2""" This is a specification to check the 'Hello world' string The 'Hello world' string should contain 11 characters $e1 start with 'Hello' $e2 end with 'world' $e3 """ def e1 = "Hello world" must have size(11) def e2 = "Hello world" must startWith("Hello") def e3 = "Hello world" must endWith("world") }
实际上是使用Fragment API,我们使用Fragment API重写什么例子,它是一系列Fragment对象通过^运算符连接而成:
import org.specs2._ class HelloWorldAcceptanceSpec extends Specification { def is = "This is a specification to check the 'Hello world' string" ^ "The 'Hello world' string should" ^ "contain 11 characters" ! e1 ^ "start with 'Hello'" ! e2 ^ "end with 'world'" ! e3 def e1 = "Hello world" must have size(11) def e2 = "Hello world" must startWith("Hello") def e3 = "Hello world" must endWith("world") }
其中的Example对象的格式为 ?description? ! body. body返回一个Result对象,当你直接使用Fragment API使用^运算符构建Text和Example对象时有些规则需要注意,这些规则影响到结果的显示格式。
规则
spec2的结果显示的布局缺省情况是自动完成,其显示和源码显示类似。
其显示规则如下: