Skip to content

Commit

Permalink
Make CommandMonitor output collection methods work with frozen string…
Browse files Browse the repository at this point in the history
… literals
  • Loading branch information
mvz committed May 31, 2024
1 parent afa64b2 commit 40dd972
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 5 deletions.
4 changes: 2 additions & 2 deletions lib/aruba/command_monitor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
37 changes: 34 additions & 3 deletions spec/aruba/command_monitor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 40dd972

Please sign in to comment.