Hello,

At 22:04 20/05/2002 +0900, you wrote:
>Tobias Reif <tobiasreif / pinkjuice.com> writes:
>
> > So it could be a great opportunity for a documenting tool
> > like RDoc to browse tests and feature their information
> > as documentation near the documented methods.
>
>Actually, by an amazing coincidence... :)  That's something we've been
>talking about doing. There's a brief hold up while I struggle with a
>philosophical question.
>
>In (say) Java, people tend to keep the unit tests in separate files. I
>think this is for two reasons. First the tests add bulk to the class
>files. Second, the additional verbiage in Java means the tests obscure
>the meaning of the code.
>
>Neither of these apply to Ruby, and yet we still tend to put the unit
>tests in a separate file. So I'm wondering what happens it we break
>that tradition:
>
>
>    class Multiplier
>
>       test :numeric, "Test that numeric multiplication works" do
>         m = Multipler.new(3)
>         assert_equal(6, m.times(2))
>         assert_equal(-9, m.times(-3))
>       end
>
>       test :alpha, "Test other uses of the '*' method" do
>         m = Multiplier.new("hi")
>         assert_equal("hihi", m.times(2))
>         assert_equal("",     m.times(0))
>       end
>
>       def initialize(by)
>         @by = by
>       end
>
>       def times(n)
>         @by * n
>       end
>
>    end
>
>When run with ruby -rtest ..., the test cases get run. When rdoc'd,
>the test code gets extracted and used as class-level documentation.
>
>I'm still not sure about this - what do folks think?
>
>
>Dave

I like that. It fits well with the principle of locality ("things that
are semantically close should be physically close"). One drawback might
be that loading time&space gets increased. The latter is probably
avoidable if test() does nothing when user is not in "test" mode.

BTW: Separating tests from implementation is good too, when tests are
written by somebody else for example. However, whatever will make it
easier to have more tests, is good. And for sure it is easier when
you're dealing with a single file (versus one for code & one for tests).
When/if file becomes too big/unmanageable, you can split (incremental
style). Often, your are not going to need it.

Yours,

Jean-Hugues