From: Jean-Hugues ROBERT Date: 2004-05-29T21:22:51+09:00 Subject: Re: Test::Unit: assert_follows_spec() (or something like that) At 20:38 29/05/2004 +0900, Florian wrote: >>JeanHuguesRobert: 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*!" > def word_boundary(.... >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!\"">. > >Regards, >Florian Gross This is definitely nice to me. Additionaly I don't like so much the idea of large distance between the code and the test code. But in your scheme a least part of the test code is close, right before the tested code, that's good I think. "xxx # => something" is apparently a well accepted convention to describe the expected result of some code. I guess that some "standard" is needed to fully describe the expected result beyond simple cases. I suspect that the error msg could be improved slightly, you most probably want to know the exact file/lineno where the assert failed. This may require some changes in test/unit that you probably will propose once your code is complete. Keep me posted. Yours, Jean-Hugues Robert ------------------------------------------------------------------------- Web: http://hdl.handle.net/1030.37/1.1 Phone: +33 (0) 4 92 27 74 17