Skip to content

Instantly share code, notes, and snippets.

@samg
Forked from heisters/script_spec.rb
Created April 23, 2009 21:22
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samg/100774 to your computer and use it in GitHub Desktop.
Save samg/100774 to your computer and use it in GitHub Desktop.
require 'open3'
describe 'my_script' do
def run *args
options = args.extract_options!
args.unshift './my_script'
out = err = ''
Open3.popen3(args.join(' ')) do |i, o, e|
i.write options[:stdin]
i.close
out, err = *[o, e].map(&:read)
end
[out, err].map(&:strip)
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