Skip to content

Instantly share code, notes, and snippets.

@heisters
Created April 23, 2009 21:19
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save heisters/100773 to your computer and use it in GitHub Desktop.
rspec I/O for a ruby script
require 'open3'
describe 'my_script' do
def run *args
options = args.extract_options!
args.unshift './my_script'
Open3.popen3(args.join(' ')) do |i, o, e|
i.write options[:stdin]
i.close
[o, e].map{|pipe|pipe.read.strip}
end
end
it "should echo STDIN" do
out, err = run :stdin => 'foo'
out.should == 'foo'
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment