diff --git a/lib/aruba/processes/basic_process.rb b/lib/aruba/processes/basic_process.rb index 44bc07ca4..b577d6466 100644 --- a/lib/aruba/processes/basic_process.rb +++ b/lib/aruba/processes/basic_process.rb @@ -115,16 +115,13 @@ def before_run; end def after_run; end def inspect - out = stdout(:wait_for_io => 0) + stderr(:wait_for_io => 0) + out = truncate("#{stdout(:wait_for_io => 0).inspect}", 35) + err = truncate("#{stderr(:wait_for_io => 0).inspect}", 35) - out = if out.length > 76 - out[0, 75] + ' ...' - else - out - end - - format '#<%s:%s commandline="%s": output="%s">', self.class, self.object_id, commandline, out + fmt = '#<%s:%s commandline="%s": stdout=%s stderr=%s>' + format fmt, self.class, self.object_id, commandline, out, err end + alias to_s inspect private @@ -138,6 +135,11 @@ def arguments [] end + + def truncate(string, max_length) + return string if string.length <= max_length + string[0, max_length - 1] + ' ...' + end end end end diff --git a/spec/aruba/processes/basic_process_spec.rb b/spec/aruba/processes/basic_process_spec.rb new file mode 100644 index 000000000..921b2b443 --- /dev/null +++ b/spec/aruba/processes/basic_process_spec.rb @@ -0,0 +1,64 @@ +require 'aruba/processes/basic_process' + +RSpec.describe Aruba::Processes::BasicProcess do + let(:cmd) { 'foobar' } + let(:exit_timeout) { 0 } + let(:io_wait_timeout) { 0 } + let(:working_directory) { Dir.pwd } + let(:stdout) { "foo output" } + let(:stderr) { "foo error output" } + + subject do + Class.new(described_class) do + def initialize(*args) + @stdout = args.shift + @stderr= args.shift + super(*args) + end + + def stdout(*args) + @stdout + end + + def stderr(*args) + @stderr + end + + end.new(stdout, stderr, cmd, exit_timeout, io_wait_timeout, working_directory) + end + + describe "#inspect" do + it "it shows useful info" do + expected = /#<#:\d+ commandline="foobar": stdout="foo output" stderr="foo error output"/ + expect(subject.inspect).to match(expected) + end + + context "with no stdout" do + let(:stdout) { nil } + + it "it shows useful info" do + expected = /#<#:\d+ commandline="foobar": stdout=nil stderr="foo error output"/ + expect(subject.inspect).to match(expected) + end + end + + context "with no stderr" do + let(:stderr) { nil } + + it "it shows useful info" do + expected = /#<#:\d+ commandline="foobar": stdout="foo output" stderr=nil/ + expect(subject.inspect).to match(expected) + end + end + + context "with neither stderr nor stdout" do + let(:stderr) { nil } + let(:stdout) { nil } + + it "it shows useful info" do + expected = /#<#:\d+ commandline="foobar": stdout=nil stderr=nil/ + expect(subject.inspect).to match(expected) + end + end + end +end