RSpec on Rails の色

WIndows(XP SP3) を使っている、「rake spec」で、デフォルトで FAIL(マゼンダ、紫) や ERROR(赤) に色が付く(gem list win32console => win32console (1.1.0))。それは良いんだけど、DOS窓の黒背景に赤文字は大変見辛い。何とかならいものだろうか。
DOS窓のプロパティで画面の色の背景を調整して見たりしたけど改善しない(背景色明るくしても、メッセージのところだけ黒背景赤文字に戻る)

RSpecに(反転させた)色を付ける - 角谷HTML化計画(2007-01-04)」「http://idm.s9.xrea.com/ratio/2007/01/02/000575.html」辺りを参考にする、しかし、少し時間が経ったせいかそのままでは動かない。

spec/spec_helper.rb

リンク先では何処かのファイルに書いておいて起動時 require するということだったけど、なんかそんな定数 Spec::Runner (クラス)無いと言われる。いいよ、spec/spec_helper.rb に書こう。

class WellLitProgressBarFormatter < Spec::Runner::Formatter::ProgressBarFormatter
  def red(text); colour(text, "\e[1;31m") end #31
  def magenta(text); colour(text, "\e[1;35m") end #35
end # class WellLitProgressBarFormatter < Spec::Runner::Formatter::ProgressBarFormatter

class InvertedProgressBarFormatter < Spec::Runner::Formatter::ProgressBarFormatter
  def red(text); colour(text, "\e[41m") end
  def magenta(text); colour(text, "\e[45m") end
end # class InvertedProgressBarFormatter < Spec::Runner::Formatter::ProgressBarFormatter

class InvertedWellLitProgressBarFormatter < Spec::Runner::Formatter::ProgressBarFormatter
  def red(text); colour(text, "\e[1;41m") end
  def magenta(text); colour(text, "\e[1;45m") end
end # class InvertedWellLitProgressBarFormatter < Spec::Runner::Formatter::ProgressBarFormatter

Spec::Runner.configureブロックの外に追記

配色は3パターン用意した。赤、紫を強調して少し明るくするもの(WellLit)、赤、紫は背景色にして白文字にするもの(Inverted)(角谷さん)、両方やって背景色と文字色のコントラストを若干強めた物(InvertedWellLit)

Pending には yellow()メソッドを、そして green()メソッドを再定義すればそれらの配色も変わる。

spec/spec.opts

リンク先では Rakeファイルで呼び出しを変更していたが、もう良いから spec/spec.opts を修正。
因みに Rakeファイルを使うなら ENV['RSPECOPTS'] は obsolute になっていて、ENV['SPEC_OPTS'] を使う事になるので注意。

--colour
--format InvertedWellLitProgressBarFormatter
--loadby mtime
--reverse

クラス名指定 InvertedWellLitProgressBarFormatter を差し替えれば配色変更可、デフォルトで入ってたのは「progress」

取敢えず InvertedWellLit の視認性が気に入っている。