If you write console based applications in ruby, chances are you’re going to want to get some test coverage on that eventually.
StringIO is a great class to use when you want to assert that your application outputs the correct stuff to the screen.
We can modify the global variable
$stdout to be an instance of
StringIO for the duration of our tests. Any method that outputs text on
Not a bad bit of TDD if I don’t say so!
Similar tricks could be used with
$stdin to get solid end-to-end test coverage on a wide variety of console-based applications.