diff options
author | Max Lincoln <max@devopsy.com> | 2014-07-09 16:05:17 -0400 |
---|---|---|
committer | Max Lincoln <max@devopsy.com> | 2014-07-17 13:01:04 -0400 |
commit | 5ce6ead83be1a46241db53e401f44c9a40f598ce (patch) | |
tree | de80864f2c23906496195ed55ad98e420d4ae558 /spec/mixlib/shellout_spec.rb | |
parent | b5e27147f0a5f0ccf44ff4968be2bdfb0c2ce35d (diff) | |
download | mixlib-shellout-5ce6ead83be1a46241db53e401f44c9a40f598ce.tar.gz |
Support separate live stream for stderr
Diffstat (limited to 'spec/mixlib/shellout_spec.rb')
-rw-r--r-- | spec/mixlib/shellout_spec.rb | 82 |
1 files changed, 78 insertions, 4 deletions
diff --git a/spec/mixlib/shellout_spec.rb b/spec/mixlib/shellout_spec.rb index 5dcb6a7..72d550e 100644 --- a/spec/mixlib/shellout_spec.rb +++ b/spec/mixlib/shellout_spec.rb @@ -187,8 +187,56 @@ describe Mixlib::ShellOut do let(:value) { stream } let(:stream) { StringIO.new } + before(:each) do + shell_cmd.live_stream = stream + end + it "should set the live stream" do - should eql(value) + shell_cmd.live_stream.should eql(stream) + end + + it "should set the live stderr stream" do + shell_cmd.live_stderr_stream.should eql(stream) + end + end + + context 'when setting a live stream and live stderr stream separately' do + let(:accessor) { :live_stream } + let(:stream) { StringIO.new } + let(:value) { stream } + let(:stdout_stream) { StringIO.new } + let(:stderr_stream) { StringIO.new } + + before(:each) do + shell_cmd.live_stream = stdout_stream + shell_cmd.live_stderr_stream = stderr_stream + end + + it "should set the live stream" do + shell_cmd.live_stream.should eql(stdout_stream) + end + + it "should set the live stream" do + shell_cmd.live_stderr_stream.should eql(stderr_stream) + end + end + + context 'when setting a live stream and explicitly disabling live stderr stream' do + let(:accessor) { :live_stream } + let(:value) { stream } + let(:stream) { StringIO.new } + + before(:each) do + shell_cmd.live_stream = stream + shell_cmd.live_stderr_stream = nil + end + + it "should set the live stream" do + shell_cmd.live_stream.should eql(stream) + end + + it "should set the live stderr stream" do + shell_cmd.live_stderr_stream.should eql(nil) end end @@ -457,9 +505,35 @@ describe Mixlib::ShellOut do stream.string.should include("hello#{LINE_ENDING}") end - it "should copy the child's stderr to the live stream" do - shell_cmd.run_command - stream.string.should include("world#{LINE_ENDING}") + context "with default stderr stream" do + it "should copy the child's stderr to the live stream" do + shell_cmd.run_command + stream.string.should include("world#{LINE_ENDING}") + end + end + + context "without an stderr stream" do + it "should not copy the child's stderr to the live stream" do + shell_cmd.live_stderr_stream = nil + shell_cmd.run_command + stream.string.should_not include("world#{LINE_ENDING}") + end + end + + context "with a separate stderr stream" do + let(:stderr_stream) { StringIO.new } + + it "should not copy the child's stderr to the live stream" do + shell_cmd.live_stderr_stream = stderr_stream + shell_cmd.run_command + stream.string.should_not include("world#{LINE_ENDING}") + end + + it "should copy the child's stderr to the live stderr stream" do + shell_cmd.live_stderr_stream = stderr_stream + shell_cmd.run_command + stderr_stream.string.should include("world#{LINE_ENDING}") + end end end |