Specs2を試す(10) - Layout -

参考: http://etorreborre.github.com/specs2/guide/org.specs2.guide.SpecStructure.html#Layout

The rules

Specs2 の Acceptance Specification を使うとソースコードに書いた Text および Example がほぼそのままの形でレポートに出る。


Specs2 のレポートレイアウトのデフォルトでは次のルールに従っている。

  • Text の次の Example はインデントされる。
  • Example がつながっているときは同じインデントレベル
  • Example の次に Text が来る場合、この Text は "subcontext" とみなされ、その次の例はもう一段インデントされる。
// コード1
"this is some presentation text"      ^                 // Text
  "and the first example"             ! success^        // Example
  "and the second example"            ! success         // Example
// コード1の出力結果
this is some presentation text
+ and the first example                     // Text の次の Example はインデントされる。
+ and the second example                    // Example がつながっているときは同じインデントレベル
// コード2
"this is some presentation text"      ^
  "and the first example"             ! success^
  "and the second example"            ! success^
  "and in this specific context"      ^                 
    "one more example"                ! success^
// コード2の出力結果
this is some presentation text
+ and the first example
+ and the second example
  and in this specific context                          // Example の次に Text => subcontext
  + one more example                                    // 次のExample はもう一段インデントされる。

The formatting fragments

インデントの調整。空行の追加などをするための fragment がいくつか用意されている。

fragment effect
br 空行を追加する。
t インデントレベルを1つ増やす(tab)。t(n)のように指定することもできる。
bt インデントレベルを1つ減らす(backtab)。bt(n)のように指定することもできる。
p 空行を追加する。インデントレベルを1つ減らす。br ^ bt
end インデントをリセットする
endbr end ^ br
endp end ^ p (endbr と全く同じ効果だけどこっちのほうが短い :-))

Turning-off the automatic layout

インデントを解除したいときは noindent という argument を先頭に付ける。

class MySpecWithNoIndent extends Specification {
  def is = noindent ^ ....
}