我试图在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
Run Code Online (Sandbox Code Playgroud)
这样做时我收到以下错误:
Failure/Error: Time.stub!(:now).and_return(@time_now)
NoMethodError:
undefined method `stub!' for Time:Class
Run Code Online (Sandbox Code Playgroud)
知道为什么会发生这种情况吗?