summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorHo-Sheng Hsiao <hosheng.hsiao@gmail.com>2012-03-26 14:25:04 -0400
committerHo-Sheng Hsiao <hosheng.hsiao@gmail.com>2012-03-26 14:25:10 -0400
commit96b71e70ae1f528b2ec2d81f4aa3bdccfe811c25 (patch)
tree26df70d78f294e33b14144429a4707012648d1e3 /spec
parent1e4f0c0b2f18dd062ee0e81277dae142bbd515e4 (diff)
downloadmixlib-shellout-96b71e70ae1f528b2ec2d81f4aa3bdccfe811c25.tar.gz
[CHEF-2994][RSPEC] ShellOut should be able to handle commands with stdin file pipes
Diffstat (limited to 'spec')
-rw-r--r--spec/mixlib/shellout/shellout_spec.rb23
1 files changed, 22 insertions, 1 deletions
diff --git a/spec/mixlib/shellout/shellout_spec.rb b/spec/mixlib/shellout/shellout_spec.rb
index 0f08c62..175d0e2 100644
--- a/spec/mixlib/shellout/shellout_spec.rb
+++ b/spec/mixlib/shellout/shellout_spec.rb
@@ -427,7 +427,7 @@ describe Mixlib::ShellOut do
end
end
- context 'with file pipes' do
+ context 'with stdout and stderr file pipes' do
let(:code) { "STDOUT.sync = true; STDERR.sync = true; print true; STDERR.print false" }
let(:cmd) { ruby_eval.call(code) + " > #{dump_file}" }
@@ -444,6 +444,27 @@ describe Mixlib::ShellOut do
end
end
+ context 'with stdin file pipe' do
+ let(:code) { "STDIN.sync = true; STDOUT.sync = true; STDERR.sync = true; print gets; STDERR.print false" }
+ let(:cmd) { ruby_eval.call(code) + " < #{dump_file_path}" }
+ let(:file_content) { "Random content #{rand(100000)}" }
+
+ let(:dump_file_path) { dump_file.path }
+ let(:dump_file) { open_file.tap(&write_file).tap(&:close) }
+ let(:file_name) { "#{dir}/input" }
+
+ let(:open_file) { File.open(file_name, 'w') }
+ let(:write_file) { lambda { |f| f.write(file_content) } }
+
+ it 'should execute' do
+ stdout.should eql(file_content)
+ end
+
+ it 'should handle stderr' do
+ stderr.should eql('false')
+ end
+ end
+
context 'with stdout and stderr file pipes' do
let(:code) { "STDOUT.sync = true; STDERR.sync = true; print true; STDERR.print false" }
let(:cmd) { ruby_eval.call(code) + " > #{dump_file} 2>&1" }