1
我在学Ruby,遇到困难时刻Time
。下面是从我需要通过rspec的要求:Ruby时间运行模块,睡眠时间为x秒
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
参数添加到您的方法和内部产生的。 – oldergod