Thanks Driven Life

日々是感謝

RSpec Turnip Formatter

Post in English here

Turnip 向けの RSpec Formatter です。

$ gem install turnip_formatter

もしくは

$ echo 'gem "turnip_formatter'" >> Gemfile
$ bundle install

からの

$ bundle exec rspec -r turnip_formatter --format RSpecTurnipFormatter --out report.html

report.html が作成されます。

Motivation

標準の formatter だとわかりづらいから。

(例) Turnip の examples を実行してみる

$ git clone git://github.com/jnicklas/turnip.git
$ cd turnip
$ bundle install --path vendor/bundle
$ buddle exec rspec examples -f html -o test.html -f documentation -o test.txt

まずは Documentation Format

$ less test.txt
(skip..)

Steps for a feature
  Evil
    the monster has an alignment -> that alignment should be "Evil"
  Neutral
    the monster has an alignment -> that alignment should be "Neutral"

Red Dragons are deadly

    there is a dragon -> there is a knight -> the dragon attacks the knight -> the knight is alive

    there is a dragon -> the dragon breathes fire -> there is a knight -> the dragon attacks the knight -> the knight is dead

各ステップが -> で繋げられて表示されるため、視線を横移動しないといけないのでつらい。 または以下のシーン

  3) raises errors Incorrect expectation there is a monster -> it should die
     Failure/Error: Then it should die

       expected: 0
            got: 1

       (compared using ==)
     # examples/steps/steps.rb:14:in `block in <top (required)>'
     # ./lib/turnip/execute.rb:20:in `step'
     # ./lib/turnip/rspec.rb:44:in `run_step'
     # ./lib/turnip/rspec.rb:70:in `block (6 levels) in run'
     # ./lib/turnip/rspec.rb:69:in `each'
     # ./lib/turnip/rspec.rb:69:in `block (5 levels) in run'
     # ./examples/errors.feature:8:in `it should die'

どのステップで失敗したか一目でわからない。backtrace で判断するしかない。

続いて HTML Format

$ open test.html

f:id:gongoZ:20130418195441p:plain

step のソースコードが見えるのは良いが

  • どのステップでこのメソッドが呼ばれて失敗したのか

というのがわからない。あと Pending 、もはやわからない。

Result

$ echo 'gem "turnip_formatter"' >> Gemfile
$ bundle install
$ bundle exec rspec examples -r turnip_formatter -f RSpecTurnipFormatter -o report.html
$ open report.html

f:id:gongoZ:20130418195458p:plain

わかりやすい!!

f:id:gongoZ:20130418195501p:plain

すごくわかりやすい!!!

デモ的な feature を ここに おいてますのでどうぞ。

Epilogue

Jenkins 氏でこのレポートを保存するようにしたので、とてもいい感じに。 「あの、このシナリオ失敗してるんだけど?」って IRC に貼りやすくなりましたね。