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

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -