Skip to content

Capture STDOUT/STDERR output written in block of Ruby code

Notifications You must be signed in to change notification settings

beccasaurus/capture

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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!

About

Capture STDOUT/STDERR output written in block of Ruby code

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages