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 -

how to prompt save As Box in Excel Interlop c# MVC 4 -

xslt 1.0 - How to access or retrieve mets content of an item from another item? -