xmpfilter.rbが便利すぎる件について
RAAをRSSでぼんやり眺めていたらxmpfilterなんてのが。
xmpfilter.rb is a small tool that can be used to
- generate Test::Unit assertions and RSpec expectations semi-automatically
- annotate source code with intermediate results (a bit like irb —simple-prompt but only for the lines explicitly marked with # =>) Very useful for example code (such as postings to ruby-talk).
例えば、
class TestComplexClass < Test::Unit::TestCase def setup @o = ComplexClass.new("foo", false) end def test_insertion @o.insert "bar" @o.insert "baz" @o.size # => @o.last # => @o.first # => @o.complex_computation # => @o.last(2) # => end end
こんな感じでテストを書いておいて、vimで%!xmpfilter.rb -uとするとあらびっくり!
def test_insertion @o.insert "bar" @o.insert "baz" assert_equal(2, @o.size) assert_equal("baz", @o.last) assert_equal("bar", @o.first) assert_in_delta(3.14159265358979, @o.complex_computation, 0.0001) assert_equal(["baz", "bar"], @o.last(2)) end
# =>をつけておいた行がassertionになってくれます。
これでassertionを書くのが面倒だった(のでろくに実践していない)TDDが超楽ちんになりそうな予感!