我正在学习 Ruby,并且在Time
. 这是我需要通过的 rspec 的要求:
it "takes about 1 second to run a block that sleeps for 1 second" do
elapsed_time = measure do
sleep 1
end
elapsed_time.should be_within(0.1).of(1)
end
我的代码measure
是:
def measure
start = Time.now
elapse = Time.now - start
end
我错过了什么?我无法通过睡眠 1 秒的街区。我试图测试并调用该块:
a = Proc.new{puts "hello"}
sleep 1
measure
# => Unknown error