Specs2を試す(9)

参考: http://etorreborre.github.com/specs2/guide/org.specs2.guide.SpecStructure.html#Shared+examples

Declare arguments

specの最初にarg(ほにゃらら=true)をくっつけることで、specの実行やレポートの挙動を返ることができる。

コード1 は args(sequential=true) を付けて、spec が並行に実行されるのを防いでいる。*1

// コード1
   class ExamplesOneByOne extends Specification { def is =

     args(sequential=true)              ^
     "first example"                    ! e1 ^
     "the the second one"               ! e2 ^
                                        end
   }

この arg(名前付き引数) には対応するショートカットメソッドも用意されています。
コード1はコード2 のようにも書けます。

// コード2
   class ExamplesOneByOne extends Specification { def is =

     sequential                              ^
     "first example"                    ! e1 ^
     "the the second one"               ! e2 ^
                                        end
   }


そのほかにもいろいろあるのでここ見ればよろし。
http://etorreborre.github.com/specs2/guide/org.specs2.guide.Runners.html#Shortcuts
ソースだとこれか。
https://github.com/etorreborre/specs2/blob/1.6/src/main/scala/org/specs2/main/ArgumentsShortcuts.scala

fmfm...少し前 descFromExpectations というのが出てきたけど、あれは args.report(fromSource=false) で置き換えられるね。

*1:specs2 はデフォルトでは並行実行されます。一回ハマりました。