From 1df1a2f39c94846f684cadd04be1858c8f1b4aba Mon Sep 17 00:00:00 2001 From: Michael Grosser Date: Thu, 14 Feb 2019 13:26:29 -0800 Subject: [PATCH] make FakeKernel#exit behave like real Kernel#exit --- lib/aruba/processes/in_process.rb | 8 ++++++- spec/aruba/processes/in_process_spec.rb | 32 ++++++++++++++++++++++++- 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/lib/aruba/processes/in_process.rb b/lib/aruba/processes/in_process.rb index 4c578ccb5..7e1e9684c 100644 --- a/lib/aruba/processes/in_process.rb +++ b/lib/aruba/processes/in_process.rb @@ -33,7 +33,13 @@ def initialize end def exit(exitstatus) - @exitstatus = exitstatus + @exitstatus = + case exitstatus + when Numeric then Integer(exitstatus) + when TrueClass then 0 + when FalseClass then 1 + else raise TypeError, "no implicit conversion of #{exitstatus.class} into Integer" + end end end diff --git a/spec/aruba/processes/in_process_spec.rb b/spec/aruba/processes/in_process_spec.rb index bc5faf9da..cd03db1a0 100644 --- a/spec/aruba/processes/in_process_spec.rb +++ b/spec/aruba/processes/in_process_spec.rb @@ -2,9 +2,10 @@ RSpec.describe Aruba::Processes::InProcess do class Runner - def initialize(_argv, _stdin, stdout, stderr, _kernel) + def initialize(_argv, _stdin, stdout, stderr, kernel) @stdout = stdout @stderr = stderr + @kernel = kernel end def execute!; end @@ -103,4 +104,33 @@ def execute! it { expect { process.start }.to raise_error RuntimeError, 'Oops' } end end + + describe "#exit_status" do + def run_process(&block) + process = described_class.new( + command, exit_timeout, io_wait, working_directory, + environment, Class.new(Runner) { define_method(:execute!, &block) } + ) + process.start + process.stop + process + end + + it "exits success" do + expect(run_process{ }.exit_status).to eq 0 + end + + it "exits with given status" do + expect(run_process { @kernel.exit 12 }.exit_status).to eq 12 + end + + it "exits with boolean" do + expect(run_process { @kernel.exit false }.exit_status).to eq 1 + end + + it "refuses to exit with anything else" do + expect { run_process { @kernel.exit "false" } } + .to raise_error(TypeError, "no implicit conversion of String into Integer") + end + end end