Read my book

I wrote books about Webpack and React. Check them out!

Sunday, March 14, 2010

Speccer - Early prototype of a specification based test runner

I came upon this post by Steven Kryskalla today. From my perspective it managed to solve one major problem, the inadequate output of assert! I know Expecter gadget can do it but still his approach seemed like a cool one. I was also inspired by the way he specified tests. Instead of doing the regular "test_" mambo, he just dropped that notion and moved into more BDD'ish direction with his naming scheme.

I decided to take the idea a little bit further. What if specifications were defined in less technical way? Enter YAML. Here's my version of the specification mentioned on his blog:



Note how simple the specification is now. I bolstered the implementation with set_up to get rid of some redundancy. There is probably some work still left in semantics but to me that strikes as something more readable than regular tests with asserts etc.

Here's my initial, extremely hacky implementation of a test runner:



And here's an implementation of the specification:



The runner is extremely limited and is pretty much guaranteed to work properly in this case only. It would be somewhat interesting to extend the idea further to work with system tests ie.