Capture STDOUT/STDERR output written in block of Ruby code
Ruby
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
lib
spec
.gitignore
README.rdoc
Rakefile
VERSION.yml
io-capture.gemspec

README.rdoc

capture

A simple gem for easily capturing writes to STDOUT & STDERR

I needed to write this for testing calls to #puts in an app and it took me awhile to get the code working properly (especially without having to write to the filesystem to get the output properly).

I figured that I might need this again or someone else might find this handy so … here it is!

Install

$ gem sources -a http://gems.github.com
$ sudo gem install remi-capture

Usage

>> Capture { puts 'hello' }
=> 'hello'

>> Capture(:stdout){ puts 'hello stdout' }
=> 'hello stdout'

>> Capture(:stderr){ warn 'hello stderr' }
=> 'hello stderr'

That's it! Like I said, super simple.

Notes

If I get bored, I'd like to update this to be able to capture writes to any IO object. That could be super useful!