portable perspectives

a blog about programming, life, universe and everything

My Tiny DocTest for ruby

I believe that doctest for python is one of the best test libraries available, because it pushes the cost to develop functional tests to zero.

While I’m writing a dummy object persistence layer I thought it would have been nice to have something like that, basically seeking some kind of literate testing process.

This is the first attempt at it (warning dirty, slow, duplicated code).

It somehow works, can be run from rcov/rake/ruby, loaded with multiple files, and allows writing nice tests like this one . As you can see in the code, everything that does not look like irb code is ignored, which allows adding comments, leave python code mixed with ruby, write formulas and so on.

The lib is really half-backed, for example you canì’t use multiline declarations in irb or print something to screen, but I think it is a nice small thing.

You can find a different take on sample/doc testing in manveru’s repository

AddThis Social Bookmark Button

1 Response to “My Tiny DocTest for ruby”

  1. Jeko Says:
    Tu sei troppo avanti.

Sorry, comments are closed for this article.