Rails + Cucumber で Culerity を使うと、
以下のような WARNING が大量に発生する。
これでは、いくらテストがgreenでも精神はredになってしまう。
1 % cucumber features/foo.feature
2 Using the default profile...
3 2010/01/20 18:43:57 com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl notify
4 警告: Obsolete content type encountered: 'text/javascript'.
5 2010/01/20 18:43:58 com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl notify
6 警告: Expected content type of 'application/javascript' or 'application/ecmascript' for remotely loaded JavaScript element at 'http://z-ecx.images-amazon.com/images/G/01/nav2/gamma/amazonJQ/amazonJQ-combined-core-5113._V228305908_.js', but got 'application/x-javascript'.
7 (...)
8 .
9
10 1 scenario (1 passed)
11 1 step (1 passed)
この警告メッセージは、 HtmlUnit が吐いているものであるが、
Culerity::RemoteBrowserProxy のオプション(log_level)
で制御することができる。
具体的には、
"script/generate culerity" を利用した場合、
以下の step ファイル内で定義されている。
1 % vi features/step_definitions/culerity_steps.rb
2 - $browser.log_level = :warning
3 + $browser.log_level = :severe
(celerity の default は :off だが、culerity が :warning にしている)
上記の修正によって、WARNING の表示が抑制される。
1 % cucumber features/foo.feature
2 Using the default profile...
3 .
4
5 1 scenario (1 passed)
6 1 step (1 passed)
新規プロジェクトの度に毎回変更するのが面倒であれば、
generator の template を直接変更するのもいいかもしれない。
1 % vi $GEM_PATH/gems/culerity-0.2.7/rails_generators/culerity/templates/features/step_definitions/culerity_steps.rb
指定可能な log_level は、
(高) :all, :severe, :warning, :info, :config, :fine, :finer, :finest, :off (低)
であり、実際に以下のコードで確認することができる。(JRuby)
1 % irb
2 irb(main):001:0> java.util.logging.Level.constants
3 => ["FINE", "CONFIG", "FINEST", "FINER", "WARNING", "SEVERE", "OFF", "INFO", "ALL"]
log level に関するさらなる詳細は java.util.logging.Level を参照のこと。
http://java.sun.com/j2se/1.5.0/ja/docs/ja/api/java/util/logging/Level.html