Add SystemCommand::Result#merged_output.

This commit is contained in:
Markus Reiter 2018-09-19 03:09:07 +02:00
parent f1a2fa5601
commit 91b0794329
2 changed files with 37 additions and 17 deletions

View File

@ -185,6 +185,11 @@ class SystemCommand
.join
end
def merged_output
@merged_output ||= @output.map { |_, line| line }
.join
end
def success?
@exit_status.zero?
end

View File

@ -1,32 +1,47 @@
require "system_command"
describe SystemCommand::Result do
describe "#to_ary" do
let(:output) {
[
[:stdout, "output"],
[:stderr, "error"],
]
}
subject(:result) {
described_class.new([], output, instance_double(Process::Status, exitstatus: 0, success?: true))
}
let(:output_array) {
[
[:stdout, "output\n"],
[:stderr, "error\n"],
]
}
subject(:result) {
described_class.new([], output_array, instance_double(Process::Status, exitstatus: 0, success?: true))
}
describe "#to_ary" do
it "can be destructed like `Open3.capture3`" do
out, err, status = result
expect(out).to eq "output"
expect(err).to eq "error"
expect(out).to eq "output\n"
expect(err).to eq "error\n"
expect(status).to be_a_success
end
end
describe "#plist" do
subject {
described_class.new(command, [[:stdout, stdout]], instance_double(Process::Status, exitstatus: 0)).plist
}
describe "#stdout" do
it "returns the standard output" do
expect(result.stdout).to eq "output\n"
end
end
let(:command) { ["true"] }
describe "#stderr" do
it "returns the standard error output" do
expect(result.stderr).to eq "error\n"
end
end
describe "#merged_output" do
it "returns the combined standard and standard error output" do
expect(result.merged_output).to eq "output\nerror\n"
end
end
describe "#plist" do
subject { result.plist }
let(:output_array) { [[:stdout, stdout]] }
let(:garbage) {
<<~EOS
Hello there! I am in no way XML am I?!?!