RubyFlow The Ruby and Rails community linklog

inline_testing

I’ve released inline_testing, a gem which does just that. Be sure to check out this article explaining what it is and how it works and you can see the Gem or the GitHub repo.

Comments

Interesting gem. I did something similar about a year back. I have used inline testing in several projects and a few gems. I went a slightly different route (I used a block to indicate where testing starts and stopped and used traditional Test::Unit to carry out the assertions) but same basic idea.

After using inline testing for a while I find good and bad things. The good is that my testing is more consistently done, kept up-to-date more often and easier to do (just add a Test block). The bad is that like rdoc sometimes the test can get in the way of seeing the actual code. I think using an editor that supports code folding might help with this some but even without code folding my experience seems to indicate that the good outweighs the bad.

https://github.com/eric1234/test_inline/wiki

I’ve done inline testing since about 2003/2004. When I started, I did it by adding test comment blocks, eg.

  =begin test/unit
    ... test code here...
  =end

Then I used a simple tool to extract out the blocks and run the tests. It worked well, and that is how Ruby Facets did it’s testing for a long time. However, I found it very limited in the face of complex fixtures or tests that hit the file system, so I moved away from it.

Later I developed a new documentation oriented testing framework called QED. It’s something of a cross between Cucumber and a traditional test framework. It turned out to be very easy to support inline testing with QED so I added that feature a few versions back. It simply runs all comments through QED as they are. To circumvent QED just double hash a comment (e.g. ## QED ignores this). Now Ruby Facets actually has two sets of tests. The usual kind, and all the comments too!

Post a comment

You can use basic HTML markup (e.g. <a>) or Markdown.

As you are not logged in, you will be
directed via GitHub to signup or sign in