diff options
author | Ho-Sheng Hsiao <hosheng.hsiao@gmail.com> | 2012-03-23 17:38:22 -0400 |
---|---|---|
committer | Ho-Sheng Hsiao <hosheng.hsiao@gmail.com> | 2012-03-23 17:38:22 -0400 |
commit | 253bd4435988e6b7618357daf71669f7c56f6ee0 (patch) | |
tree | 17a1c522e74591bd109f8b5c633da1bb416607ad /spec | |
parent | 96e487a60094b5a5be07dae7edff11a6e00df334 (diff) | |
download | mixlib-shellout-253bd4435988e6b7618357daf71669f7c56f6ee0.tar.gz |
[RSPEC] Refactored spec for #format_for_exception
Diffstat (limited to 'spec')
-rw-r--r-- | spec/mixlib/shellout/shellout_spec.rb | 29 |
1 files changed, 18 insertions, 11 deletions
diff --git a/spec/mixlib/shellout/shellout_spec.rb b/spec/mixlib/shellout/shellout_spec.rb index 19b6cb3..513b04d 100644 --- a/spec/mixlib/shellout/shellout_spec.rb +++ b/spec/mixlib/shellout/shellout_spec.rb @@ -655,6 +655,7 @@ describe Mixlib::ShellOut do should be_empty end 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}" } } @@ -716,19 +717,25 @@ describe Mixlib::ShellOut do end end end - end - end + describe "#format_for_exception" do + let(:ruby_code) { %q{STDERR.puts "msg_in_stderr"; puts "msg_in_stdout"} } + let(:cmd) { ruby_eval.call(ruby_code) } + let(:exception_output) { executed_cmd.format_for_exception.split("\n") } + let(:expected_output) { [ + %q{---- Begin output of ruby -e 'STDERR.puts "msg_in_stderr"; puts "msg_in_stdout"' ----}, + %q{STDOUT: msg_in_stdout}, + %q{STDERR: msg_in_stderr}, + %q{---- End output of ruby -e 'STDERR.puts "msg_in_stderr"; puts "msg_in_stdout"' ----}, + "Ran ruby -e 'STDERR.puts \"msg_in_stderr\"; puts \"msg_in_stdout\"' returned 0" + ] } - it "formats itself for exception messages" do - cmd = Mixlib::ShellOut.new %q{ruby -e 'STDERR.puts "msg_in_stderr"; puts "msg_in_stdout"'} - cmd.run_command - cmd.format_for_exception.split("\n")[0].should == %q{---- Begin output of ruby -e 'STDERR.puts "msg_in_stderr"; puts "msg_in_stdout"' ----} - cmd.format_for_exception.split("\n")[1].should == %q{STDOUT: msg_in_stdout} - cmd.format_for_exception.split("\n")[2].should == %q{STDERR: msg_in_stderr} - cmd.format_for_exception.split("\n")[3].should == %q{---- End output of ruby -e 'STDERR.puts "msg_in_stderr"; puts "msg_in_stdout"' ----} + it "should format exception messages" do + exception_output.each_with_index do |output_line, i| + output_line.should eql(expected_output[i]) + end + end + end end - - end |