diff options
Diffstat (limited to 'spec/ruby/library/timeout/timeout_spec.rb')
| -rw-r--r-- | spec/ruby/library/timeout/timeout_spec.rb | 41 |
1 files changed, 27 insertions, 14 deletions
diff --git a/spec/ruby/library/timeout/timeout_spec.rb b/spec/ruby/library/timeout/timeout_spec.rb index 2eccd02097..9ae70bf600 100644 --- a/spec/ruby/library/timeout/timeout_spec.rb +++ b/spec/ruby/library/timeout/timeout_spec.rb @@ -1,32 +1,37 @@ -require File.expand_path('../../../spec_helper', __FILE__) +require_relative '../../spec_helper' require 'timeout' describe "Timeout.timeout" do it "raises Timeout::Error when it times out with no specified error type" do - lambda { + -> { Timeout.timeout(1) do - sleep 3 + sleep end - }.should raise_error(Timeout::Error) + }.should.raise(Timeout::Error) end it "raises specified error type when it times out" do - lambda do + -> do Timeout.timeout(1, StandardError) do - sleep 3 + sleep end - end.should raise_error(StandardError) + end.should.raise(StandardError) end - it "does not wait too long" do - before_time = Time.now - lambda do - Timeout.timeout(1, StandardError) do - sleep 3 + it "raises specified error type with specified message when it times out" do + -> do + Timeout.timeout(1, StandardError, "foobar") do + sleep end - end.should raise_error(StandardError) + end.should.raise(StandardError, "foobar") + end - (Time.now - before_time).should be_close(1.0, 0.5) + it "raises specified error type with a default message when it times out if message is nil" do + -> do + Timeout.timeout(1, StandardError, nil) do + sleep + end + end.should.raise(StandardError, "execution expired") end it "returns back the last value in the block" do @@ -34,4 +39,12 @@ describe "Timeout.timeout" do 42 end.should == 42 end + + ruby_version_is "3.4" do + it "raises an ArgumentError when provided with a negative duration" do + -> { + Timeout.timeout(-1) + }.should.raise(ArgumentError, "Timeout sec must be a non-negative number") + end + end end |
