summaryrefslogtreecommitdiff
path: root/spec/ruby/shared/process/exit.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/ruby/shared/process/exit.rb')
-rw-r--r--spec/ruby/shared/process/exit.rb38
1 files changed, 35 insertions, 3 deletions
diff --git a/spec/ruby/shared/process/exit.rb b/spec/ruby/shared/process/exit.rb
index 1820dd17fd..1e073614a3 100644
--- a/spec/ruby/shared/process/exit.rb
+++ b/spec/ruby/shared/process/exit.rb
@@ -21,6 +21,12 @@ describe :process_exit, shared: true do
end
end
+ it "raises a SystemExit with message 'exit'" do
+ -> { @object.exit }.should raise_error(SystemExit) { |e|
+ e.message.should == "exit"
+ }
+ end
+
it "tries to convert the passed argument to an Integer using #to_int" do
obj = mock('5')
obj.should_receive(:to_int).and_return(5)
@@ -75,20 +81,46 @@ end
describe :process_exit!, shared: true do
it "exits with the given status" do
- out = ruby_exe("#{@object}.send(:exit!, 21)", args: '2>&1')
+ out = ruby_exe("#{@object}.send(:exit!, 21)", args: '2>&1', exit_status: 21)
out.should == ""
$?.exitstatus.should == 21
end
it "exits when called from a thread" do
- out = ruby_exe("Thread.new { #{@object}.send(:exit!, 21) }.join; sleep", args: '2>&1')
+ out = ruby_exe("Thread.new { #{@object}.send(:exit!, 21) }.join; sleep", args: '2>&1', exit_status: 21)
out.should == ""
$?.exitstatus.should == 21
end
it "exits when called from a fiber" do
- out = ruby_exe("Fiber.new { #{@object}.send(:exit!, 21) }.resume", args: '2>&1')
+ out = ruby_exe("Fiber.new { #{@object}.send(:exit!, 21) }.resume", args: '2>&1', exit_status: 21)
+ out.should == ""
+ $?.exitstatus.should == 21
+ end
+
+ it "skips at_exit handlers" do
+ out = ruby_exe("at_exit { STDERR.puts 'at_exit' }; #{@object}.send(:exit!, 21)", args: '2>&1', exit_status: 21)
out.should == ""
$?.exitstatus.should == 21
end
+
+ it "skips ensure clauses" do
+ out = ruby_exe("begin; STDERR.puts 'before'; #{@object}.send(:exit!, 21); ensure; STDERR.puts 'ensure'; end", args: '2>&1', exit_status: 21)
+ out.should == "before\n"
+ $?.exitstatus.should == 21
+ end
+
+ it "overrides the original exception and exit status when called from #at_exit" do
+ code = <<-RUBY
+ at_exit do
+ STDERR.puts 'in at_exit'
+ STDERR.puts "$! is \#{$!.class}:\#{$!.message}"
+ #{@object}.send(:exit!, 21)
+ end
+ raise 'original error'
+ RUBY
+ out = ruby_exe(code, args: '2>&1', exit_status: 21)
+ out.should == "in at_exit\n$! is RuntimeError:original error\n"
+ $?.exitstatus.should == 21
+ end
end