In my previous post I mentioned an awesome gem for building CLI tools. A CLI
tool’s User Interface is through
stderr, but how do you test that
in RSpec? My initial thought was to capture
stdout/stderr by setting
$stderr to a
spy and inspecting the output.
Before I did that, I thought I’d do a quick search to see if the RSpec developers had already thought of this and provided matchers for this use case. Sure enough, RSpec includes an output matcher. Here’s a quick example what it might look like to use it.
Once again, with the magic of RSpec, my tests are cleaner and more English like. Thanks RSpec!