Skip to content

Commit

Permalink
Merge pull request #594 from grosser/grosser/fake
Browse files Browse the repository at this point in the history
make FakeKernel#exit behave like real Kernel#exit
  • Loading branch information
olleolleolle authored Feb 17, 2019
2 parents 8c14082 + 1df1a2f commit f198b36
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
8 changes: 7 additions & 1 deletion lib/aruba/processes/in_process.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
32 changes: 31 additions & 1 deletion 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 Down Expand Up @@ -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

0 comments on commit f198b36

Please sign in to comment.