diff options
author | Ho-Sheng Hsiao <hosheng.hsiao@gmail.com> | 2012-03-23 16:00:09 -0400 |
---|---|---|
committer | Ho-Sheng Hsiao <hosheng.hsiao@gmail.com> | 2012-03-23 16:00:09 -0400 |
commit | 274dee188ba467c5876796ff12ac82821c9bd2e3 (patch) | |
tree | 11d846da37124917157f0c3c94504267b7401f07 /spec | |
parent | fe51d5cad3eb6421b9d645a78afb6f53a03b3cd6 (diff) | |
download | mixlib-shellout-274dee188ba467c5876796ff12ac82821c9bd2e3.tar.gz |
[RSPEC] Refactored spec for dumping lots of data through STDOUT and STDERR
Diffstat (limited to 'spec')
-rw-r--r-- | spec/mixlib/shellout/shellout_spec.rb | 31 |
1 files changed, 18 insertions, 13 deletions
diff --git a/spec/mixlib/shellout/shellout_spec.rb b/spec/mixlib/shellout/shellout_spec.rb index 4f587ad..690b6df 100644 --- a/spec/mixlib/shellout/shellout_spec.rb +++ b/spec/mixlib/shellout/shellout_spec.rb @@ -591,20 +591,25 @@ describe Mixlib::ShellOut do end end - it "does not deadlock when the subprocess writes lots of data to both stdout and stderr" do - chatty = %q{ruby -e "puts 'f' * 20_000;STDERR.puts 'u' * 20_000; puts 'f' * 20_000;STDERR.puts 'u' * 20_000"} - cmd = Mixlib::ShellOut.new(chatty) - cmd.run_command - cmd.stdout.should == ('f' * 20_000) + "#{LINE_ENDING}" + ('f' * 20_000) + "#{LINE_ENDING}" - cmd.stderr.should == ('u' * 20_000) + "#{LINE_ENDING}" + ('u' * 20_000) + "#{LINE_ENDING}" - end + context 'with subprocess writing lots of data to both stdout and stderr' do + let(:cmd) { ruby_eval.call(chatty) } + let(:expected_output_with) { lambda { |chr| (chr * 20_000) + "#{LINE_ENDING}" + (chr * 20_000) + "#{LINE_ENDING}" } } - it "does not deadlock when the subprocess writes lots of data to both stdout and stderr (part2)" do - chatty = %q{ruby -e "STDERR.puts 'u' * 20_000; puts 'f' * 20_000;STDERR.puts 'u' * 20_000; puts 'f' * 20_000"} - cmd = Mixlib::ShellOut.new(chatty) - cmd.run_command - cmd.stdout.should == ('f' * 20_000) + "#{LINE_ENDING}" + ('f' * 20_000) + "#{LINE_ENDING}" - cmd.stderr.should == ('u' * 20_000) + "#{LINE_ENDING}" + ('u' * 20_000) + "#{LINE_ENDING}" + context 'when writing to STDOUT first' do + let(:chatty) { %q{puts "f" * 20_000; STDERR.puts "u" * 20_000; puts "f" * 20_000; STDERR.puts "u" * 20_000} } + it "should not deadlock" do + stdout.should eql(expected_output_with.call('f')) + stderr.should eql(expected_output_with.call('u')) + end + end + + context 'when writing to STDERR first' do + let(:chatty) { %q{STDERR.puts "u" * 20_000; puts "f" * 20_000; STDERR.puts "u" * 20_000; puts "f" * 20_000} } + it "should not deadlock" do + stdout.should eql(expected_output_with.call('f')) + stderr.should eql(expected_output_with.call('u')) + end + end end it "doesn't hang or lose output when a process writes, pauses, then continues writing" do |