【发布时间】:2015-08-30 19:42:44
【问题描述】:
我正在尝试按如下方式在 RSpec 中存根 Time.now:
it "should set the date to the current date" do
@time_now = Time.now
Time.stub!(:now).and_return(@time_now)
@thing.capture_item("description")
expect(@thing.items[0].date_captured).to eq(@time_now)
end
这样做时出现以下错误:
Failure/Error: Time.stub!(:now).and_return(@time_now)
NoMethodError:
undefined method `stub!' for Time:Class
知道为什么会发生这种情况吗?
【问题讨论】:
-
正如它所说的那样。
Time没有名为stub!的方法。