public
Last active

rspec I/O for a ruby script

  • Download Gist
script_spec.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
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

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.