1require_relative '../../spec_helper' 2require_relative 'fixtures/classes' 3 4describe "Kernel.at_exit" do 5 it "is a private method" do 6 Kernel.should have_private_instance_method(:at_exit) 7 end 8 9 it "runs after all other code" do 10 ruby_exe("at_exit {print 5}; print 6").should == "65" 11 end 12 13 it "runs in reverse order of registration" do 14 code = "at_exit {print 4};at_exit {print 5}; print 6; at_exit {print 7}" 15 ruby_exe(code).should == "6754" 16 end 17 18 it "allows calling exit inside at_exit handler" do 19 code = "at_exit {print 3}; at_exit {print 4; exit; print 5}; at_exit {print 6}" 20 ruby_exe(code).should == "643" 21 end 22 23 it "gives access to the last raised exception" do 24 code = <<-EOC 25 at_exit do 26 puts "The exception matches: \#{$! == $exception}" 27 end 28 29 begin 30 raise "foo" 31 rescue => $exception 32 raise 33 end 34 EOC 35 36 result = ruby_exe(code, args: "2>&1", escape: true) 37 result.should =~ /The exception matches: true/ 38 end 39 40end 41 42describe "Kernel#at_exit" do 43 it "needs to be reviewed for spec completeness" 44end 45