2018-03-04 10:09:32 -05:00
|
|
|
require_relative '../../spec_helper'
|
|
|
|
require_relative 'fixtures/classes'
|
2017-05-07 08:04:49 -04:00
|
|
|
|
|
|
|
describe "Kernel#sleep" do
|
|
|
|
it "is a private method" do
|
|
|
|
Kernel.should have_private_instance_method(:sleep)
|
|
|
|
end
|
|
|
|
|
2019-03-28 10:22:29 -04:00
|
|
|
it "returns an Integer" do
|
|
|
|
sleep(0.001).should be_kind_of(Integer)
|
|
|
|
end
|
|
|
|
|
2017-05-07 08:04:49 -04:00
|
|
|
it "accepts a Float" do
|
2019-03-28 10:22:29 -04:00
|
|
|
sleep(0.001).should >= 0
|
2017-05-07 08:04:49 -04:00
|
|
|
end
|
|
|
|
|
2020-12-20 11:16:26 -05:00
|
|
|
it "accepts an Integer" do
|
2019-03-28 10:22:29 -04:00
|
|
|
sleep(0).should >= 0
|
2017-05-07 08:04:49 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "accepts a Rational" do
|
2019-03-28 10:22:29 -04:00
|
|
|
sleep(Rational(1, 999)).should >= 0
|
2017-05-07 08:04:49 -04:00
|
|
|
end
|
|
|
|
|
2021-03-27 08:02:41 -04:00
|
|
|
it "accepts any Object that reponds to divmod" do
|
|
|
|
o = Object.new
|
|
|
|
def o.divmod(*); [0, 0.001]; end
|
|
|
|
sleep(o).should >= 0
|
|
|
|
end
|
|
|
|
|
2017-05-07 08:04:49 -04:00
|
|
|
it "raises an ArgumentError when passed a negative duration" do
|
2019-07-27 06:40:09 -04:00
|
|
|
-> { sleep(-0.1) }.should raise_error(ArgumentError)
|
|
|
|
-> { sleep(-1) }.should raise_error(ArgumentError)
|
2017-05-07 08:04:49 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "raises a TypeError when passed nil" do
|
2019-07-27 06:40:09 -04:00
|
|
|
-> { sleep(nil) }.should raise_error(TypeError)
|
2017-05-07 08:04:49 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "raises a TypeError when passed a String" do
|
2019-07-27 06:40:09 -04:00
|
|
|
-> { sleep('2') }.should raise_error(TypeError)
|
2017-05-07 08:04:49 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "pauses execution indefinitely if not given a duration" do
|
|
|
|
running = false
|
|
|
|
t = Thread.new do
|
|
|
|
running = true
|
|
|
|
sleep
|
|
|
|
5
|
|
|
|
end
|
|
|
|
|
|
|
|
Thread.pass until running
|
|
|
|
Thread.pass while t.status and t.status != "sleep"
|
|
|
|
|
|
|
|
t.wakeup
|
|
|
|
t.value.should == 5
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "Kernel.sleep" do
|
|
|
|
it "needs to be reviewed for spec completeness"
|
|
|
|
end
|