更新mongoid場我試圖單元測試下面的代碼:單元測試使用RR
require 'mongoid'
class Seller
include Mongoid::Document
field :updated_at, type: Time
def update_updated_at
updated_at = Time.now
save
end
end
這是我嘗試
describe Seller do
describe 'update_updated_at' do
it 'sets updated_at to Time.now' do
now = Time.new(2013,10,14)
seller = Seller.new
mock(Time).now { now }
mock(seller).updated_at= now
mock(seller).save
seller.update_updated_at
end
end
end
我收到以下故障
updated_at=(2013-10-14 00:00:00 -0600)
Called 0 times.
Expected 1 times.
+1用於引入timecop。 +1用於觸摸。 – zhon