summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHo-Sheng Hsiao <hosheng.hsiao@gmail.com>2012-03-26 14:52:35 -0400
committerHo-Sheng Hsiao <hosheng.hsiao@gmail.com>2012-03-26 14:54:48 -0400
commit318c5572bc6cd1f3452760558bbb9da8b3b6dc9d (patch)
tree6915e8b3b6d5740f40215073f33d7bdc33b38ac0
parent724419d3d443ccf58075ef803b9aaf028ce2a4ee (diff)
downloadchef-318c5572bc6cd1f3452760558bbb9da8b3b6dc9d.tar.gz
[CHEF-2994][STDIN] ShellOut.new should accept input as an option
-rw-r--r--lib/mixlib/shellout.rb4
-rw-r--r--spec/mixlib/shellout/shellout_spec.rb9
2 files changed, 11 insertions, 2 deletions
diff --git a/lib/mixlib/shellout.rb b/lib/mixlib/shellout.rb
index 94ea6c9b29..2082f4165a 100644
--- a/lib/mixlib/shellout.rb
+++ b/lib/mixlib/shellout.rb
@@ -145,6 +145,7 @@ module Mixlib
def initialize(*command_args)
@stdout, @stderr = '', ''
@live_stream = nil
+ @input = nil
@log_level = :debug
@log_tag = nil
@environment = DEFAULT_ENVIRONMENT
@@ -255,6 +256,7 @@ module Mixlib
private
+ # FIXME: This can be done better
def parse_options(opts)
opts.each do |option, setting|
case option.to_s
@@ -272,6 +274,8 @@ module Mixlib
self.valid_exit_codes = Array(setting)
when 'live_stream'
self.live_stream = setting
+ when 'input'
+ self.input = setting
when 'logger'
self.logger = setting
when 'log_level'
diff --git a/spec/mixlib/shellout/shellout_spec.rb b/spec/mixlib/shellout/shellout_spec.rb
index baf06d1806..59afce0304 100644
--- a/spec/mixlib/shellout/shellout_spec.rb
+++ b/spec/mixlib/shellout/shellout_spec.rb
@@ -160,7 +160,6 @@ describe Mixlib::ShellOut do
context 'when setting an input' do
let(:accessor) { :input }
let(:value) { "Random content #{rand(1000000)}" }
- let(:stream) { StringIO.new }
it "should set the input" do
should eql(value)
@@ -171,7 +170,8 @@ describe Mixlib::ShellOut do
context "with options hash" do
let(:cmd) { 'brew install couchdb' }
let(:options) { { :cwd => cwd, :user => user, :group => group, :umask => umask,
- :timeout => timeout, :environment => environment, :returns => valid_exit_codes, :live_stream => stream } }
+ :timeout => timeout, :environment => environment, :returns => valid_exit_codes,
+ :live_stream => stream, :input => input } }
let(:cwd) { '/tmp' }
let(:user) { 'toor' }
@@ -181,6 +181,7 @@ describe Mixlib::ShellOut do
let(:environment) { { 'RUBY_OPTS' => '-w' } }
let(:valid_exit_codes) { [ 0, 1, 42 ] }
let(:stream) { StringIO.new }
+ let(:input) { 1.upto(10).map { "Data #{rand(100000)}" }.join("\n") }
it "should set the working directory" do
shell_cmd.cwd.should eql(cwd)
@@ -240,6 +241,10 @@ describe Mixlib::ShellOut do
shell_cmd.live_stream.should eql(stream)
end
+ it "should set the input" do
+ shell_cmd.input.should eql(input)
+ end
+
context 'with an invalid option' do
let(:options) { { :frab => :job } }
let(:invalid_option_exception) { Mixlib::ShellOut::InvalidCommandOption }