diff options
Diffstat (limited to 'spec/ruby/shared/process/exit.rb')
| -rw-r--r-- | spec/ruby/shared/process/exit.rb | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/spec/ruby/shared/process/exit.rb b/spec/ruby/shared/process/exit.rb index e633afc73a..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,29 +81,35 @@ 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') + 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 @@ -107,7 +119,7 @@ describe :process_exit!, shared: true do end raise 'original error' RUBY - out = ruby_exe(code, args: '2>&1') + 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 |
