Implement extended doctests

This works. But I'm not entirely happy with this approach.

I had to split the logic of `test_content` into two cases: when there is an exception and when there is none. The reason for this is that we need different `rescue` clauses for those cases.

Please take a look @josevalim, @yrashk.