diff --git a/lib/aruba/command_monitor.rb b/lib/aruba/command_monitor.rb index 79208398..2ac19e5a 100644 --- a/lib/aruba/command_monitor.rb +++ b/lib/aruba/command_monitor.rb @@ -98,7 +98,7 @@ def clear def all_stdout registered_commands.each(&:stop) - registered_commands.each_with_object("") { |e, a| a << e.stdout } + registered_commands.map(&:stdout).join end # Get stderr of all commands @@ -108,7 +108,7 @@ def all_stdout def all_stderr registered_commands.each(&:stop) - registered_commands.each_with_object("") { |e, a| a << e.stderr } + registered_commands.map(&:stderr).join end # Get stderr and stdout of all commands diff --git a/spec/aruba/command_monitor_spec.rb b/spec/aruba/command_monitor_spec.rb index fc338b6c..ffd91f0d 100644 --- a/spec/aruba/command_monitor_spec.rb +++ b/spec/aruba/command_monitor_spec.rb @@ -5,19 +5,50 @@ RSpec.describe Aruba::CommandMonitor do let(:monitor) { described_class.new(announcer: announcer) } let(:announcer) { instance_double(Aruba::Platforms::Announcer) } - let(:process) { instance_double(Aruba::Processes::BasicProcess, commandline: "foobar") } + let(:foo_process) do + instance_double(Aruba::Processes::InProcess, commandline: "foo", + stop: nil, + stdout: "foo_stdout\n", + stderr: "foo_stderr\n") + end + let(:bar_process) do + instance_double(Aruba::Processes::InProcess, commandline: "bar", + stop: nil, + stdout: "bar_stdout\n", + stderr: "bar_stderr\n") + end before do - monitor.register_command(process) + monitor.register_command(foo_process) + monitor.register_command(bar_process) end describe "#find" do it "find the process with the given name" do - expect(monitor.find("foobar")).to eq process + expect(monitor.find("foo")).to eq foo_process end it "fails if no process with the given name exists" do expect { monitor.find("boofar") }.to raise_error Aruba::CommandNotFoundError end end + + describe "#all_stdout" do + it "combines stdout from all registered processs" do + expect(monitor.all_stdout).to eq "foo_stdout\nbar_stdout\n" + end + end + + describe "#all_stderr" do + it "combines stderr from all registered processs" do + expect(monitor.all_stderr).to eq "foo_stderr\nbar_stderr\n" + end + end + + describe "#all_output" do + it "combines stdout and stderr from all registered processs" do + expect(monitor.all_output) + .to eq "foo_stdout\nbar_stdout\nfoo_stderr\nbar_stderr\n" + end + end end