我似乎无法掌握存根到底是什么。
有人可以解释一下下面的 RSPEC 代码应该做什么。在这里使用存根有什么好处?
require "performance_monitor"
require "time" # loads up the Time.parse method -- do NOT create time.rb!
describe "Performance Monitor" do
before do
@eleven_am = Time.parse("2011-1-2 11:00:00")
end
it "takes exactly 1 second to run a block that sleeps for 1 second (with stubs)" do
fake_time = @eleven_am
Time.stub(:now) { fake_time }
elapsed_time = measure do
fake_time += 60 # adds one minute to fake_time
end
elapsed_time.should == 60
end
end
我想我可以通过一个例子来理解。