ruby - Stubbing Time.now with RSpec -
i trying stub time.now in rspec follows:
it "should set date current date" @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
i following error when doing so:
failure/error: time.stub!(:now).and_return(@time_now) nomethoderror: undefined method `stub!' time:class
any idea why happening?
depending on version of rspec might want use newer syntax:
allow(time).to receive(:now).and_return(@time_now)
see rspec mocks 3.3
Comments
Post a Comment