Skip to content

Commit

Permalink
make FakeKernel#exit behave like real Kernel#exit
Browse files Browse the repository at this point in the history
  • Loading branch information
grosser committed Feb 14, 2019
1 parent 688ad05 commit 3b5602c
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 4 deletions.
7 changes: 6 additions & 1 deletion lib/aruba/processes/in_process.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,12 @@ def initialize
end

def exit(exitstatus)
@exitstatus = exitstatus
@exitstatus =
case exitstatus
when Numeric then Integer(exitstatus)
when TrueClass, FalseClass then exitstatus ? 0 : 1
else raise TypeError, "no implicit conversion of #{exitstatus.class} into Integer"
end
end
end

Expand Down
35 changes: 32 additions & 3 deletions spec/aruba/processes/in_process_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -28,11 +29,13 @@ def execute!
end
end

subject(:process) do
def build_process(main_class)
described_class.new(command, exit_timeout, io_wait, working_directory,
environment, main_class)
environment, main_class)
end

subject(:process) { build_process(main_class) }

let(:command) { 'foo' }
let(:exit_timeout) { 1 }
let(:io_wait) { 1 }
Expand Down Expand Up @@ -103,4 +106,30 @@ def execute!
it { expect { process.start }.to raise_error RuntimeError, 'Oops' }
end
end

describe "#exit_status" do
def run_process(&block)
process = build_process Class.new(Runner) { define_method(:execute!, &block) }
process.start
process.stop
process.exit_status
end

it "exists success" do
expect(run_process{ }).to eq 0
end

it "exists with given status" do
expect(run_process { @kernel.exit 12 }).to eq 12
end

it "exists with boolean" do
expect(run_process { @kernel.exit false }).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

0 comments on commit 3b5602c

Please sign in to comment.