From: Florian Gross Date: 2004-05-29T20:38:39+09:00 Subject: Re: Test::Unit: assert_follows_spec() (or something like that) Jean-Hugues ROBERT wrote: > Hi Moin. > About the generation of HTML documentation, I feel, again, that the > full spec is not easy to grab. I would rather like to see some RDoc > tool that would consider test cases as "examples". I'm currently embedding test cases into the documentation. They look a lot like example code. I think this is commonly called "Specification by example". I've written a tool for automatically extracting and running them. Here is an example: # Matches the space between words. # This is a zero-width anchor. # # re = Regexp::English.word_boundary # text = "Hello World!" # text.gsub(re, "*") # => "*Hello* *World*!" # # Matches the word "and", but not "band" # re2 = Regexp::English.new do # literal("and").surrounded_by(word_boundary) # end # "band".match(re2) # => nil # "and".match(re2)[0] # => "and" def word_boundary; Node::Anchor.new(/\b/); end If this test case where to fail you would get an useful error like this: > 1) Failure: > test_word_boundary() > [(eval):3:in `eval' > (eval):7:in `test_word_boundary' > (eval):3:in `test_word_boundary']: > c:/ruby/lib/ruby/1.8/test/unit/assertions.rb:32:in `assert_block'<"\"*Hello* *World*!\""> expected but was <"\"Hello World!\"">. > Yours, > JeanHuguesRobert Regards, Florian Gross