diff options
Diffstat (limited to 'spec/ruby/core/exception/signal_exception_spec.rb')
| -rw-r--r-- | spec/ruby/core/exception/signal_exception_spec.rb | 61 |
1 files changed, 55 insertions, 6 deletions
diff --git a/spec/ruby/core/exception/signal_exception_spec.rb b/spec/ruby/core/exception/signal_exception_spec.rb index 3b2d1aad61..010181bc55 100644 --- a/spec/ruby/core/exception/signal_exception_spec.rb +++ b/spec/ruby/core/exception/signal_exception_spec.rb @@ -1,4 +1,4 @@ -require File.expand_path('../../../spec_helper', __FILE__) +require_relative '../../spec_helper' describe "SignalException.new" do it "takes a signal number as the first argument" do @@ -9,7 +9,7 @@ describe "SignalException.new" do end it "raises an exception with an invalid signal number" do - lambda { SignalException.new(100000) }.should raise_error(ArgumentError) + -> { SignalException.new(100000) }.should.raise(ArgumentError) end it "takes a signal name without SIG prefix as the first argument" do @@ -27,7 +27,11 @@ describe "SignalException.new" do end it "raises an exception with an invalid signal name" do - lambda { SignalException.new("NONEXISTANT") }.should raise_error(ArgumentError) + -> { SignalException.new("NONEXISTENT") }.should.raise(ArgumentError) + end + + it "raises an exception with an invalid first argument type" do + -> { SignalException.new(Object.new) }.should.raise(ArgumentError) end it "takes a signal symbol without SIG prefix as the first argument" do @@ -45,7 +49,7 @@ describe "SignalException.new" do end it "raises an exception with an invalid signal name" do - lambda { SignalException.new(:NONEXISTANT) }.should raise_error(ArgumentError) + -> { SignalException.new(:NONEXISTENT) }.should.raise(ArgumentError) end it "takes an optional message argument with a signal number" do @@ -56,11 +60,11 @@ describe "SignalException.new" do end it "raises an exception for an optional argument with a signal name" do - lambda { SignalException.new("INT","name") }.should raise_error(ArgumentError) + -> { SignalException.new("INT","name") }.should.raise(ArgumentError) end end -describe "rescueing SignalException" do +describe "rescuing SignalException" do it "raises a SignalException when sent a signal" do begin Process.kill :TERM, Process.pid @@ -72,3 +76,48 @@ describe "rescueing SignalException" do end end end + +describe "SignalException" do + it "can be rescued" do + ruby_exe(<<-RUBY) + begin + raise SignalException, 'SIGKILL' + rescue SignalException + exit(0) + end + exit(1) + RUBY + + $?.exitstatus.should == 0 + end + + platform_is_not :windows do + it "runs after at_exit" do + output = ruby_exe(<<-RUBY, exit_status: :SIGKILL) + at_exit do + puts "hello" + $stdout.flush + end + + raise SignalException, 'SIGKILL' + RUBY + + $?.termsig.should == Signal.list.fetch("KILL") + output.should == "hello\n" + end + + it "cannot be trapped with Signal.trap" do + ruby_exe(<<-RUBY, exit_status: :SIGPROF) + Signal.trap("PROF") {} + raise(SignalException, "PROF") + RUBY + + $?.termsig.should == Signal.list.fetch("PROF") + end + + it "self-signals for USR1" do + ruby_exe("raise(SignalException, 'USR1')", exit_status: :SIGUSR1) + $?.termsig.should == Signal.list.fetch('USR1') + end + end +end |
