Specs2を試す(2)
Acceptance specification
Acceptance specification では、一つ一つの'frgment'を^でつなぎ、
'fragmentのリスト(flagments)'を作るという書き方をする。
例えば下の例は
- 1つのText fragment
- 2つのexample fragmentから成っている。
"this is my specification" ^ "and example 1" ! e1^ "and example 2" ! e2 def e1 = success def e2 = success
example fragmentは
"description" ! body という形をしている
// description body "and example 1" ! e1
bodyはResult型を返すメソッドであり、Textの部分とは分けて定義する。
bodyの命名の仕方について、ルールとかは特にないようだ。
e1, e2のように短い名前にしてもよいし、``で囲んで長い説明的な名前を付けるのもよい。
"this is my specification" ^ "and example 1" ! `first example`^ "and example 2" ! `second example` // ``で囲む def `first example` = success def `second example` = success
descriptionを省略した書き方もできる。
長い名前を付けてたらdescriptionの部分いらないもんね。
"this is my specification" ^ `and example 1` ^ `and example 2` def `and example 1` = success def `and example 2` = success